#VRML V2.0 utf8 # Modification History # When Who What # ---- --- ---- # 97.08.08 LTD Creation WorldInfo { title "Clock" info ["Authored by Leonard Daly", "Version 1.0", "Copyright 1997, Leonard Daly"] } # Define background coloring and landscapes Background { groundColor [ 0. .3 0., 0. .4 0., 0. .5 0. ] groundAngle [1.05, 1.57] skyColor [ 0. 0. .2, .1 .1 .5, .2 .2 .7 ] skyAngle [1.05, 1.57] # rightUrl "../textures/east.png" # leftUrl "../textures/west.png" # topUrl "../textures/gpsRec.gif" # bottomUrl "../textures/gpsRec.gif" # frontUrl "../textures/north.png" # backUrl "../textures/south.png" } # Build Clock Group { children [ # DEF CLOCK_TOUCH TouchSensor { }, DEF FACE Transform { translation 0 0 0 rotation 1 0 0 1.57 children [ Shape { appearance Appearance { material Material { diffuseColor 1 1 1 transparency 0 } } geometry Cylinder { height 0.01 radius 2.0 } } ] } ] } # Define Minute Hand Group { children [ # DEF MINUTE_TOUCH TouchSensor { }, DEF MINUTE_HAND Transform { rotation 0 0 1 0.0 translation 0 .75 0 scale 1 1 1 children [ Shape { appearance Appearance { material Material { diffuseColor 1. 0. 0 } } geometry Cone { bottomRadius .2 height 1.5 side TRUE bottom TRUE } } ] } ] } # Define Hour Hand Group { children [ # DEF HOUR_TOUCH TouchSensor { }, DEF HOUR_HAND Transform { rotation 0 0 1 0.0 translation 0 .5 0 children [ Shape { appearance Appearance { material Material { diffuseColor 0. 0. 1. } } geometry Cone { bottomRadius .3 height 1.0 side TRUE bottom TRUE } } ] } ] } # Define sweep second hand DEF SECOND_HAND Transform { rotation 0 0 1 0.0 translation 0 .9 0 scale 1 1 1 children [ Shape { appearance Appearance { material Material { diffuseColor 0. 1. 0. } } geometry Cylinder { height 1.8 radius .05 side TRUE top TRUE bottom TRUE } } ] } DEF tempStart TimeSensor { cycleInterval 5 enabled TRUE loop TRUE } DEF worldStart TimeSensor { cycleInterval 4 enabled FALSE loop TRUE } DEF timerTick TimeSensor { cycleInterval 1 enabled FALSE loop TRUE startTime 1 stopTime 2 } DEF Counter Script { field SFFloat second 0 # system state field SFFloat minute 0 # system state field SFFloat hour 0 # system state eventIn SFTime increment eventIn SFTime initClock eventOut SFTime startTime eventOut SFBool isActive eventOut SFVec3f sec_pos # eventOut SFVec3f min_pos # eventOut SFVec3f hr_pos # eventOut SFRotation sec_rot # eventOut SFRotation min_rot # eventOut SFRotation hr_rot # url "vrmlscript: function increment (value) { second = second + 1; if (second > 59) { minute = minute + 1; second = 0; } if (minute > 59) { hour = hour + 1; minute = 0; } if (hour > 11) { hour = 0; } angle = 3.14159 * second / 30.; sec_rot[0] = 0; sec_rot[1] = 0; sec_rot[2] = 1; sec_rot[3] = - angle; sec_pos[0] = .9 * Math.cos(1.57 - angle); sec_pos[1] = .9 * Math.cos(- angle); sec_pos[2] = 0; angle = 3.14159 * minute / 30.; min_rot[0] = 0; min_rot[1] = 0; min_rot[2] = 1; min_rot[3] = - angle; min_pos[0] = .75 * Math.cos(1.57 - angle); min_pos[1] = .75 * Math.cos(- angle); min_pos[2] = 0; angle = 3.14159 * (hour + minute/60.) / 6.; hr_rot[0] = 0; hr_rot[1] = 0; hr_rot[2] = 1; hr_rot[3] = - angle; hr_pos[0] = .5 * Math.cos(1.57 - angle); hr_pos[1] = .5 * Math.cos(- angle); hr_pos[2] = 0; } // Initialize Hand positions function initClock (time) { current = time % 86400; current = Math.floor (current); second = current % 60; minute = ((current-second) % 3600 ) / 60; hour = Math.floor (current / 3600); if (hour > 11) { hour = hour - 12; } second = second - 1; increment (time); startTime = time; isActive = TRUE; } " } ROUTE tempStart.isActive TO worldStart.enabled ROUTE worldStart.cycleTime TO Counter.initClock ROUTE Counter.isActive TO timerTick.enabled ROUTE Counter.startTime TO timerTick.startTime ROUTE timerTick.cycleTime TO Counter.increment ROUTE Counter.sec_pos TO SECOND_HAND.translation ROUTE Counter.sec_rot TO SECOND_HAND.rotation ROUTE Counter.min_pos TO MINUTE_HAND.translation ROUTE Counter.min_rot TO MINUTE_HAND.rotation ROUTE Counter.hr_pos TO HOUR_HAND.translation ROUTE Counter.hr_rot TO HOUR_HAND.rotation