-
Please Help me line-up a layer with a camera
I’ve been fighting with this for two nights now, so it’s time to get some help!!
What I want to do is orient a layer so it passes through the camera. The layer needs to look like a line in the output rendering. I have 3D objects on the layer, and I want to be able to rotate those objects toward or away from the camera in a single visual plane.
My thought process so far has gone like this:
Pick two points on the “image plane,” and as we learned in geometry class, a third point should define a plane. I want to use the camera’s position as my third point, and so have a layer that appears to the camera as just a line at some angle. As an aside, that angle should be the same as the angle of those first two points on the image plane.
pos=thisComp.activeCamera.position;
posZ=-pos[2];
// isolates the Z-position of the camera,
// makes it positive.point1= …
point2= …
// any two 2D points,
// I’ve got them tied to Point Controls, fwiw.// Now I’m going to find the angle
// of the line that those two points
// define…
vect1=sub(point2,point1);
Ang1=Math.atan2(vect1[1],vect1[0]);// Now I’m trying to find the angle of a line
// formed by the first point
// and the center of the comp…
pointC=[360,240];
Vect2=sub(pointC, point1);
Ang2=Math.atan2(Vect2[1],Vect2[0]);// I subtract these two angles
// and use that to calculate the minimum distance
// from the first line and the center point
Ang=(Ang2-Ang1);
d=-length(Vect2)*Math.sin(Ang);// Now I have a new triangle to trig out:
// “d” is the short leg of a slim triangle
// “posZ” is the long leg of this triangle: the distance
// to the camera position.
// So this final calc should give the angle that
// I should rotate the layer/plane to touch the
// Camera’s position…
x1=(d/posZ);
((radiansToDegrees(Math.atan(x1)))+90);
^^^^^^^^^^^^^//Pass this valueOn paper it looks right, and I’ve checked each line and they all give the numbers I expect. However, the layer I’m rotating does not appear to be a line: I’m off by between 0.5 degree and 2 degrees depending on the angle of the first two-point-line. So there’s something wrong with my approach here, I guess.
Help, please!!! I’d love someone to straighten out my code, or show me the ‘right way,’ to get this done!!
-drew
