-
2D to spherical coordinate script
I have a new head-scratcher. I need to write a script that will convert a selected 2D layer into a 3D layer that is locked to a sphere around the camera, with the radius of that sphere being the distance the layer is from the camera’s origin. I have part of this working, but not quite what I want. I’m converting the 2D coordinates to 3D based on the width of the frame, but I think this is what is throwing off the result, so as I move the layer in 3D, its center of orbit seems offset from the camera. Anyone out there with better trig knowledge than I that could offer some advice?
r= transform.position[2]*-1;//convert X,Y 2D coordinates with the comp dimensions as a reference
convertX = transform.position[0]/thisComp.width*2*Math.PI-Math.PI;
convertY = transform.position[1]/thisComp.width*2*Math.PI-Math.PI/2;//spherical coordinates
sX = -(Math.cos(convertX-Math.PI/2))*(Math.cos(convertY))*r;
sY = -Math.sin(convertY)*r;
sZ = (Math.sin(convertX-Math.PI/2))*(Math.cos(convertY))*r;[sX,sY,sZ]