#### Archived

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

# Forward Movement no matter what rotation

This topic is 6378 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''m trying to better my OpenGL skills and I''m a bit stuck at the moment. I have a triangle (2d) that I can rotate with the keyboard, but how can I get it to move forward no matter what rotation it is at? (forward being the tip of the triangle) Movement is along the X and Y axis only. If you need more information let me know. Thanks! "I am convinced that He (God) does not play dice." -- Albert Einstein

##### Share on other sites
u need vars to hold position and angle:
float x,y,angle;

angle is the current direction for triangle(forward)

if UP key pressed{
x+=cos(angle);
y+=sin(angle);
}

position triangle using x,y as current point
rotate angle(*note that sin() and cos() take RADIANS NOTE DEGREES!!!)

Radians = Degrees * PI / 180

hope this helps

--I don''t judge, I just observe

Stuck in the Bush''s, Florida

##### Share on other sites
i 4got 2 tell u that the code above will move 1 unit every time. if u wanna move faster just multiply times ur speed.
i.e. wanna move 4 units each time:
x+=cos(angle)*4;
y+=sin(angle)*4;

--I don''t judge, I just observe

Stuck in the Bush''s, Florida

##### Share on other sites
Actually, that is very inefficient dude.

What you''re doing is is rotating and then translating.
You''ll notice that if you translate first, you''ll get what you''re looking for.

it explains it in the redbook on page 107

##### Share on other sites
quote:
Original post by Anonymous Poster

Actually, that is very inefficient dude.

What you''re doing is is rotating and then translating.
You''ll notice that if you translate first, you''ll get what you''re looking for.

it explains it in the redbook on page 107

so where is the inefficiency?? because i translated first? i don''t do opengl, i was just helpin the guy move the triangle.

--I don''t judge, I just observe

Stuck in the Bush''s, Florida

##### Share on other sites
Rotate first, then translate.

##### Share on other sites
Thanks for all of your help.

"I am convinced that He (God) does not play dice."
-- Albert Einstein

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 22
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631766
• Total Posts
3002219
×