# 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.

## 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 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)

edit:
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]

cheers :)

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 14
• 12
• 29
• 11
• 44
• ### Forum Statistics

• Total Topics
634856
• Total Posts
3019661
×