Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Rotation sunrise/sunset

Wyatt Weatherwax
Registered User
Join date: 23 Oct 2007
Posts: 59
02-21-2009 05:13
OK, I've worked on this off and on work a week know and can't seem to get it right. Using math and testing it seems OK but checking on it after a time it always not what I expect to see. I want a prim and texture representation of the SL sun rising and traveling thru the sky and setting (rising on the left and setting on the right. It will be seen as the top half of a vertical facing circle (the bottom half will be masked). I'm using a texture rotation and need it to rotate 180 degrees in 3 hours (the SL day length). I reset the hand using the llGetTimeOfDay or free it to rotate at the calculated sunrise rime of 1900 seconds. Below is the script, thanks for any help.

//Start Code

float rotate;

default
{
state_entry()
{
llGetTimeOfDay( );
rotate = 270 * DEG_TO_RAD;

//llSetPrimitiveParams([ PRIM_TEXTURE, ALL_SIDES, "78353051-ef9c-002f-f5db-68773b22f2dd", <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0 ]);
llSetTimerEvent(40);

}

timer()
{

rotate = rotate + 0.5 * DEG_TO_RAD;

llGetTimeOfDay( );
float TOD = llGetTimeOfDay( );
if (TOD > 1900)
{
// rotate = 0;
llRotateTexture(rotate*-1,ALL_SIDES);
}
else

llSetPrimitiveParams([ PRIM_TEXTURE, ALL_SIDES, "78353051-ef9c-002f-f5db-68773b22f2dd", <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 90 * DEG_TO_RAD ]);
}
}

//End Code
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
02-21-2009 11:06
An SL "day" is 4 hours long, with 3 hours of daylight and 1 hour of night, therefore, the sun "moves faster" at night to traverse the same distance at night (in 1 hour) that it does during the day, (in 3 hours). Therefore, you're probably going to want to use llGetSunDirection() not llGetTimeOfDay() to determine the position of the sun. llGetSunDirection returns a normalized vector, and you're looking for the sun's elevation, so what you need to do is something along the lines of this...
integer face = 1;
vector sun = llGetSunDirection();
eul = <sun.z * 90-90,0,0>;
eul *= DEG_TO_RAD;
rotation quat = llEuler2Rot (eul);
llRotateTexture (quat, face);

...where face is the face number you want to rotate. In this case I chose 1, but you can change that to the face you need (or rotate all sides with ALL_SIDES).

Hope that helps.
_____________________
My tutes
http://www.youtube.com/johanlaurasia
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-21-2009 15:24
The sun actually doesn't move "faster" at night. They just screwed with the orbit such that the sun has a "shorter" path below ground than it does above.

See /54/1b/303299/1.html for more info.
Wyatt Weatherwax
Registered User
Join date: 23 Oct 2007
Posts: 59
02-21-2009 20:24
Thanks for the replies. I had considered using the sun's angle but the time of day thing seems so neat I though I give it a try. Seems to be more trouble than it's worth. I'll try and rework the script this week and see how it goes.

Can you explain the 90-90 part of this code? eul = <sun.z * 90-90,0,0>;


Thanks
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
02-21-2009 21:31
order of operations? apparently * 90 is an overcompensation, so (sun.z * 90) - 90 would be the way it's read. it just fixes the rotation to a certain direction for convenience.

thought: is that formula right? I would have thought the vector for sun direction came back in radians? neither LSL Portal nor lslwiki seems to say, and I've never used the exact rotation, only the day/night version
_____________________
|
| . "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...
| -
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-21-2009 23:37
Hmm. I have no idea what that line's supposed to be doing either. llRotateTexture() takes a scalar angle, not a quaternion. Now...

z*90-90 = (z-1)*90

which will range from 0 when the sun is straight overhead (usually never happens, even at noon) to -180 when the sun is straight down (again usually doesn't happen even at midnight), and yes, -90 when the sun is at the horizon (that part at least should work correctly). Using the z-component alone like that will not differentiate between AM and PM, so sunrise and sunset will look exactly the same.

Probably a more useful measure for "timekeeping"--giving you true "noon", "midnight", "sunrise", and "sunset" (though don't expect them to happen at regular intervals because of the extremely artificial orbit of the sun)--would be:

CODE

vector sunDir = llGetSunDirection();
float angle = llAtan2(sun.z, sun.x);
if (angle < 0.0)
{
angle += TWO_PI;
}


When angle=0, it's sunrise. When angle=PI/2 it's noon (sun as straight overhead as it's going to get). When angle=PI, it's sunset. When angle=(3/2)*PI, it's midnight (sun as straight underfoot as it is going to get). At least the Lindens kept the orbit pretty much symmetrical about the yz-plane, even though they did mess with it plenty in other ways.

[EDIT: Corrected logic for negative atan results.]
Wyatt Weatherwax
Registered User
Join date: 23 Oct 2007
Posts: 59
02-22-2009 04:30
Being "on the road" I can't test these ideas but I do know that sun.z at sunrise is 0.0 and increases to about 1.0 at noon and then backs down to 0.0 at sunset. The numbers then turn negative as the sun travels below the horizon. In part, this is why I was using a timer and not the sun's position to rotate the texture. I was (am) having trouble calculating the increments that it would take (in rotation units) to travel the 180 degrees of "day". Once below the horizon the image would be masked by another prim so position accuracy is not needed. All I need then is a trigger to reset the position at sunrise back the the horizon. I was using llGetTimeOfDay for that. Not having the time to watch this thing rotate for 4 hours and my maths not working, I just don't know if I have the movement/rotation worked out correctly. Peaking in from time to time, I'd so "no". However, I will explore these ideas when I get home.

Thanks