VRML Script Tutorial Full list VRML Interactive Tutorial
Introduction
Hierarchical Node Structures
Defining and Instancing Nodes Defining Levels of Detail Events in VRML
|
|
|
A complete example is now presented. A Shape is drawn at the origin. The OrientationInterpolator will rotate the shape to the right by 180 degrees and down again by 180 degrees. The cycle is repeated forever.
First one needs the to define a Transform with a Shape, a TimeSensor, and an OrientationInterpolator.
DEF tr Transform {
Now the only thing which is missing is routing the events.
We need to get the eventOut fraction_changed generated by the TimeSensor. This event outputs a value between 0 and 1. We can use this value to set a key for the OrientationInterpolator by routing the fraction_changed eventOut from the TimeSensor to the set_fraction eventIn from the OrientationInterpolator.
A new fraction being set in an interpolator causes the keyValue to be changed. As a consequence the interpolator will generate the fraction_changed eventOut. Because the interpolator used is a OrientationInterpolator, this event outputs a rotation value.
Finally we use this eventOut to set a rotation in the Transform node. Because the rotation is an exposed field of the Transform node we can use the eventIn set_rotation to change it. To do this we route the fraction_changed eventOut of the OrientationInterpolator to the set_rotation eventIn of the Transform node.
The ROUTE statements to do this are: