View Full Version : Draw multiple objects? Save parameters?

03-11-2010, 09:36 AM

I am (very) new to OpenGL, trying to do a University project.

I want to draw to the screen several objects (which come as md2 files actually). Each object has its own 3 parameters: location on the 3d world, scale and rotation.

My question is:
Suppose I did some object manipulation (lets say, I rotated the object). Now lets say I want to manipulate the object again (another rotation, say 5 mins after) - and, I want that now every time that the object is drawn it is drawn with those 2 rotations applied.

How do I save the matrix of the object between the first rotation and the second rotation?

Using glGetf (to get and save the current matrix as a parameter) is not advised (as much as I can tell from googling..)

If I can't save the matrix every time I do an operation, I would have to save the history of operations (say, rotation1, rotation2, etc..) and every time start from the identity matrix, and do the whole history of operations - which naturally does not make any sense...

Thank you very much

My design is as follows:
With each iteration, the object's class is in charge of drawing itself. Meaning, the object should set the right matrix parameters (scale, rotation, etc.) and call the display list.
Thus - a way to save the objects current parameters is required (in the meaning described above..)

thanks again

Ehsan Kamrani
03-11-2010, 07:03 PM
Trying to use your own matrices and passing the results to glMultMatrix() is not a bad idea for a university project ;)

If you want to use your own matrices, You need to mimic the behavior of OpenGL transformations. You can use row major or column major matrices and apply the appropriate equations. I used this option excessively in my project to load collada files. Collada files consist of some nodes and each node have its own transformations. So we need to concatenate the new matrices with the matrices of the parent's node to get the final transformation of each node.Then I send this matrix to glMultMatrix() instead of using direct OpenGL transformation functions such as glTranslate() and glScale() and finally draw the geometries of that node( if available ).

You can also use quaternions and convert the results to a rotation matrix if you want to mimic the behavior of OpenGL rotations. It's simpler than using direct rotation matrices.

03-11-2010, 09:51 PM
Thanks a lot for your reply.

Do you happen to know of a good mathematics class that mimics the behavior of glTranslate, glRotate, etc. ? (Good in the sense of efficiency)

This math class should have an API as close to OpenGL's as possible.

Thanks a lot again

03-12-2010, 03:32 AM
This one sound pretty good :