Calculate the position of an element inside a photosphere

前端 未结 2 1721
野趣味
野趣味 2021-01-25 20:01

Im using an a-sky element to display a 360° photosphere.

My problem is that I have to place inside the photosphere some elements that must act like \'markers\'; but I do

2条回答
  •  北海茫月
    2021-01-25 20:47

    Sorry for answering my own question but this time was really easy:

    function sphericalCoordsToVector3(distance, latitude, longitude){
      return new THREE.Vector3(
        distance * -Math.cos(latitude) * Math.cos(longitude),
        distance * Math.sin(latitude),
        distance * -Math.cos(latitude) * Math.sin(longitude)
      );
    }
    

    Where distance is the distance from the centre (camera) where we want to put our element.

    Just for the records, the opposite function is:

    function vector3ToSphericalCoords(vector) {
      var phi = Math.acos(vector.y / Math.sqrt(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z));
      var theta = Math.atan2(vector.x, vector.z);
      return {
        longitude: theta < 0 ? -theta : (Math.PI * 2.0) - theta,
        latitude: (Math.PI / 2.0) - phi
      };
    };
    

    The original functions can be found here: mistic100/Photo-Sphere-Viewer (there are also nice functions to get the position of the element inside the screen)

提交回复
热议问题