Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Time, clock hands and offsets...

Yingzi Xue
Registered User
Join date: 11 Jun 2008
Posts: 144
11-09-2008 06:17
I have a clock script that moves hands in real time, using degrees of rotation according to the time (hour, minute, second each separately).

The following is my hour hand script. The hour hand moves as the hour transpires. The problem I have is when I start using offsets. If I enter a positive offset value the accuracy of the hour hand stays "positive", but if I enter a negative offset and use llFabs to convert the negative to a positive I end up losing the fractional difference and my hour hand goes that difference in the opposite direction (negative). My question is, what is causing the loss if a negative number for offset is used, but the script works fine with positive?

From: someone

integer offset;

load_defaults()
{
offset = -12;
}

default
{
state_entry()
{
load_defaults();
llSetTimerEvent(1);
}

timer()
{
float now = llGetWallclock();
float minute = (integer)now / 60;
float hour = minute / 60;

if (offset != 0)
{
hour = (hour + offset);

if (hour < 0) { hour = llFabs(hour);}

if (hour > 12)
{
do
{hour = hour - 12;}
while (hour > 12);
}
}

rotation hand_rot = llEuler2Rot(<0, 30 * hour * DEG_TO_RAD, 0>;);
llSetLocalRot(hand_rot);
}
}
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
11-09-2008 08:17
CODE

integer offset;

load_defaults()
{
offset = -12;
}

default {
state_entry() {
load_defaults();
llSetTimerEvent(1);
}

timer() {
float now = llGetWallclock();
float minute = (integer) now / 60;
float hour = minute / 60;
if (offset != 0) {
hour += offset;
if (hour < 0) {
hour += 12;
}
if (hour > 12) {
hour -= 12;
}
}
rotation hand_rot = llEuler2Rot(<0, 30 * hour * DEG_TO_RAD, 0 >);
llSetLocalRot(hand_rot);
}
}
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
ab Vanmoer
Registered User
Join date: 28 Nov 2006
Posts: 131
11-09-2008 08:59
Unless the timezone you are interested in has the same summer/winter time changeover date as Pacific time, you might want to use llGetGMTclock instead of llGetWallclock as your base time.
llGetWallclock is Pacific time and will be 7 or 8 hours behind UTC/GMT depending on the time of the year.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
11-09-2008 09:50
you could also prevent possible bad input by using offest = offset % 12, which will reduce any input over 12 to the range of +/-[0 - 12). assuming anyone besides you will edit it.

noticed you truncated your minutes, but not your hours using (integer)...
you can get the same partial movement running the hourhand in 12 minute increments, instead of 60, and using 6 degrees instead of 30... that would allow you to slow the timer down, without losing much in the way of smothness (and it'll avoid any reappearance of the change not showing on the viewer because it was too small)

another thing you might look into is a single timer sending link messages to all the hands, then let them do their own scale tweaks from there, so you don't have 2-4 timers going (#4 is the sun/moon dial on grandfather clocks)

oh and you can do away with that extra minutes variable, and just use 3600 instead of using 60 twice

also be aware sim time dilation may affect how smooth you clock timer runs
_____________________
|
| . "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...
| -