Forward Movement no matter what rotation
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
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
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
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
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
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
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement