Skip to main content
Known Participant
October 15, 2015
Answered

Absolute position and orientation of camera

  • October 15, 2015
  • 4 replies
  • 2477 views

Hey folks, I'm banging my head against the wall trying to figure out what I think should be a pretty simple expression.

I'm trying to hand off my camera move from an animatic to an animator, and it doesn't import properly on his system unless the camera isn't parented to anything in after effects.

So, my relatively simple (I thought) solution was to use the toWorld expression on a new camera to look at the old one and generate absolute position and X,Y,Z rotations.  However, nothing I'm doing seems to put the new camera in the proper place, and I can't figure out how to make the rotation keyframes work at all.

Just a little info on the project, the camera has separate X, Y, and Z position keyframes and keyframes for X and Y rotation as well as Orientation (though I want the final camera to just have X, Y Z rotation keyframes).  The camera is parented to a null which has keyframed Y rotation.

If anyone can help me put these expressions together I would be so grateful!  Thanks!

This topic has been closed for replies.
Correct answer Dan Ebberts

See if this helps:

//  position

C = thisComp.layer("Camera 1");

C.toWorld([0,0,0])

// point of interest

C = thisComp.layer("Camera 1");

C.toWorld(C.pointOfInterest)

// orientation

C = thisComp.layer("Camera 1");

u = C.toWorldVec([1,0,0]);

v = C.toWorldVec([0,1,0]);

w = C.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)]

Dan

4 replies

jerry303
Participant
November 12, 2018

This is superhandy when having complex comps and when you want to separate layers while mainting the camera, in situations where you cannot make use of the "collapse transformations / contiously rasterize layers" option!

I use this to 'clone' the camera from a parented comp to a subcomp.

The parent comp has many layers and the subcomp uses the Element 3D plugin and also a lot of layers.

The camera inside the Element 3D subcomp matches the camera from the parent comp, using Dan's expressions.

Thanks!

ArivlAuthor
Known Participant
October 17, 2015

Dan that worked like a charm!!  You, sir, should be given a medal.     Some day, I'll dig in and get more familiar with how to use toWorldVec.  In the meantime, I'm so glad the Adobe forum is frequented by geniuses like you.

I'm saving this as a preset as I anticipate using it a lot!

I cross-posted this on Creative Cow.  I'm going to go paste this answer there.  I imagine this will come in handy for a lot of people, especially as things like Element 3D and AE's native 3D capabilities make it more and more feasible to do animatics in AE.

ArivlAuthor
Known Participant
October 17, 2015

Ok, so that math is beyond me, but is there anyone who can figure out the math?  I think this would be an incredibly generally useful expression.

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
October 17, 2015

See if this helps:

//  position

C = thisComp.layer("Camera 1");

C.toWorld([0,0,0])

// point of interest

C = thisComp.layer("Camera 1");

C.toWorld(C.pointOfInterest)

// orientation

C = thisComp.layer("Camera 1");

u = C.toWorldVec([1,0,0]);

v = C.toWorldVec([0,1,0]);

w = C.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)]

Dan

ArivlAuthor
Known Participant
October 17, 2015

Hey Dan, does this still work if my cameras don't  have points of interest?  Should I just ignore that part?  I've got auto-orient set to "off".

Mylenium
Legend
October 17, 2015

Not really. Yo run into a snag when using Orientation. That old Quarternions vs. Euler rotations. That's why it doesn't work. Unless you write your own matrix code and decompose the absolute angles, you will forever run into this problem. You need to use one or the other, not both. Pretty much anything that Orientation does can be mimicked with a lookAt() expression, anyway, but straightening out your rotations is inevitable.

Mylenium