PositionInterpolator

The PositionInterpolator node is an interpolator which takes a list of 3D coordinate values in the field keyValue

For a list of the events of this node see interpolator

Syntax: 
PositionInterpolator { 
key [ ] 
keyValue[ ] 

This interpolator is used to animate objects, moving them along the path specified in keyValue  

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. 

#VRML V2.0 utf8 

DEF tr Transform { 
 
children [
 
Shape {
 
appearance Appearance {
 
material DEF mat Material { diffuseColor 1 0 0 }
geometry Sphere {}
DEF pi PositionInterpolator {
 
key [ 0 1 ] 
keyValue [ 0 0 0, 0 1 0, 0 0 0]
DEF ts TimeSensor {
 
cycleInterval 2 
loop TRUE
}
]


 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 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: 
ROUTE ts.fraction_changed TO pi.set_fraction 
ROUTE pi.value_changed TO tr.set_translation 
Note that the nodes being routed are given a name using the DEF statement. This is because a name is required in a ROUTE statement.