Using llGetSunPosition to calculate phase of day/night cycle
|
|
EF Klaar
Registered User
Join date: 11 Jun 2007
Posts: 330
|
07-18-2009 08:02
It's that wristwatch again!
I would like to add a hand that indicates the local regional time of day (as in sunrise, midday, sunset, midnight) on a circular scale (in this case the 8:30 position is sunrise, the 12:00 position is noon, the 4:30 position is sunset and the 6:00 position is midnight).
The necessary information can be got by calling llGetSunPosition, but my vector math and my trigonometry skills are rubbish. And this isn't helped by the fact that the sun moves three times faster during the day than during the night.
I already have one "daylight" hand that shows this information based on the actual time, but I'd like to add one that shows the regional sun position in regions using their own setting, and the small seasonal variation from the "theoretical" position, if any, in regions using the default word sun.
My eternal gratitude to anyone who can point me at a code fragment that'll convert the llGetSunPosition vector to a number indicating what phase of the day/night cycle I am in, or to an angle on the circular dial I descibed above.
|
|
Rygel Ryba
Registered User
Join date: 12 Feb 2008
Posts: 254
|
07-18-2009 08:23
Being in the same boat you are (ie. blowing at vector math, lol) I would use the llGetTimeOfDay function... http://wiki.secondlife.com/wiki/LlGetTimeOfDayusing that code, you just need to figure out where you are at in a 4 hour clock. 1/2 hour into it, is sunrise. 2 hours into it is high noon. Sunset will be at 3.5 hours into the cycle and at mightnight it'll reset.
|
|
SuezanneC Baskerville
Forums Rock!
Join date: 22 Dec 2003
Posts: 14,229
|
07-18-2009 08:26
Is that the same as llGetSunDirection?
_____________________
-
So long to these forums, the vBulletin forums that used to be at forums.secondlife.com. I will miss them.
I can be found on the web by searching for "SuezanneC Baskerville", or go to
http://www.google.com/profiles/suezanne
-
http://lindenlab.tribe.net/ created on 11/19/03.
Members: Ben, Catherine, Colin, Cory, Dan, Doug, Jim, Philip, Phoenix, Richard, Robin, and Ryan
-
|
|
EF Klaar
Registered User
Join date: 11 Jun 2007
Posts: 330
|
07-18-2009 08:48
From: Rygel Ryba Being in the same boat you are (ie. blowing at vector math, lol) I would use the llGetTimeOfDay function... Yes, that'd make sense  But... How would I calculate the fixed sun position when llGetTimeOfDay returns a value greater than 4.0 * 60.0 * 60.0, which will be the time since the region restart in a region with a fixed sun, which, for some reason, is what it does do? I guess I'd be willing to live with the four hours that it'd be completely wrong immediately after a region restart in a fixed sun region.
|
|
Rygel Ryba
Registered User
Join date: 12 Feb 2008
Posts: 254
|
07-18-2009 09:11
You could also do some basic conditionals too. If it's 30 minutes into the cycle but the sun z is very high or very low (i.e. nowhere near 0) - the then you know it's a fixed sun. if it's near midnight or noon according to the time, but your X (your east west) is nowhere near 0, then you know the sun is fixed too.
I dunno. It's very basic checks I'm doing here. A math wiz would surely be able to do a lot better.
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
07-18-2009 21:17
forget seasonal shifts... they may be in the server code, but they haven't shown since the windlight viewer went live (yes this means it'll never actually agree with what the server sends back)
you can forget all the annoying vector math too as the z vector is on the circle and the whole thing is normalized
vPosChk = llGetSunDirection() llSetRot( llEuler2Rot( < 0.0, 0.0, llAtan2( vPosChk.x, vPosChk,z ) > ) );
or thereabouts
ETA: that'll give you a balanced 50.50 dial, day night... if you REALLY want to balance it by the hours, multiple the return from llAtan2 by .5, if z < 0 and 1.5 if > 0
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
SuezanneC Baskerville
Forums Rock!
Join date: 22 Dec 2003
Posts: 14,229
|
07-18-2009 22:12
llSetPos with a rotation as the parameter?
_____________________
-
So long to these forums, the vBulletin forums that used to be at forums.secondlife.com. I will miss them.
I can be found on the web by searching for "SuezanneC Baskerville", or go to
http://www.google.com/profiles/suezanne
-
http://lindenlab.tribe.net/ created on 11/19/03.
Members: Ben, Catherine, Colin, Cory, Dan, Doug, Jim, Philip, Phoenix, Richard, Robin, and Ryan
-
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
07-19-2009 01:44
From: SuezanneC Baskerville llSetPos with a rotation as the parameter? see what I get for running through too quickly.... shoulda been setRot.
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
EF Klaar
Registered User
Join date: 11 Jun 2007
Posts: 330
|
07-19-2009 14:16
From: Rygel Ryba You could also do some basic conditionals too. If it's 30 minutes into the cycle but the sun z is very high or very low (i.e. nowhere near 0) - the then you know it's a fixed sun. if it's near midnight or noon according to the time, but your X (your east west) is nowhere near 0, then you know the sun is fixed too.
I dunno. It's very basic checks I'm doing here. A math wiz would surely be able to do a lot better. Also, I just spotted the REGION_FLAG_FIXED_SUN flag in llGetRegionFlags 
|
|
EF Klaar
Registered User
Join date: 11 Jun 2007
Posts: 330
|
07-19-2009 14:19
From: Void Singer vPosChk = llGetSunDirection() llSetRot( llEuler2Rot( < 0.0, 0.0, llAtan2( vPosChk.x, vPosChk,z ) > ) ); Void, you have my eternal gratitude 
|
|
Rygel Ryba
Registered User
Join date: 12 Feb 2008
Posts: 254
|
07-19-2009 14:50
Nice. New the math whizzes would come through and show me up sooner or later. 
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
07-19-2009 17:32
me != math whiz, me = location whiz (I pretty much did that from memory of a wiki example, or maybe it was someones orrery, meaning the location was... some page somewhere =X )...
seriously though, I actually flunked trig 3 times (not because I can't get it, but because I can't keep it in memory... so I have to look up formulas)
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
07-20-2009 07:18
From: Void Singer forget seasonal shifts... they may be in the server code, but they haven't shown since the windlight viewer went live (yes this means it'll never actually agree with what the server sends back) /me has never quite gotten this - how did Windlight break llGetSunDirection? I remember hearing at the time that it wasn't accurate any more but.. why?
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!! - Go here: http://jira.secondlife.com/browse/SVC-1224- If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
07-20-2009 09:47
From: Meade Paravane /me has never quite gotten this - how did Windlight break llGetSunDirection? I remember hearing at the time that it wasn't accurate any more but.. why? apparently the viewer does it's own simplified calculation now (or maybe it the otherway around I forget now) but the view of the sun no longer show the same as is being calculated elswhere... it's not a huge difference, but the seasonl shifts are ignored now, which means the timing is off by a small amount (the shift that's no longer being shown)
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|