direction and rotation

Started by
1 comment, last by rfterdarc 18 years, 4 months ago
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 ?
Advertisement
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 :)

This topic is closed to new replies.

Advertisement