View Full Version : Rotating the projection matrix

10-13-2011, 12:59 AM

Not sure whether I'm thinking wrongly about my problem or whether I just not haven't found the right way to do it yet, but here it is.

What I want to do is apply a rotation to the projection matrix and then apply glOrtho. Why do I want to do that? Because the objects I draw are given to me in another referential. Of course I could just rotate the modelview before drawing the objects (and this works) but I don't understand why the rotation of the projection matrix does not work.

// where I would like to insert some glRotatef
glOrtho(-150, 150, -100, 200, 1, 10000);
gluLookAt(-300, 0, 300, 0.0f, 0.0f, .0f, 0.0, 1.0, 0.0);
glRotatef(-90.0f, 1.0, .0f, .0f);
glRotatef(180.0f, .0, .0f, 1.0f);
// draw my objects here

Now what I would like to do is get the same effect but by rotating the projection matrix (where I put the comment in the code). If I rotate around the z axis, the objects are drawn correctly, just with another orientation. But if I apply a rotation of 90 degrees on x, than the object get completely crushed on one of the side of the viewport.

Any advice / light shed on this would be really welcome!!

Alfonse Reinheart
10-13-2011, 02:02 AM
What exactly is it that you expect to have happen when you apply a rotation to post-orthographic projected points? What effect are you trying to achieve?

10-13-2011, 02:14 AM
I'm trying to rotate the referential by -90 degrees on x and 180 degrees on z. My goal is to change my existing referential so that it matches the one of the objects that I'm trying to draw. Does it make sense?

10-13-2011, 08:21 AM
You really should do it with the modelview matrix.

Rotating -90 around x makes x unchanged, y maps to -z, and z maps to y. Rotating the result of 180 around z will then make x maps to -x, y maps to z and z maps to y.

So, a matrix like this one might help:

-1 0 0 0
0 0 1 0
0 1 0 0
0 0 0 1

10-13-2011, 11:45 PM
OK thanks! That's what I wasn't sure of (using the proj. vs. the MV matrix).