how to set projection matrix to match Maya view?

Hi All,

I’ve got a little ogl application where I’m loading models and camera paths exported from Maya… but I don’t have the correct projection matrix logic to get a matching view between my application and Maya. Currently, I’m just calling gluPerspective() to generate my perspective matrix.

Searching the net, I’ve only managed to find one reference to the Maya projection matrix that seems useful to ogl:

I don’t know how accurate this web reference is… comparing it to the output of gluPerspective(), the matrix generated is very close. Should be easy to test…
So I wrote a little gluPerspective() replacement that should mimic the official gluPerspective(). Comparing its output with a glGet() of the perspective matrix generated by the official gluPerspective() shows the same matrix being generated… which is good. However, looking at that web reference describing the Maya perspective matrix, I don’t know where in Maya to get the camera’s vertical field of view or the aspect ratio. I see various camera attributes, but the vertical field of view and the device aspect ratio could be a number of different things in their terminology…

Does anyone have any experience in getting a matching view between your ogl app and Maya?


If your ogl projection matrix match the maya one, I think that your problem is in the modelview matrix that you set on opengl.
Actually, the projection matrix is used for projection as its name says and then, you have to set the ogl modelview matrix to match the maya view point. If you can retrieve from maya, the camera position, its target and its vertical field of view, you can call the gluLookAt function to set the modelview matrix.

the aspect ratio is defined as :
a = viewport_width/viewport_height, in opengl.

So this depends on your ogl window size, not Maya.

I do not believe you are correct. I am setting the modelview matrix with the same srt xform as used in Maya. However, Maya does not normally have a viewing target, as used by gluLookAt(). One can set up something like that with a view constraint, but that is not the normal Maya camera rig. I tried creating an empty node (a ‘locator’ in Maya terms) and used the View pulldown menu’s “Look At Selection” function to create a view where I knew the “look at” target for the Maya camera. However, simply passing in the camera’s position, my look at target position, and an up vector does not create a matching OGL view as seen in Maya.

What I’m seeking is which parameters from Maya’s camera correspond to the ‘f’ parameter in this description:

I don’t actually know if that web reference is correct, but it is the only reference on this I’ve been able to locate.

Anyone else with any information in this subject? Your input will be greatly appreciated.

This might be a long shot, but have you tried using something like to grab the OpenGL function calls Maya makes? You may be able to see what matrices are used.

(I have not tried it myself - so I have no idea if it would work)

Actually, with a simple little MEL command (Maya’s scripting language) like this:
xform -q -a -os -matrix persp
I get the perspective camera’s modelview matrix directly from Maya. So I tried just glLoadMatrix’ing this as the modelview matrix for my scene before rendering my objects, but that did not work. I suspect that I’m not understanding (or forgot) something in the OGL xform pipeline about how to overwrite OGL’s normal matrix logic. I think this matrix I get from Maya is a combination of both the perspective xform and the camera’s own local space xform, but I don’t know if I should glLoadMatrix it transposed or what.

Plus, I think this matrix being a combination of the camera’s xform and the perspective xform may be a problem for OGL. I seem to remember warnings about projection matrix abuse and this seems to be clearly in that camp.

I suspect information I’d learn from glIntercept would put me in the same position. In fact, I considered glIntercept before realizing I could just query the matrix directly via MEL.

Could it be you’re mixing up row- vs- column order?

I don’t think so. I’m printing them after glGets, and they look correct. Besides, that side steps understanding how that matrix is being generated.

I think your problem is very unclear. The perspective matrix don’t do all the work in 3D viewing, but if you think that the modelview matrix that you set is correct, maybe the gluPerpective spec could help you:

It explains clearly what is the f value. It should not be difficult, as far as I know, the Maya view configuration interface is very close to OpenGL 3D viewing configuration.

The problem is quite simple: calling gluPerspective() and gluLookAt() with the information I have is not creating a matching view in my OGL app as the view in Maya.

I believe the problem is that I am not setting the correct “fovy” term for gluPerspective(). I believe (in Maya) the fov is expressed as a horizontal field of view, so I converted it to a vertical FOV and plugged that into gluPerspective(), while passing in the same aspect, near and far as used by Maya. I also set gluLookAt() with the Maya camera’s position and a viewing target I set manually…

Yet, my ogl view does not match the view when rendering from Maya. So, I am left to believe that I am not getting the correct fovy term.

However, being that I’m unsure, I am asking the community here if anyone has experience in this. If you have experience in this area, your contribution will be appreciated.

1 Like

What is the formula you use for converting your fovy to fovx ?

Im using this code…

 m_Aspect = xres/yres;
 float D = 1.0f / tanf((m_FovY*3.1415926/180.0f)/2.0f);
 m_FovX = atan2f(m_Aspect, D);

In your link

they talk about vertical field of view for f

aspect = width / height;
fovy = fovh / aspect;

width = 640.0f; height = 480.0f;
aspect = 1.3333f;
fovh = 35.0f

fovy becomes 26.25f

yooyo: you must have been typing your reply at the same time I was entering mine… look like you have different logic for your fovx calculation. I’ll try yours. Thanks!

ArtificialOffical: Have you done with this problem. Now I’m troubling this problem too, plz help me.