Hello everybody! It’s me again …
I’ve been working on the problem described in my last post for a while now and still no avail.
I have this pyramid (aka Flyer) that I want to be able to move in 3d space around the screen without moving the viewport (i.e. if the player points it away from the screen and goes forward it will get smaller, the ‘camera’ wont follow it).
Here’s how I’m trying to do it now:
(flyer.h)
GLvoid CFlyer::Draw() {
Move();
Rotate();
glTranslatef( pos.x, pos.y , pos.z );
glRotatef( zrot, 0.0f, 0.0f, 1.0f );
glRotatef( yrot, 0.0f, 1.0f, 0.0f );
glRotatef( xrot, 1.0f, 0.0f, 0.0f );
glColor3f( color.red, color.green, color.blue );
glCallList( flyer );
glTranslatef( pos.x * -1.0f, pos.y * -1.0f, pos.z * -1.0f );
glLoadIdentity();
}
GLvoid CFlyer::Move ( ) {
pos.y += speed;
}
GLvoid CFlyer::Rotate( ) {
xrot += xrSpeed;
yrot += yrSpeed;
}
(main.cpp)
GLvoid KeyboardInput(GLvoid) {
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;
}
…
The movement code doesn’t work. The rotating code works fine; I can point it any direction I want, but getting it to move in that direction doesn’t do anything. It just stays in place no matter how long you hold down RSHIFT or RCONTROL.
I figure the error is probably in the math somewhere (of which I know nothing, lol!). I here talk of vectors and matrices and this code doesn’t mess with any of that.
Anybody see what I’m doing wrong? Thanks in advance! You guys have been a big help!
- = TEFLON DRAGON = -