Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Change throughout the day

Katanya Mistral
The Lonely Tigress
Join date: 6 Oct 2005
Posts: 87
02-12-2009 00:36
I have a sign that I want to change to a certain texture at different times of the day. Instead of just the normal day/night like in auto-lights, I need morning/afternoon/night.

I'm not sure how I do that, though I assume it has something to do with the sun's position. Could anyone give me a hint or point me in the right direction please?
_____________________
Visit my website: Katanya.net
My SL site: Kitty's SL Adventures
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
02-12-2009 00:45
Just sample the sun direction more often, and set up arbitrary check.

if(angle >= lowmidday && angle <= highmidday)
{
it's mid day
}

or something like that.. where low and high midday are the minimum and maximum angle you want for the sun... something like that :)
Katanya Mistral
The Lonely Tigress
Join date: 6 Oct 2005
Posts: 87
02-12-2009 07:55
From: Lazink Maeterlinck
Just sample the sun direction more often, and set up arbitrary check.

if(angle >= lowmidday && angle <= highmidday)
{
it's mid day
}

or something like that.. where low and high midday are the minimum and maximum angle you want for the sun... something like that :)


Alright, still a bit lost, think I haven't slept enough, but how would I add such an adaption into a script like below:
CODE

default
{
state_entry()
{
llSetTimerEvent(60);
}
timer()
{
vector sun = llGetSunDirection();
if(sun.z > 0)
{
llSetTexture("day_texture",ALL_SIDES);
}
else
{
llSetTexture("night_texture",ALL_SIDES);
}
}
}


Also, is that timer okay, or can it be set higher?
_____________________
Visit my website: Katanya.net
My SL site: Kitty's SL Adventures
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-12-2009 10:45
Well, I suppose you could do something like this, though be advised that they have modified the sun's path through the sky in a very strange way (it "orbits" a point to the South someplace ABOVE the ground in order to make the day longer than the night):

CODE

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

if (sunAngle < 0.4*PI)
{
// Morning
} else if (sunAngle < 0.6*PI)
{
// Midday
} else if (sunAngle < 0.8*PI)
{
// Afternoon
} else if (sunAngle < PI)
{
// Evening
} else
{
// Night
}
Katanya Mistral
The Lonely Tigress
Join date: 6 Oct 2005
Posts: 87
02-15-2009 09:46
Based on that, would this work?

CODE

default
{
state_entry()
{
llSetTimerEvent(60);
}
timer()
{
vector sunDir = llGetSunDirection();
float sunAngle = llAtan2(sunDir.z, sunDir.x);
if (sunAngle < 0.0)
{
sunAngle += TWO_PI;
}

if (sunAngle < 0.4*PI)
{
llSetTexture("morning_texture",ALL_SIDES);
} else if (sunAngle < 0.8*PI)
{
llSetTexture("afternoon_texture",ALL_SIDES);
} else
{
llSetTexture("night_texture",ALL_SIDES);
}

}
}
_____________________
Visit my website: Katanya.net
My SL site: Kitty's SL Adventures
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-15-2009 10:35
Sure. I'd think so. You might want some logic in there to see if the texture has changed from the last time. Not sure if setting a texture redundantly has any affect on clients and object update messages and such.