Archived

This topic is now archived and is closed to further replies.

NaliXL

FAQ!? Combining camera and object translate/rotations?

Recommended Posts

Hi! I''ve just been reading NeHe''s lesson 10, and now I really start to wonder : is there an easy way to combine the translate/rotate operations? Suppose we want to implement the rotating cube from lesson 6 into lesson 10. Then from what I''ve learned, I suppose you''d have to do the following : 1. Translate the matrix to get a "camera position". 2. Rotate the matrix to get a "camera position". 3. Translate the matrix to the position of the cube. 4. Rotate the matrix to get the rotation of the cube. 5. Draw the cube. Now I''m quite sure that I just misunderstood this or there is some kind of algorythm to do steps 1 to 4 in just 2 steps, with just one translation and rotation. One other question that comes from this first one : would this alghorythm be faster or would translating and rotating 2 times be faster? Especially keeping in mind that hardware T&L is becoming more standard than exception today...

Share this post


Link to post
Share on other sites
Hi,

The transformations could all be made into one matrix. You could then just load that one matrix into the opengl modelview matrix.

This would mean sending less data too your vid card (so faster), but depending on T&L it may be faster to let the card do it.

At least I think thats correct ;¬)

A good refernece on the transformation stuff is here.

Dan

Edited by - mrbastard on February 18, 2002 9:01:55 PM

Share this post


Link to post
Share on other sites
Hmm,

Not sure if its exactly on topic but...

My proto engine has a ''transformation'' object that stores a single matrix that represents all the translations/rotations that need to be applied to an object to move it from the origin to its location/orientation in world space.

I use this object for the camera and for movable models.

To change the camera view you just load the transformation matrix into the model view matrix. To draw an object you push the current model view matrix, multiple the modleview by the transformation matrix for that object, draw it and pop the original model view back.

The tranformation matrix just accumulates all the rotations and translations that you apply in sequence. A nice feature is that you can choose to translate/rotate relative to the world axis or to the model''s orientation (great for full 3d apps).

A matrix multiplication per model per frame is not really a high price to pay and it sure beats messing about with quaternions. Of course for high volume application like a particle engine you would want something a little more lightweight.

Keef






-----------------------
glDisable(WORK);
glEnable(GL_CODING);

Share this post


Link to post
Share on other sites
quote:
Original post by mrbastard
The transformations could all be made into one matrix.


You mean doing all transformations on the objects by hand and then passing the whole thing to OpenGL?

Share this post


Link to post
Share on other sites
quote:
Original post by NaliXL
You mean doing all transformations on the objects by hand and then passing the whole thing to OpenGL?



Yeah, either by making a matrix to represent all the transformations for the object and loading it into the modelview prior to drawing the object, OR by translating the objects vertices by the matrix and just passing the vertices (but that has loads of downsides, as your model is now specified in world space, rather than from its own orign).

Dan

Share this post


Link to post
Share on other sites