I'm back a month later, having beefed up my algebra, and I finally have a handle on this problem. 3D rotations are much more complicated than I thought.
For anyone new to this, I'll give a quick explanation. The system of rotation most animators are familiar with, represented by degrees about the XYZ axes, is only one of many mathematical representations possible. The advantage to this system, called Euler angles, is that you only need 3 numbers to represent rotation. The disadvantage is that if the axes are rotated in different orders the same numbers actually could get confused with your object pointing in entirely different directions. This is what cropped up in transferring the AE camera to Maya. Maya's default rotation is ZYX, the exact opposite of AE's default rotation, which is XYZ.
So how do you translate one into the other?
The first part of the answer is to change rotation into a representation where a set of numbers always means your object is pointing in such and such a direction with no confusion. It turns out, I've learned, that your animation program is doing this behind the scenes anyway. To do this, we need more numbers than 3. Euler representations can be converted into 3x3, 9 number matrix notations.
The rest rotation we usually think of as
[0,0,0]
looks like this
|1,0,0|
|0,1,0|
|0,0,1|
So the trick in converting XYZ rotation into ZYX rotation is to convert to the matrix notation in between, going XYZ --> Matrix --> ZYX. To do this you not only have to have good trigonometry skills, but also be able to multiply matrices, which can be tricky algebra.
This, for example, this is what ends up as the X rotation expression I put on a ZYX camera in AE:
L=this_comp.layer("Camera");
u=L.toWorldVec([1,0,0]);
v=L.toWorldVec([0,1,0]);
w=L.toWorldVec([0,0,1);
hLock=clamp(u[2],-1,1);h=Math.asin(-hLock);cosH=Math.cos(h);
if (Math.abs(cosH) > 0.0005){
p=Math.atan2(v[2], w[2]);
b=Math.atan2(u[1],u[0]/thisComp.pixelAspect);
}else{
b=Math.atan2(w[1], v[1]);
p=0;
}
BHP = [ radiansToDegrees(b), radiansToDegrees(h), radiansToDegrees(p) ];
BHP[2]
It's too involved to explain the above in a short space, but the result is this script I wrote, which transfers an AE Camera to Maya (I have been trying to do this on and off for years, by the way. Finally!).
All you have to do highlight your camera, and the script does everything else, including outputting a .ma file for Maya. It shouldn't matter how your camera is animated (parented, with POI, with auto-orientation), whether you're in non-square pixels or not, or if you've animated your zoom value (focal length). This baby should handle all that.
http://www.urbanspaceman.net/shared/AEs ... ToMaya.jsx