Answer the question
In order to leave comments, you need to log in
How to determine the coordinates of a click on a rotating sphere?
1) there is a globe made on three.js
self.earth = new THREE.Mesh(new THREE.SphereGeometry(50, 32, 32), new THREE.MeshBasicMaterial({map: tex}));
2) click intersections found
var mouse3D = new THREE.Vector3( );
var raycaster = new THREE.Raycaster();
mouse3D.set( ( (event.clientX) / window.innerWidth ) * 2 - 1, -( (event.clientY) / window.innerHeight ) * 2 + 1, 0.5 ).unproject(self.camera);
raycaster.set(self.camera.position, mouse3D.sub(self.camera.position ).normalize());
.
.
r=50; // radius
x = object.point.x ;
y = object.point.y ;
z = object.point.z ;
3) calculate coordinates
var lat = ( 90 - (Math.acos(y / r)) * 180 / Math.PI );
var lon = ((270 + (Math.atan2(x , z)) * 180 / Math.PI) % 360);
it does not work clearly, but at least this way, when adding rotation (for example, when adding the earth to the scene: self.obj.rotation.y = 34.3; this is the object in which the earth itself is located, marks on it, etc.), it does not count at all correctly, tell me what make?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question