Public Group

# understanding modelview for a camera

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

## 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
glPushMatrix();
doMethod_here_to_inverse(cameraM)
gldrawObject();
glPopMatrix();
}

is this the correct way to translate hte camera with the object?

1. 1
2. 2
3. 3
4. 4
frob
13
5. 5

• 16
• 13
• 20
• 12
• 19
• ### Forum Statistics

• Total Topics
632170
• Total Posts
3004550

×