Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Rotating the projection matrix

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2010
    Posts
    17

    Rotating the projection matrix

    Hi,

    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.

    Code :
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
            // where I would like to insert some glRotatef
    	glOrtho(-150, 150, -100, 200, 1, 10000);
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    	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!!

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,714

    Re: Rotating the projection matrix

    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?

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2010
    Posts
    17

    Re: Rotating the projection matrix

    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?

  4. #4
    Member Regular Contributor
    Join Date
    Oct 2010
    Location
    France
    Posts
    466

    Re: Rotating the projection matrix

    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:

    Code :
    -1  0  0  0
    0   0  1  0
    0   1  0  0
    0   0  0  1

  5. #5
    Junior Member Newbie
    Join Date
    Aug 2010
    Posts
    17

    Re: Rotating the projection matrix

    OK thanks! That's what I wasn't sure of (using the proj. vs. the MV matrix).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •