|
Torin Golding
Misanthropic Humanist
Join date: 13 Sep 2005
Posts: 41
|
04-23-2007 20:20
Hello scripters I hope some math whizes can help this Humanities person out. I want to create a script using llGetSunDirection(); on a timer to trigger 12 different events during the SL day. The event will be simply changing a texure on a prim, so no biggie. As I understand the wiki, since the ratio to day:night is 3:1, I should be able to divide the SL day up into 12 neat parts: From: someone Day 1 (Display texture 1) Day 2 (Display texture 2) Day 3 (Display texture 3) Day 4 (Display texture 4) Day 5 (Display texture 5) Day 6 (Display texture 6) Day 7 (Display texture 7) Day 8 (Display texture  Day 9 (Display texture 9) Night 1 (Display texture 10) Night 2 (Display texture 11) Night 3 (Display texture 12) Theoretically I should be able to call llGetSunDirection(); and based on the vector being greater or less than a certain degree, either keep the current event going or switch to the next one. Trouble is I can't figure out the vector numbers (or presumably just the z) to make the if/else statements in my script. Can anyone help me with an example or a suggestion of how to accomplish this? Many thanks in advance!
|
|
Brenham Beale
Registered User
Join date: 26 Aug 2006
Posts: 65
|
04-23-2007 22:28
The LSL Wiki might help you (this isn't the Second Life wiki, which tends to have even less info than its mirror sites).
Specifically here: http://www.lslwiki.net/lslwiki/wakka.php?wakka=llGetSunDirectionI searched the forums and came across these threads: 125628107757All the math and code made my head spin. I couldn't tell if there was a definitive answer on what angle numbers corresponds to sun direction. You might be able to make more sense of it than I could.
|
|
Torin Golding
Misanthropic Humanist
Join date: 13 Sep 2005
Posts: 41
|
04-23-2007 23:04
Hi Brenham. Thanks. Yes I saw those threads too but couldn't understand any of the trig. I saw the LSL Wiki as well (that's where I got the 3:1 ratio) but couldn't find any way to trigger an event based on a specific part of the SL day. I presume it's probably straightforward, but I just can't figure out the math either. 
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
04-24-2007 01:14
From: Torin Golding Hi Brenham. Thanks. Yes I saw those threads too but couldn't understand any of the trig. I saw the LSL Wiki as well (that's where I got the 3:1 ratio) but couldn't find any way to trigger an event based on a specific part of the SL day. I presume it's probably straightforward, but I just can't figure out the math either.  llGetSunDirection returns a normalised vector, i.e. values are -1.0 to +1.0 not degrees. I have not played with this but I expect that the sun height will be cycling , i.e. it will have the same height as it ascends in the 'morning' and descends in the 'afternoon' so a straight z comparison will give incorrect results. You will also find that the any script using llGetSunDirection will not respond to "force sun" which only affects your local client.
|
|
Ralph Doctorow
Registered User
Join date: 16 Oct 2005
Posts: 560
|
04-24-2007 06:51
If you want to do a clock as opposed to something like a sundial, you can also just use llSetTimerEvent to go off every half hour or so and just count where you are. However, to keep it accurate, I'd suggest you call llGetWallclock to make small adjustment in each timer delay so errors don't build up. If you want to make something like a sundial, just set a timer for say 5 minutes and keep track of just the X and Z values returned from llGetSunDirection. Z is max at noon, min (neg) at midnight, 0 at sunup and sun down. X is max at sunrise, min (neg) at sunset. Don't look at absolute values, look at min and max and interpolate between them.
|
|
Winter Ventura
Eclectic Randomness
Join date: 18 Jul 2006
Posts: 2,579
|
04-24-2007 13:37
The unfortunate problem is, any system that doesn't rely on the sun's position, will fail on private islands where the day/night cycle is different (or stopped). However, as the days are only 4-5 hours long in most sims, it wouldn't take too much work to do some tests of the math to check time against the sun. I note that Kyrah Abattoir made a really neat clock, not too long ago, that uses the sun's position. /15/cc/166419/1.htmlThis also looks useful.. for determining day/night: /15/ec/172164/1.htmlAnd here's a bit of code that I love.. From the "Giving Campfire".. Open Source script by Apotheus Silverman, found within the "Giving Campfire" freebee by Cherry Asturias list daySounds = ["American Oriole", "Cardinal", "Robin", "Song Sparrow", "Tree Swallow", "Locust"]; list nightSounds = ["Great Horned Owl", "wolfie.wav", "wolf_howl++"];
list nightAmbient = ["Cricket"];
default { state_entry() { llStopSound(); llSetTimerEvent(2.0); }
timer() { vector time = llGetSunDirection(); list myList; float density = 0.9;
if (time.z > 0.0) { myList = llListRandomize(daySounds, 1); } else { myList = llListRandomize(nightSounds, 1); density = 0.98; // Ambient nighttime sound if (llFrand(1.0) > 0.85) { llStopSound(); } else { llLoopSound(llList2String(nightAmbient, 0), 1.0); } } if (llFrand(1.0) > density) { llTriggerSound(llList2String(myList, 0), 1.0); } } }
_____________________
 ● Inworld Store: http://slurl.eclectic-randomness.com ● Website: http://www.eclectic-randomness.com ● Twitter: @WinterVentura
|