Hello,
I am trying to create an AR app with Three.js. I have already been able to implement the following points
- Camera image as background image
- Drawing 3D elements on the background image
- Controlling the camera with mobile phone sensors (DeviceOrientationControls)
My code looks like this:
Creating Three.js Scene
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth /
window.innerHeight, 0.01, 1000 );
camera.lookAt(scene);
const renderer = new THREE.WebGLRenderer({ alpha: true });
renderer.setSize( window.innerWidth, window.innerHeight );
const controls = new DeviceOrientationControls( camera );
document.body.appendChild( renderer.domElement );
Creating. Cube and Axeshelper
const geometry = new THREE.BoxGeometry( 1, 1, 1 );
const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
const cube = new THREE.Mesh( geometry, material );
const geometry2 = new THREE.BoxGeometry( 1, 1, 1 );
const material2 = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
const cube2 = new THREE.Mesh( geometry2, material2 );
const axeshelper = new THREE.AxesHelper( 5 );
scene.add(axeshelper);
camera.position.z = 2;
Converting Lat/Lon Data to cartesian Coordinates and position the cube
const myPos = this.calcPosFromLatLonRad(52.498604, 13.391799, 1);
const myPosX = myPos[0];
const myPosY = myPos[1];
const myPosZ = myPos[2];
cube.position.set(myPosX, myPosY, myPosZ);
cube2.position.set(2,2,2)
scene.add ( cube );
scene.add ( cube2 );
Rendering the scene
const animate = () => {
requestAnimationFrame( animate );
controls.update();
renderer.render( scene, camera );
};
animate();
But now I don’t know whether simply calculating the GPS coordinates into a Cartesian product is sufficient. It definitely does not work at the moment. The points get almost the same value after the conversion, so that two points that should theoretically be displayed at completely different positions are displayed directly next to each other. In addition, I think I have to look at the world from the user’s coordinate point. But I don’t know how to do that.