Rotating ElevationGrid
Someone asked about an ElevationGrid rotating about its center in the X3DOM User Mailling List, so I created this one using VRMath2 Editor to demonstrate that it is quite easy to create one. The idea in this demo is to have the center of ElevationGrid at 0,0,0 then move the ElevationGrid into an empty Transform node. The OrientationInterpolator is then applied on to the outer Transform node.
Below is the 3D virtual world with an ElevationGrid rotating about its center. You can click on the square at the top-left corner to open up the 3D interface UI.
The above x3d is created in VRMath2 Editor with the Logo program below. If you visit VRMath2 Editor, you can open up this program as a guest in the Logo Editor (can be found in the Window menu).
; Rotating ElevationGrid about its center ; By Andy Yeh CS RESET TRANSFORM ; create an empty transform node MAKE "elegrid OBJECT ; create a variable :elegrid with value the current object id. FD 4.5 WEST 4.5 ; move the turtle so the elevationgrid will have 0,0,0 as center ELEGRID ; create a random 10x10 ElevationGrid to the right and back of the turtle MOVE OBJECT :elegrid ; whenever there is an object created, the keyword object will store its id. ; :elegrid will be used later for animation MAKE "key [] ; make a variable :key 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 QUEUE "orilist ORI ; queue first value of current orientation REPEAT 4 [ ; use repeat to collect the next 4 values. QUEUE "key REPCOUNT / 4 ; queue is a command to add a value to the end of the list 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 "ts 10 "true ; to animate orientation, we need an orientation interpolator ; oriint name key value ORIENTATIONINTERPOLATOR "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 "ts "fraction_changed "oi "set_fraction ; the above, we use the timesensor to drive orientationinterpolator ; the fraction_changed and set_fraction are fixed, simply type in exactly as they are. ROUTE "route2 "oi "value_changed :elegrid "rotation ; value_changed is also a fixed term, which has to be exactly as it is.
If you are only interested in the x3d file, you can download here: rotating_elevationgrid.x3d.
Please leave a comment and let me know what you think.
- Andy's blog
- Login or register to post comments
- 4790 reads