Results 1 to 6 of 6

Thread: Problem with PROJECTION / MODELVIEW matrices

  1. #1
    Guest

    Problem with PROJECTION / MODELVIEW matrices

    Does anyone know why this code works the same way when bProjectionNotModeview == TRUE or FALSE:
    glClearColor(0.0, 0.0, 0.0, 1.0);
    glClearDepth(1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0, 640.0 / 480.0, 1.0, 1000.0);

    if ((m_bMoveCameraForward == true) && (m_bMoveCameraBackward == false))
    {
    m_f32CameraPositionZ += 0.1F;
    }
    else if ((m_bMoveCameraForward == false) && (m_bMoveCameraBackward == true))
    {
    m_f32CameraPositionZ -= 0.1F;
    }

    if ((m_bMoveCameraLeft == true) && (m_bMoveCameraRight == false))
    {
    //m_f32CameraPositionX += 0.1F;
    m_f32CameraAngleY -= 0.5F;
    }
    else if ((m_bMoveCameraLeft == false) && (m_bMoveCameraRight == true))
    {
    //m_f32CameraPositionX -= 0.1F;
    m_f32CameraAngleY += 0.5F;
    }

    if (bProjectionNotModeview == true)
    {
    glMatrixMode(GL_PROJECTION);

    glTranslatef(m_f32CameraPositionX, 0.0F, m_f32CameraPositionZ);
    glRotatef(m_f32CameraAngleY, 0.0F, 1.0F, 0.0F);
    glRotatef(m_f32CameraAngleX, 1.0F, 0.0F, 0.0F);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    }
    else
    {
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glTranslatef(m_f32CameraPositionX, 0.0F, m_f32CameraPositionZ);
    glRotatef(m_f32CameraAngleY, 0.0F, 1.0F, 0.0F);
    glRotatef(m_f32CameraAngleX, 1.0F, 0.0F, 0.0F);
    }

    glShadeModel(GL_SMOOTH);

    glEnable(GL_DEPTH_TEST);

    glBegin(GL_QUADS);
    glColor3ub(255, 0, 0);
    glVertex3f( 10.0F, 10.0F, 10.0F);
    glColor3ub( 0, 255, 0);
    glVertex3f(-10.0F, 10.0F, 10.0F);
    glColor3ub( 0, 0, 255);
    glVertex3f(-10.0F, -10.0F, 10.0F);
    glColor3ub(255, 255, 0);
    glVertex3f( 10.0F, -10.0F, 10.0F);

    glColor3ub(255, 0, 0);
    glVertex3f( 10.0F, 10.0F, -10.0F);
    glColor3ub(255, 0, 0);
    glVertex3f( 10.0F, 10.0F, 10.0F);
    glColor3ub(255, 255, 0);
    glVertex3f( 10.0F, -10.0F, 10.0F);
    glColor3ub(255, 255, 0);
    glVertex3f( 10.0F, -10.0F, -10.0F);

    glColor3ub( 0, 255, 0);
    glVertex3f(-10.0F, 10.0F, 10.0F);
    glColor3ub( 0, 255, 0);
    glVertex3f(-10.0F, 10.0F, -10.0F);
    glColor3ub( 0, 0, 255);
    glVertex3f(-10.0F, -10.0F, -10.0F);
    glColor3ub( 0, 0, 255);
    glVertex3f(-10.0F, -10.0F, 10.0F);

    glColor3ub( 0, 255, 0);
    glVertex3f(-10.0F, 10.0F, -10.0F);
    glColor3ub(255, 0, 0);
    glVertex3f( 10.0F, 10.0F, -10.0F);
    glColor3ub(255, 255, 0);
    glVertex3f( 10.0F, -10.0F, -10.0F);
    glColor3ub( 0, 0, 255);
    glVertex3f(-10.0F, -10.0F, -10.0F);
    glEnd();

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Oct 2001
    Posts
    595

    Re: Problem with PROJECTION / MODELVIEW matrices

    It may look the same, but it isnt..

    You should NEVER ( unless you have very specific reasons) do anything else than projection in the Projection matrix..

    reason : A number of operations like fog, lighting and texture coordinate calculations are made on then vertices after the modelview tranformation and before projection.. so screing up the projection matrix makes those calculations go wild.

  3. #3
    Guest

    Re: Problem with PROJECTION / MODELVIEW matrices

    What I wanna see is like it's written in the red book:
    glMatrix(GL_PROJECTION)
    glTranslatef(0.0F, 0.0F, 5.0F);
    EQUAL
    glMatrix(GL_MODELVIEW)
    glTranslatef(0.0F, 0.0F, -5.0F);
    Am I wrong ?

  4. #4
    Junior Member Newbie
    Join Date
    Dec 2002
    Location
    Ann Arbor, MI , USA
    Posts
    4

    Re: Problem with PROJECTION / MODELVIEW matrices

    Basically, if you want to use glTranslatef(), it always uses openGL like this
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0.0F, 0.0F, 5.0F);

    So, the answer to your question is NOT EQULE.

    Originally posted by Matthieu DUFOURNEAUD:
    What I wanna see is like it's written in the red book:
    glMatrix(GL_PROJECTION)
    glTranslatef(0.0F, 0.0F, 5.0F);
    EQUAL
    glMatrix(GL_MODELVIEW)
    glTranslatef(0.0F, 0.0F, -5.0F);
    Am I wrong ?

  5. #5
    Guest

    Re: Problem with PROJECTION / MODELVIEW matrices

    On which matrix does process glTranslate ?
    The one choose by glMatrixMode or always GL_MODELVIEW ?

  6. #6

    Re: Problem with PROJECTION / MODELVIEW matrices

    The one selected with glMatrixMode(...)

Similar Threads

  1. Using modelview/projection matrix to do a projection myself
    By AllForum in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 08-30-2012, 07:42 AM
  2. noob question - modelview and projection matrices
    By newsb in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 04-23-2012, 05:19 PM
  3. Problem AR: Modelview and projection matrices
    By dehabu in forum OpenGL: General
    Replies: 1
    Last Post: 07-17-2010, 11:45 AM
  4. gl modelview matrices
    By appleGuy in forum OpenGL: General
    Replies: 2
    Last Post: 03-02-2007, 08:05 AM
  5. Projection and Modelview matrices
    By in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 07-11-2003, 01:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean