PDA

View Full Version : Confused about rotation and translation



teflon_dragon
04-01-2002, 07:22 AM
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 = -

nexusone
04-01-2002, 09:07 AM
Here is some of my code:

void My_display(void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLoadIdentity();
glMatrixMode(GL_MODELVIEW);

glPushMatrix();


glRotatef(WrotateX, 1.0f, 0.0f, 0.0f); //Rotate world and not the camara.
glRotatef(WrotateY, 0.0f, 1.0f, 0.0f);
glRotatef(WrotateZ, 0.0f, 0.0f, 1.0f);
glTranslatef( 0,0, Worldz); // move world on z plane

glTranslatef(My_Object[(int)j].Curent_point.xyz[0], My_Object[(int)j].Curent_point.xyz[1], My_Object[(int)j].Curent_point.xyz[2]); // Move my object to it point in space.

glRotatef(My_Object[(int)j].Rotation_x, 1.0f, 0.0f, 0.0f); // Rotate object on axis
glRotatef(My_Object[(int)j].Rotation_y, 0.0f, 1.0f, 0.0f);
glRotatef(My_Object[(int)j].Rotation_z, 0.0f, 0.0f, 1.0f);
glScalef(xscale, xscale, xscale); // scale object
Draw_My_Object();

glPopMatrix();

}


Originally posted by teflon_dragon:
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)


- = TEFLON DRAGON = -



[This message has been edited by nexusone (edited 04-01-2002).]

teflon_dragon
04-01-2002, 09:52 AM
Many thanks Nexusone, you've been a big help these past few weeks!

Well, I've solved half the battle...

the only thing that recognizes VK_R and VK_L stuff is GetAsyncKeyState() .. so turns out this whole time no changes were being made to the triangle's coordinates.

How can I figure out what point is at the tip of the Flyer no matter which way it is facing, and then give that point to my translation funtion?

- = TEFLON DRAGON = -

[This message has been edited by teflon_dragon (edited 04-01-2002).]

nexusone
04-01-2002, 11:56 AM
I am currect that you want your world to move but not your ship as if you are the pilot of it?


Originally posted by teflon_dragon:
Many thanks Nexusone, you've been a big help these past few weeks!

Well, I've solved half the battle...

the only thing that recognizes VK_R and VK_L stuff is GetAsyncKeyState() .. so turns out this whole time no changes were being made to the triangle's coordinates.

How can I figure out what point is at the tip of the Flyer no matter which way it is facing, and then give that point to my translation funtion?

- = TEFLON DRAGON = -

[This message has been edited by teflon_dragon (edited 04-01-2002).]

teflon_dragon
04-01-2002, 03:53 PM
Right now I am only wanting the ship to move, I'll add 1st / 3rd person cameras later.

I want the camera (view port) to remain stationary and only the ship to move. Thanks!

- = TEFLON DRAGON = -

nexusone
04-01-2002, 06:37 PM
Try and setup your drawing routine like the example I posted....
Let me know if it works for you.
http://www.opengl.org/discussion_boards/ubb/smile.gif


Originally posted by teflon_dragon:
Right now I am only wanting the ship to move, I'll add 1st / 3rd person cameras later.

I want the camera (view port) to remain stationary and only the ship to move. Thanks!

- = TEFLON DRAGON = -