Please take a moment to consider if this thread is worth bumping.

## Recommended Posts

Those familiar with the llGetSunDirection know it's very easy to determine whether the sun is above or below the horizon. I am finding it very difficult to determine when, exactly, the sun is at it's zenith (high noon) or nadir (opposite the moon at midnight) using this function, however.

I am not concerned with the slight innacuracy with windlight, and I do not want to resort to timekeeping to determine when these two events occur; I just want zenith or nadir accoding to the SL sun's position <vector> alone. I am having difficulty interpreting the data from the llGetSunPosition vector and it appears to fluctuate quite a bit - and isn't nearly as concise and neat as " z axis is above / below 0."

Can anyone shed some light on how to best determne these two sun positions using LSL and the sun's reported position alone?

##### Share on other sites

given the seasonal shift that is in the sun direction code, it may be painful to calculate....

you'd need to calculate the angle of the plane that the sun is on, which will require two sampling of position. from there the easiest way would be to eliminate the angle, then zenith and nadir would be z = +/-1

##### Share on other sites

It's pretty much as simple as determining when it's on the horizon. Just as you can tell whether the sun is above or below the horizon looking at the z-axis, and know it just crossed the horizon when it transitions from positive to negative or back, you can look at the x-axis for whether it's east or west of your "longitude", and know that it's just past its zenith or nadir when the x-axis transitions from positive to negative or back. In theory, the sun is exactly on the horizon when z=0.0, and exactly at its zenith or nadir when x=0.0, but I'm not sure if it ever has that exact value, so you might have to watch for the transition across, or do a fuzzy compare.

Incidentally, the sun position updates every 10 seconds, so llSetTimerEvent(10.0) will let you poll the sun position and theoretically (in a world with no lag) catch every single value llGetSunDirection() returns during the day.  It would be sufficient to simply save the last result in a global variable, and check to see if the sign of x or z had changed since the last tick.  This would work even if you missed ticks due to lag, or use a longer time between timer events, say llSetTimerEvent(60.0) if you don't care to be more accurate than to the nearest minute.

##### Share on other sites

so obvious, dunno how I could've missed that... got caught up thinking about the seasonal shift that the obvious escaped me. Thanks for that Gaius

##### Share on other sites

llGetTimeOfDay() will return 0 seconds at midnight and 7200 seconds (2 hours) at noon
It is a function of the sun's position:smileyvery-happy: