PDA

View Full Version : matrices



paneb
03-31-2003, 11:04 AM
i was doing some of the nehe tutorials, and then i also found out about the gametutorials.com ones..right off the starts, in the GT.com ones, Digiben uses matrix functions (glPush and glPop)..i didn't know about them before..and i was wondering what was the advantage of using different matrices that way over just doing it the way tis done at nehe in the beginning
thanks

nexusone
03-31-2003, 12:44 PM
Once you get to the more advance stuff, nehe starts to use them also.

The camera in openGL does not move, you move everything around it to make it look like it is moving.

in a scene you will define camera movement before drawing with gluLookAt or just a bunch of rotate and translate commands.

Now when we rotate/translate we are changing the matrix, but we don't want to have rotating or translating an object to effect our camera settings.


// Scene draw
// Set camera

My_camera_routine();

// Draw first object
glPushMatrix() // We save current matrix state, which holds our camera rotations and translations

glTranslatef // Matrix is altered
glRotatef // Matrix is altered

Draw_object(); // Draw object with camera and new matrix changes.
glPopMatrix(); // We have finish drawing our object, return matrix camera settings.

We repeat this for each object.

Hope this helps



Originally posted by paneb:
i was doing some of the nehe tutorials, and then i also found out about the gametutorials.com ones..right off the starts, in the GT.com ones, Digiben uses matrix functions (glPush and glPop)..i didn't know about them before..and i was wondering what was the advantage of using different matrices that way over just doing it the way tis done at nehe in the beginning
thanks

paneb
03-31-2003, 12:56 PM
so i dont really need to use it for simple stuff such as creating a cube with textures or the like..
anyways, i kinda get it now http://www.opengl.org/discussion_boards/ubb/smile.gif..
thanks nexusone

Deiussum
04-01-2003, 05:21 AM
It's also useful for doing hierarchical transformations. Usually I use a solar system example. This time I'll try to be different and use an arm example, complete with fingers.




glPushMatrix()
DoUpperArmTransformations();
DrawUpperArm();
glPushMatrix();
DoLowerArmTransformations();
DrawLowerArm();
glPushMatrix();
DoHandTransformations();
DrawHand();
for(int c=0;c<5;c++)
{
glPushMatrix();
DoFingerTransformations(c);
DrawFinger(c);
glPopMatrix(); // Pop finger transformations
}
glPopMatrix(); // Pop hand transformations
glPopMatrix(); // Pop lower arm transformations
glPopMatrix(); // Pop upper arm transformations


With the above code, each of the sections of transformations only have to do their transformations in relation to their parent object. Because of the way I set it up, it will then also be multiplied by the parent objects transformations.

Technically, I gues I didn't need to do the push/pop around the lower arm and hand in the above code, so maybe the solar system would have been a better example since you can have multiple planets with multiple satelites. Hopefully you get the idea, though. http://www.opengl.org/discussion_boards/ubb/smile.gif