Jump to content
• Advertisement

Archived

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

3D movement in space with OpenGL

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, here we go... I have some problems with the movement in OpenGL in 3D. I use the glTranslatef and glRotatef commands for the movement in the code I made so far. glTranslatef to get another coord like this: glTranslatef(player.x, player.y, player.z); player.x is increased when pressing W, and decreased when pressing S player.z is increased when pressing D, and decreased when pressing A This uses strafing. But now, I want to rotate, and move forward again using the new angel. If I use glRotatef, I can rotate, say, 45 degrees on the x axis. When I press W though, to move again, it increases the player.x value, which doesn''t move me forward with the new angle, but with the old one! So I can''t really make the player move towards the new set angle. And even worse, I have absolutely NO CLUE how to do it in 3D!!! Add the point that space-movement is even harder, because there is no thing like gravity and other forces to let you stop, you can see that I am absolutely lost! Oh, I program with Visual C++ and use OpenGL, not GLUT! If anyone can help me on this, please mail me about it or post it here. My e-mail address is HNSProgramming@hotmail.com (old address ) Source examples are also welcome. It doesn''t matter if you use other commands than glRotatef and glTranslatef, as long as it works

Share this post

Share on other sites
Advertisement
true moving like so...

player.x += sin(angle*3.1415/180) * speed;
player.z += cos(angle*3.1415/180) * speed;

//not depending on how you do things, you may need to use - instead of + or switch cos/sin around.

Share this post

Share on other sites
hmmmmmm yeah I thought about sin and cos for a little while... I just thought there''d be an OpenGL-implemented function for this movement though, so I don''t have to calculate it all...

Share this post

Share on other sites
WTF? How lazy can you get.. it''s 2 calls, 1 to cos, and 1 to sin. How is opengl going to hide that for you?

I''ll make it nice and simple for you:

glMovePlayer(PlayerS &p, float Speed)
{
p.x += sin(p.angle*3.1415/180) * Speed;
p.z += cos(p.angle*3.1415/180) * Speed;
}

Simply call glMovePlayer(Player,1), or glMovePlayer(Player,-1) to move your player forward/backwards.. how much simpler can it get?

Share this post

Share on other sites
ehhhhhhhhhhhh ok it''s that simple I guess I just lacked of math intelligence to see that thank you very much for helping me out

Share this post

Share on other sites

• Advertisement

Announcements

• Advertisement

• Popular Contributors

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5
• Advertisement

• 11
• 37
• 12
• 12
• 11
• Forum Statistics

• Total Topics
631413
• Total Posts
2999945
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!