A simple 3D analog clock - No models needed.
As I move more of my work to DBPro, I need to master the various idiosyncrasies of the engine. One of these is the apparent absence of rotations around a world-relative-reference. Most of the rotation syntax is dedicated to rotation around a local-axis-reference.
After fiddling a bit with the commands, the 'rotate object' works perfectly for a world reference, provided that the other axis are 'zeroed'.
Here is an analog clock that uses this approach in order to manage the hand rotations based on a world-relative-reference.
Since this is purely code, no models are needed.
` DBPro Example
` _analog_clock: A simple 3D analog clock - No models needed.
` Author: [email protected]
SYNC on: SYNC RATE 60
SET DISPLAY MODE 640,480,32
`camera
AUTOCAM OFF
POSITION CAMERA 0,0,-10
POINT CAMERA 0,0,0
`light
SET AMBIENT LIGHT 30
`clock face
GLOBAL face = 500
MAKE OBJECT SPHERE face, 8
POSITION OBJECT face, 0,0,0
SCALE OBJECT face, 100,100,5
COLOR OBJECT face, RGB(0,50,150)
`large ticks
mbase = 400
FOR i = 1 TO 12
MAKE OBJECT BOX mbase+i, 0.15,0.7,0.2
COLOR OBJECT mbase+i, RGB(00,00,0)
POSITION OBJECT mbase+i, 0,0,-0.1
ROTATE OBJECT mbase+i, 0,0,i*36
MOVE OBJECT UP mbase+i, 3.1
NEXT i
`small ticks
'tbase = 200
FOR i = 1 TO 60
MAKE OBJECT BOX tbase+i, 0.1,0.5,0.2
COLOR OBJECT tbase+i, RGB(250,250,0)
POSITION OBJECT tbase+i, 0,0,-0.1
ROTATE OBJECT tbase+i, 0,0,i*6
MOVE OBJECT UP tbase+i, 3
NEXT i
`secondHand
GLOBAL secondhand = 600
MAKE OBJECT BOX secondhand, 0.05,3.6,0.2
COLOR OBJECT secondhand, RGB(250,0,0)
POSITION OBJECT secondhand, 0,0,-0.3
`minuteHand
GLOBAL minutehand = 601
MAKE OBJECT BOX minutehand, 0.15,3.2,0.2
COLOR OBJECT minutehand, RGB(0,0,0)
POSITION OBJECT minutehand, 0,0,-0.25
`hourHand
GLOBAL hourHand = 602
MAKE OBJECT BOX hourHand, 0.15,2.6,0.2
COLOR OBJECT hourHand, RGB(0,0,0)
POSITION OBJECT hourHand, 0,0,-0.2
DO
_clock()
SYNC
LOOP
END
FUNCTION _clock()
systemtime$ = GET TIME$()
hour$ = FIRST TOKEN$(systemtime$,":")
minute$ = NEXT TOKEN$(":")
second$ = NEXT TOKEN$(":")
hour# = VAL(hour$)
minute# = VAL(minute$)
second# = VAL(second$)
secondAngle# = -360.0/60.0*second#
POSITION OBJECT secondhand, 0,0,-0.3
ROTATE OBJECT secondhand, 0,0,secondAngle#
MOVE OBJECT UP secondhand, 1.5
minuteAngle# = -360.0/60.0*minute#
POSITION OBJECT minutehand, 0,0,-0.25
ROTATE OBJECT minutehand, 0,0,minuteAngle#
MOVE OBJECT UP minutehand,1.3
hourAngle# = -360.0/12.0*hour#
hourAngle# = hourAngle# - 0.5*minute#
POSITION OBJECT hourHand, 0,0,-0.2
MOVE OBJECT UP hourHand, 1
ROTATE OBJECT hourhand, 0,0,hourAngle#
ENDFUNCTION