|
From: Ben S. <bs...@vr...> - 2002-03-26 23:09:05
|
In short, yes. Consider the following example.
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glRotatef( 30.0, 1,0,0 );
glBegin( GL_QUADS );
// draw cube ...
glEnd();
glRotatef( 15.0, 0,1,0 );
glBegin( GL_TRIANGLES );
// draw pyramid ...
glEnd();
Here, the cube will be rotated 30 degrees about the x-axis. Then the
pyramid will be rotated 15 degrees about the y-axis followed by a 30
degree rotation about the x-axis. So it sounds like this behavior would
cause a problem for your app. You essentially have 2 solutions:
1. Clear the modelview matrix before drawing the pyramid using
glLoadIdentity() before the second call to glRotatef().
2. Use the matrix stack. Each matrix type (modelview/projection/texture)
is actually a stack. In the case of the modelview matrix stack, you are
guaranteed at least 32 matrices on the stack. By using the stack, you can
keep a copy of the current matrix and push a copy of it onto the top of
the stack. You can modify the new matrix with calls to glRotatef(), etc
and then pop that matrix off when you are finished to get back to your
original matrix. For example.
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glPushMatrix(); // push a new matrix on the stack
glRotatef( 30.0, 1,0,0 );
// draw cube ...
glPopMatrix(); // pop the modified matrix off and use the identity again
glPushMatrix();
glRotatef( 15.0, 0,1,0 );
// draw pyramid ...
glPopMatrix();
This time, the rotations are independent of each other. Thus rotating the
cube does not affect the rotation of the pyramid. :)
You could always do something more complex ...
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
// draw BMX
glPushMatrix();
glTranslatef( ... );
glRotatef( ... );
// Draw BMX body
// wheel is relative to BMX body
glPushMatrix();
glTranslatef( ... );
glRotatef( ... );
// draw BMX wheel
glPopMatrix();
// do other wheel ...
// Handlebars are also relative to the body
glPushMatrix();
glTranslatef( ... );
glRotatef( ... );
// draw BMX handlebars
glPopMatrix();
glPopMatrix();
In this setup you only have to worry about the relationship between the
body and say the wheels rather than update the world position of each
wheel every time you update the position of the body.
cheers,
-----
Ben Scott
President ISU Game Developers Club
Treasurer ISU Ballroom Dance Company
bs...@ia...
On Tue, 26 Mar 2002, Lou Herard wrote:
> Yes, that was pretty helpful. Now my next question is, if I declare more
> than one OpenGL object, using glBegin() and glEnd() and I call glRotate,
> does it rotate all of them? I'm asking this because I have to keep track of
> two sets of angles: one for the handlebars (which will actually consist of
> the handlebars, front fork, and front wheel), and one for the frame of the
> bike and the rear wheel. So, if glRotate rotates every OpenGL object I
> create, that would cause a problem.
>
> - Lou
>
>
>
|