The OrientationInterpolator node is an interpolator
which takes a list of rotation values, i.e. a 3D coordinate plus an angle,
in the field keyValue. See the Transform
node for a brief explanation on rotations.
For a list of the events of this node see interpolator.
Syntax:
OrientationInterpolator {
key [ ]
keyValue[ ]
}
This interpolator is used to animate objects, rotating them according
to the values in the keyValue field.
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.
#VRML V2.0 utf8
DEF tr Transform {
children [
Shape {
appearance Appearance {
material DEF mat Material { diffuseColor 1 0 0 }
}
geometry Sphere {}
}
DEF oi OrientationInterpolator {
key [ 0 1 ]
keyValue [ 0 1 0 0,
0 1 0 3.14, # rotate right
0 0 1 3.14] # rotate down
}
DEF ts TimeSensor {
cycleInterval 2
loop TRUE
}
]
}
Note that whereas in the first two keyValues the interpolation is done
in the angle, in the last two the interpolation is done in the vector which
defines the interpolation.
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:
ROUTE ts.fraction_changed TO oi.set_fraction
ROUTE oi.value_changed TO tr.set_rotation
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.