Move direction in 3D?

Started by
1 comment, last by Ivan Mandic 15 years, 6 months ago
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..
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.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Thanks man..Smal changes and it works perfect..

This topic is closed to new replies.

Advertisement