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 PositionInterpolator will move the shape up and down along the y axis. The cycle is repeated forever.
First one needs the to define a Transform with a Shape, a TimeSensor, and a PositionInterpolator.
DEF tr Transform {
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 PositionInterpolator by routing the fraction_changed eventOut from the TimeSensor to the set_fraction eventIn from the PositionInterpolator.
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 PositionInterpolator, this event outputs a 3D coordinate value.
Finally we use this eventOut to set a translation in the Transform node. Because the translation is an exposed field of the Transform node we can use the eventIn set_translation to change it. To do this we route the fraction_changed eventOut of the PositionInterpolator to the set_translation eventIn of the Transform node.
The ROUTE statements to do this are: