I made Globe using sphere and added image on top of sphere using texture. my goal is to achieve, if i select a country suppose India, sphere has to be rotate so that India will be in center. For this i am doing i am taking the intersection point of sphere of India, and created the function for which will create latitude and longitude and return it, later i am passing this latitude and longitude to another function which will rotate accordingly, but the problem is it is not rotating properly. Please help. Below is my code snip.
function createLatAndLong(pointX, pointY, pointZ) {
var pointOnSphere = new THREE.Vector3();
pointOnSphere.x = pointX;
pointOnSphere.y = pointY;
pointOnSphere.z = pointZ;
var EarthRadius = 20;
var lat =
90 - (Math.acos(pointOnSphere.y / EarthRadius) * 180) / Math.PI;
var lon =
((90 +
(Math.atan2(pointOnSphere.x, pointOnSphere.z) * 180) / Math.PI) %
360) -
180;
let latAndLongObj = { latitude: lat, longitude: lon };
return latAndLongObj;
}
This will create latitude points and longitude, based on intersection points.
function rotateGloab(lat,lon)
{
var verticalOffset = 0.1;
earthmesh.rotation.x =lat * (Math.PI / 180) - verticalOffset ;
earthmesh.rotation.y = (270 - lon) * (Math.PI / 180) ;
}
This function is do rotation of sphere.
Please help me, i am new to three js.