• Advertisement
Sign in to follow this  

understanding modelview for a camera

This topic is 4145 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, im really trying to grasp on how a camera really works in opengl with respect to the viewing transform. In order to udnerstand this, i dont want to use gllookat, and for my perspective matrix im using glFrustum. Im essentially doing all rotations and trnaslations with matrix mutliplication, i don't want to shortchange myself with opengl utility functions. Lets say i have an object , i draw it by saying drawObject(); this box roates and translates, and i want to make a camera that translates with the box but doesnt rotate with it. My first question is, do i have camera matrix, object oreientation matrix, and a viewing matrix to load into the modelview? so lets one matrix is a translation matrix with the 1st row and fourth column have an arbitrary unit ( this is a translation along the x axis.) so from what i think, this is how i would implement this,psuedocode camera matrix = cameraM object oreientation matrix = objectM translation matrix = tranM viewing matrix = viewing M

Keybaord handler{
      switch(key){
         case 'x':
                    tranM[0][3] = .01; //translating matrix set
                    objectM = objectM * tranM;      //translating object
                    tranM[0][3] = - .01;
                    cameraM = tranM * cameraM;         //translating camera
                    break;
              }
}
function drawandmovestuff()
{
    glgetMatrix(gl_modelview)
    viewing = objectM * cameraM;     //im not getting the inverse of this
                                     //since i applied the inverse translation                                  
    glLoadMatrix(viewing);
    glPushMatrix();
    doMethod_here_to_inverse(cameraM)
    glLoadMatrix(cameraM);
    gldrawObject();
    glPopMatrix();
}                      
is this the correct way to translate hte camera with the object?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement