Jump to content
  • Advertisement
Sign in to follow this  
Ivan Mandic

Move direction in 3D?

This topic is 3552 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

Hello everyone. I need code for moving in 3D. Something like this(2D moving): xpos += (float)sin(angle*0.0174532925f); ypos += (float)cos(angle*0.0174532925f); Only with 2 angles and z.. p.s. Thanks,and sorry for my bad English..

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Ivan Mandic
Something like this(2D moving):
xpos += (float)sin(angle*0.0174532925f);
ypos += (float)cos(angle*0.0174532925f);
Only with 2 angles and z..
You need to convert a spherical coordinate (represented by 2 angles and a radius), to a cartesian coordinate (represented by x, y, z):

For simplicity, you can regard it as a unit sphere, so R=1, which cancels R entirely from the preceding equations. So you are left with:
x = sin(theta)*cos(omega)
y = sin(theta)*sin(omega)
z = cos(theta)

Where theta and omega are your 2 angles.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!