-
Camera to Layer angle
Hi,
it’s been a couple of days since I started my research on how to calculate the angle between a camera’s Z axis and a layer’s Z axis;
It would seem pretty simple but there are a couple of aspects I really can’t seem to figure out.
Basically in my comp I have a camera and a layer; nothing fancy.
I want to know the angle beteen the two, which NOT ONLY changes with the position of the camera when you orbit around the layer, but also when you move from side to side while looking at the layer and, most importantly, if the layer is rotated on it’s own, while the camera is still or moves along another path.I attached 3 examples that should help explain the task I want to accomplish; all drawings are referred to a TOP VIEW.



My first attemp was to use lookAt(thisComp.activeCamera.position,position)[1]; to know the orientation of the layer;
although it seemed to be working, once I started turning the layer on its own, the expression broke, basically not changing the value since the camera and the layer did not physically move.
Besides, it does not return a value that can actually tell my if the camera is looking at the layer from the left or the right, kind of as if the value was absolute.My second, and last, attempt was to use one of Dan Ebberts expressions which I found in this forum:
try{
TargLayer = thisComp.layer(“target layer”);
C = thisComp.activeCamera;
v1 = normalize(C.toWorld([0,0,0]) – TargLayer.toWorld(anchorPoint))
v2 = TargLayer.toWorldVec([0,0,1]);angle = radiansToDegrees(Math.acos(dot(v1,v2)));
linear(angle,90,135,0,100);
}
catch(e){
value;
}And while it did a better job, by dealing with rotation of the layer as well, it also couldn’t tell me if the layer was rotated to the left or to the right of the camera.
My question then is:
Is there a way to know whether the target layer is rotated to the right or to the left?
Maybe using other parameters of the camera or layer….
If there was a way to know, for example, which side of the target layer is closer to the camera, it would be perfect!I attach also a simple project file that you can use to help me out: https://f1.creativecow.net/11724/11724
Thanks,
Leopy.

