//
Analog Wall Clock
//
Created by Water Rogers
for IBM/Opensource
//
Purpose
//
--------------------------------------------------------------
//
This purpose of this script is to show llRotateTexture() in
//
action. It also uses multiple
scripts in different links of
//
the object.
//
Requirements
//
--------------------------------------------------------------
//
3 Prims are required for all 3 functions, as well as a texture
//
that looks like a clock hand where the rotation of the object's
//
Roll is 0 degrees.
//
Usage
//
--------------------------------------------------------------
//
Put this script into an object, and use the function desired.
//
Hours, minutes, and seconds all affect how and when the texture
//
will rotate.
//
EVENTS
//
--------------------------------------------------------------
display_hours()
{
// Get
the
wallclock, and in order to figure out the hours, divide
// the
seconds
returned from wallclock by 60, then divide that number
// by 60. This will return the hour of the day (in
military time).
// Since
this is
the hour hand, we take 360 degrees (a full circle)
// and
divide it
by 12 (the hours on a clock). This
returns 30
// degrees
-
multiply by the current hour, then translate the remainder
// to
Radians,
since that's how rotations are interpretted in SL.
llRotateTexture(-(((llGetWallclock()
/ 60) / 60) * 30) * DEG_TO_RAD, ALL_SIDES);
}
display_minutes()
{
// The
same logic
applies to minutes, as with hours, except this time we
// are
only
interested by how many minutes have passed rather then hours.
// One
less
mathmatical computation. Also, 360
divided by 60 segments
// equates
to 6
degrees.
llRotateTexture(-((llGetWallclock()
/ 60) * 6) * DEG_TO_RAD, ALL_SIDES);
}
display_seconds()
{
// Same
as the
other two, except the wallclock already returns how many
// seconds,
so
there is no need to do any other math other then to translate
// to
radians and
rotate the texture.
llRotateTexture(-(llGetWallclock()
* 6) * DEG_TO_RAD, ALL_SIDES);
}
default
{
state_entry()
{
// Call
the
function that this object will represent.
This particular
// object
happens
to be the "seconds" hand of the clock. The
other 2
// will
call the
other 2 respectively.
display_seconds();
llSetTimerEvent(1); //change
this to (15) for minutes and (60) for hours for better function in OS.
timer()
{
display_seconds();
}
}