• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# problem with moving and rotating objects

## Recommended Posts

Knuffy    122
I was going to program just a rocket flying around(you can guide it) i use glRrotatef(rotate, 0.0f, 1.0f, 0.0f) when i want to turn the rocket from the left to the right. but the rocket is moving in the direction the rocket is pointing at. when it moves just straigt i could use translatef(0.0f, 0.0f,z) while z is the "speed" of the rocket, but when i turn it how do i calculate the new position? I know Ì could use tan, cos, sin but what is the angle? I turn it in my program "rotate=rotate+0.1" right now. 0.1 how much is that in degree?

##### Share on other sites
alargeduck    122
you know, if you rotate first and then translate...

##### Share on other sites
ATronic    122
I''m not very with it right now, but I''ll give it a try. I think it''s something along the lines of

  rocket.x += (sin(rocket.xrotation)*rocket.speed);rocket.y += (cos(rocket.xrotation)*rocket.speed);rocket.z += (sin(rocket.zrotation)*rocket.speed);

I think I mixed up the sin/cos'' but I''m not sure. Experiment a little. Someone correct me if I''m wrong. Or rather, HOW I''m wrong.

A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."

##### Share on other sites
ATronic    122
Oh, and alargeduck, that will not work. Doing what you said will rotate the entire path of the rocket, making it look as if it were attacked to the end of a swinging stick. It would work, however, if the heading never changed. Very limiting indeed.

A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."

##### Share on other sites
alargeduck    122
Atronic, you are right, what I suggested wont work.

What you are suggesting is right, except that x should be based on cos, y on sin. Remeber that 0 degrees points down the positive x axis.

##### Share on other sites
alargeduck    122
Atronic, you are right, what I suggested wont work.

What you are suggesting is right, except that x should be based on cos, y on sin. Remeber that 0 degrees points down the positive x axis.

xrotation = yaw, z rotation = pitch

##### Share on other sites
Knuffy    122
x += (cos(rotatex)*speed);
y += (sin(rotatex)*speed);
z += (sin(rotatey)*speed);
glTranslatef(x,y,z);
glRotatef(rotatex,1.0f,0.0f,0.0f);//moving up and down(and other way)
glRotatef(rotatey,0.0f,1.0f,0.0f);//moving from left to the right(and other way)

i put this in front of where is draw the object, when i move it(meaning i press up or down, left or right) the object "turns" right but it moves completly wrong and i can''t figure out how to fix it.

##### Share on other sites
Knuffy    122
x += (cos(anglex)*sin(angley)*speed);
y += (sin(anglex)*speed);
z -= (cos(anglex)*cos(angley)*speed);
glTranslatef(x,y,z);
glRotatef(rotatex,1.0f,0.0f,0.0f);//up down
glRotatef(rotatey,0.0f,1.0f,0.0f);//left right

UPDATE: i found an old mathbook of mine, and voila it works, when i start the programm and turn up the "rocket" moves up, same when i turn left and right, but when i try bot at once(turning sideways and pitch, doesn't mean both keys have to be pressed, just when i turn a bit up and then left for example)everything is all wrong

(btw: angle is in radians, not in degrees like rotate is)

Edited by - Knuffy on January 9, 2002 11:46:43 AM