PDA

View Full Version : Rotating a directional light 360 degrees about a single axis



kevinfishburne
08-29-2012, 10:01 PM
I have some code:


' Update solar light source direction.
SolarPosition[0] = Unknown
SolarPosition[1] = 0
SolarPosition[2] = 1
SolarPosition[3] = 0
Gl.Lightfv(Gl.LIGHT0, Gl.POSITION, SolarPosition)

I realize that a directional light uses a vector to determine its direction but can't figure out what values should be used to make it spin continuously about one axis, simulating the sun. I can get it to bounce between what appears to be a 180 degree arc, but I can't get it to a full cycle. Experimental values produce illogical results. What am I missing here?

thokra
08-29-2012, 11:29 PM
Post your rotation math pls. The stuff you posted is merely what you want to do after calculating the new, rotated direction.

kevinfishburne
08-31-2012, 10:59 PM
This seems to work:


Dim cs As Single
Dim sn As Single
Dim x As Single
Dim y As Single
Dim px As Single
Dim py As Single

' Calculate solar direction vector.
cs = Cos(Rad(360 - SanctimoniaOrientation + 90))
sn = Sin(Rad(360 - SanctimoniaOrientation + 90))
x = 0
y = 1
px = x * cs - y * sn
py = x * sn + y * cs

' Set solar light source direction.
SolarPosition[0] = py
SolarPosition[1] = 0
SolarPosition[2] = px
SolarPosition[3] = 0
Gl.Lightfv(Gl.LIGHT0, Gl.POSITION, SolarPosition)

Some notes: I inverted the Y axis with a modelview matrix scale transformation and SanctimoniaOrientation is the axial orientation of the planet where noon is at 180 degrees and midnight is at 0/360 degrees.

Let me know if you need more help with these sorts of things, as I know math isn't your strong suit. Good luck with your project!

thokra
09-01-2012, 12:47 AM
Let me know if you need more help with these sorts of things, as I know math isn't your strong suit. Good luck with your project!

Ehm ... what? :confused:

kevinfishburne
09-01-2012, 01:21 AM
Just a sad attempt at humor, or at least being passive-aggressive. Ignoring all that, I hope the code I came up with is reasonably correct for my purpose.