PDA

View Full Version : [OpenGL] transformations and camera



chronozphere
10-07-2009, 11:49 AM
Hey guys

A little question.

Unlike Direct3D, OpenGL combines the Model and view matrix into one. Lets say I want to render three objects that are positioned next to eachother. Calls like gluLookAt() and glTranslatef() will generate a matrix and multiply it with the existing one.
After setting this matrix and rendering an object, I want to render another one with the same camera, but with a different translation.

I could just setup the camera and call glTranslatef() a couple of times, but then you need to know the positions of the objects with respect to eachother. I could also rebuild the entire Modelview matrix for every object I render, but this seems Inefficient to me. glPushMatrix() and glPopMatrix() is also a possibility.

What's the best way to do this? Any code would be helpfull. :)

Thanks in advance

VilleK
10-07-2009, 12:56 PM
I believe the simplest technique is this:

1. position your camera
2. pushmatrix
3. translate to objects position
4. render object
5. popmatrix
6. repeat steps 2-5 for all objects