moving my Flyer in 3d space

Hey everybody, it’s me again.
Many thanks to everybody who helped me out last time, but I have another question.

Now that my CFlyer class is displaying and rotating properly, I’m reading to start moving it backwards and forwards in 3d space.

I know the following code is probably lousy but hey this is my first OpenGL (and windows … for that matter ) app so bare with me!

// Here’s my CFlyer movement code …
GLvoid CFlyer::Move ( ) {
pos.y += speed;
}

// And my input detection code …
if(keys[VK_RSHIFT]) {
myFlyer->speed += .01f;
}
else if( !keys[VK_RSHIFT] && myFlyer->speed > 0.0f ) {
myFlyer->speed -= .01f;
}
if(keys[VK_RCONTROL]) {
myFlyer->speed -= .01f;
}
else if( !keys[VK_RCONTROL] && myFlyer->speed < 0.0f ) {
myFlyer->speed += .01f;
}

Now I’m pretty confident on my input detection, I believe my theory on the CFlyer::Move() code is what is way off. This code does make the flyer move ever so little that I can’t tell which way it’s going and increasing to input values doesn’t change anything. Help!

  • = TEFLON DRAGON = -

I’ve just cross-checked with your previous thread. You sure that you don’t call myFlyer->SetPos(something) every frame? Well, you shouldn’t! Other than that, it looks ok.

Just a further hint, constant movement per frame is a bad thing as movement speed will change with machine speed. You should always have a timer that measures the time elapsed since the last frame, multiply the result with speed and use the result for position updates.

But you can save that issue for later

I’ve also noticed that you call glLoadIdentity() after translating and drawing the flyer. Place that call before glTranslatef(). Also make sure that your current matrix mode is GL_MODELVIEW_MATRIX.

Here’s my CFlyer: :Draw to give insight into how I’m implementing the movement…

GLvoid CFlyer: :Draw() {

Rotate();
Move();

glColor3f( color.red, color.green, color.blue );
glRotatef( zrot, 0.0f, 0.0f, 1.0f );
glRotatef( yrot, 0.0f, 1.0f, 0.0f );
glRotatef( xrot, 1.0f, 0.0f, 0.0f );
glTranslatef( pos.x, pos.y, pos.z );

glCallList( flyer );

glLoadIdentity();
}

I will try messing w/ the glLoadIdentity and I’ll have to check on the matrix settings. How do they affect what I draw?

  • = TEFLON DRAGON = -

[This message has been edited by teflon_dragon (edited 03-29-2002).]

Originally posted by teflon_dragon:
I will try messing w/ the glLoadIdentity and I’ll have to check on the matrix settings. How do they affect what I draw?

The matrix setting does not affect what you draw, but it controls where the glTranslatef and glRotate calls go. Typically, you set up some sort of projection matrix at the start of the application, eg

void
init_gl_view()
{
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(blabla);
//important bit here
    glMatrixMode(GL_MODELVIEW);
}

If you don’t switch back to GL_MODELVIEW, your matrix updates (rotations, translations and other stuff) will operate on the projection matrix, where stuff works a little differently.

Originally posted by teflon_dragon:

[quote]

Rotate();
Move();

glColor3f( color.red, color.green, color.blue );
glRotatef( zrot, 0.0f, 0.0f, 1.0f );
glRotatef( yrot, 0.0f, 1.0f, 0.0f );
glRotatef( xrot, 1.0f, 0.0f, 0.0f );
glTranslatef( pos.x, pos.y, pos.z );

glCallList( flyer );

glLoadIdentity();
}

[/QUOTE]

Looks a little redundant to me. You’re rotating and translating twice. Possibly you’re translating in the opposite direction when you call Move();. That may very well explain the problem. Comment out the Rotate(); and Move(); at the top and see if it makes a difference. If it doesn’t help, post the code for Rotate() and Move() as well.

Sorry for not clarifying Rotate() and Draw(), all they do is apply the changes to the pos variables and xrot/yrot/zrot variables, they don’t actually do glTranslate or glRotate commands.

GLvoid CFlyer::Move ( ) {
pos.y += speed;
}

GLvoid CFlyer::Rotate( ) {

xrot += xrSpeed;
           

yrot += yrSpeed;

}

Also, GL_MODELVIEW is my current matrix setting so that should be good.

My theory is this: Assuming that when I do a glRotate, it rotates the object’s x y and z axees (?) , I add a specific amount (GLfloat speed = an amount depending on how ever long user has been pressing RSHIFT) to it’s y axis. In theory this should continue to advance it along it’s own y-axis which I’m rotating with the glRotate commands.

Anyway, I figure this theory is off. lol

My goal is for the flyer to behave similiarly to the space ships in those old “Asteroids!” games (except now in 3d of course).

Help! lol

  • = TEFLON DRAGON = -

[This message has been edited by teflon_dragon (edited 03-29-2002).]

[This message has been edited by teflon_dragon (edited 03-29-2002).]