Basic animation in VRMath2
Animation in VRMath2 is still in the development stage. I have created some Logo commands to achieve some basic animation. Animation in Logo can be very powerful because it is very easy to move the turtle around in 3D space and collect its position and orientation for animation.
Here is a basic introduction of animation in VRMath2. The whole animation framework will be revised and more GUI will be developed to enable easy creation of animations.
; Basic animation ; RESET ; reset scale, materials etc. CS ; clearscreen + home BOX ; create a box MAKE "box OBJECT ; create a variable :box with value the current object id. ; whenever there is an object created, the keyword object will store its id. ; :box will be used later for animation MAKE "key [] ; make a variable :key as an empty list MAKE "poslist [] ; make a variable :poslist as an empty list MAKE "orilist [] ; make a variable :orilist as an empty list ; collect key values. Keys should be between 0 to 1 ; I want to make 5 values as [0 0.25 0.5 0.75 1] in the key list ; I can certainly type in make "key [0 0.25 0.5 0.75 1] but I like using ; repeat to collect value because sometimes I need more values between 0 and 1 ; the keys can be different intervals. QUEUE "key 0 ; queue first value in key list REPEAT 4 [ QUEUE "key REPCOUNT / 4 ; queue is a command to add a value to the end of the list ] ; to collect position values, simply move the turtle around ; the command pos will return the turtle's position/location QUEUE "poslist POS ; queue current position as the first value in :poslist list WEST 2 QUEUE "poslist POS ; second value EAST 2 QUEUE "poslist POS ; third value EAST 1 QUEUE "poslist POS ; fourth value, I only go east 1 because this will create different speed effect. WEST 1 QUEUE "poslist POS ; fifth value, back to beginning position ; to collect orientation values, simply rotate the turtle ; the command ori will return turtle's orientation. QUEUE "orilist ORI ; queue first value of current orientation REPEAT 4 [ ; use repeat to collect the next 4 values. RT 90 QUEUE "orilist ORI ] ; ; for animation, a timesensor is needed. The syntax of timesensor is ; timesensor name loop_interval_in_second loop_true_or_false TIMESENSOR "time 4 "true ; to animate position, we need a position interpolator ; posint name key value POSINT "pi :key :poslist ; to animate orientation, we need an orientation interpolator ; oriint name key value ORIINT "oi :key :orilist ; now we have everything ; we use command route to hook up everything ; route name from_node from_field to_node to_field ROUTE "route1 "time "fraction_changed "pi "set_fraction ROUTE "route2 "time "fraction_changed "oi "set_fraction ; the above, we use the same timesensor to drive both interpolators ; the fraction_changed and set_fraction are fixed, simply type in exactly as they are. ROUTE "route3 "pi "value_changed :box "translation ; since pi is now in action, we route its value to :box's translation ROUTE "route4 "oi "value_changed :box "rotation ; similarly we route the orientation value to :box's rotation ; value_changed is also a fixed term, which has to be exactly as it is.
- Andy's blog
- Login or register to post comments
- 4183 reads