Skip to content

Instantly share code, notes, and snippets.

@petfactory
Created April 24, 2013 14:36
Show Gist options
  • Save petfactory/5452613 to your computer and use it in GitHub Desktop.
Save petfactory/5452613 to your computer and use it in GitHub Desktop.
This snippet makes sure that a layer is facing the camera. All tribute to Dan Ebberts - www.motionscript.com
L = thisComp.layer("Camera 1");
u = fromWorldVec(L.toWorldVec([1,0,0]));
v = fromWorldVec(L.toWorldVec([0,1,0]));
w = normalize(fromWorldVec(L.toWorldVec([0,0,1])));
sinb = clamp(w[0],-1,1);
b = Math.asin(sinb);
cosb = Math.cos(b);
if (Math.abs(cosb) > .0005){
c = -Math.atan2(v[0],u[0]);
a = -Math.atan2(w[1],w[2]);
}
else{
a = (sinb < 0 ? -1 : 1)*Math.atan2(u[1],v[1]);
c = 0;
}
[radiansToDegrees(a),radiansToDegrees(b),radiansToDegrees(c)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment