View Full Version : how to set projection matrix to match Maya view?

05-29-2008, 06:44 PM
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?


05-30-2008, 09:45 AM
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.

05-30-2008, 12:23 PM
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.

05-31-2008, 02:18 AM
This might be a long shot, but have you tried using something like http://glintercept.nutty.org/ 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)

05-31-2008, 09:57 AM
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.

05-31-2008, 12:02 PM
Could it be you're mixing up row- vs- column order?

05-31-2008, 02:32 PM
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.

06-01-2008, 02:10 PM
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.

06-02-2008, 07:24 PM
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.

06-03-2008, 04:37 AM
What is the formula you use for converting your fovy to fovx ?

06-03-2008, 05:20 AM
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);

06-03-2008, 08:22 AM
In your link

they talk about vertical field of view for f

06-03-2008, 08:29 AM
aspect = width / height;
fovy = fovh / aspect;

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

fovy becomes 26.25f

06-03-2008, 08:32 AM
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!

03-19-2012, 05:55 AM
ArtificialOffical: Have you done with this problem. Now I'm troubling this problem too, plz help me.