Jump to content
  • Advertisement
Sign in to follow this  

direction and rotation

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

directx lights have a direction property. if i want the light to have a rotation of ( 50, 25, 0 ) degrees, how do i turn a 'rotation' in to a 'direction' and vv ?

Share this post

Link to post
Share on other sites
I believe the easiest way to turn directions into angles is through spherical coordinates. You can take your direction vector, project it into spherical coordinates, and you'll get 3 coordinates (r,phi,theta) where r is the magnitude of your vector, phi=its longitude (pitch angle) and theta its latitude (yaw).
You can do the exact opposite when you want to derive the direction from the angles.

The equation for switching between cartesian-spherical are:
(I must have posted these 10 times! lol)

'mag' is the magnitude (length) of the vector

cartesian -> spherical
mag = sqrt( sqr(x)+sqr(y)+sqr(z) )
phi = atan(y/x)
theta = atan( z/sqrt(sqr(x)+sqr(y))

spherical -> cartesian
x = mag*cos(phi)*cos(theta)
y = mag*sin(phi)*cos(theta)
z = mag*sin(theta)

some implementations of atan return values in (-pi/2,pi/2). Use one that takes into account the quadrant in which your point is, like atan2. Its range is (-pi, pi)
e.g. phi=atan2(y,x)
theta = atan2( z, sqrt(blah blah) )

[Edited by - someusername on November 30, 2005 12:18:28 PM]

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!