Interpolating multiple values
You can connect the timer node to any numeric attribute of any node, just by passing the $value variable in place of one of the parameters in a message. However, many attributes and messages have multiple values. theposition
message, for instance, takes 3 values for x, y, and z. The diffuse message, which sets
the color of a light, takes 3 values for red, green, and blue. The fog message in the environment s
node takes values for the color in red, green, and blue, the starting point of the fog, and the distance of total opacity.
So what if you want to control one of these attributes with a timer? You need to be able to update multiple
parameters of a message simultaneously. To accomodate this, the timer node (and all other value nodes)
can actually contain multiple values, not just one. A variables inside the node are stored as an array, numbered
value 1,2,3,4, etc. So, $value is now just the first element of the array; $value1, $value2, $value3, etc... are the
rest of the variables.
Note that $value1 is actually the second item in the array, NOT the first. The first item in the array is item zero, not item 1. This is a common convention when using arrays in many programming languages; just remember to start counting with zero.
Array value nodes can operate on all their variables at once, so the timer can change all of its variables at every time step. This example moves the cube on all three axes at once:
// animating a cube light ((1 -1 1)) object cube ((cube.pfb),(-10 10 0)) timer ((-10 10 0),(10 8 5),(5),, when(changed,cube.($value $value1 $value2)))
$value, $value1, and $value2 are connected to the x, y, and z position of the cube.
$value3, $value4, and $value5 are connected to the three rotation axes.
$value6, $value7, and $value8 are control the scale on the x,y, and z axes.
The effect is that the cube moves from left to right, rotating on the z axis, and getting longer.
// animating many attributes at once light ((1 -1 1)) object cube ((cube.pfb),(-10 10 0)) timer ((-10 10 0 0 0 0 1 1 1),(10 10 0 0 360 0 1 1 3),, when(changed,cube.($value $value1 $value2), cube.($value3 $value4 $value5), cube.($value6 $value7 $value8)) )
Note that a lot of these variables don't actually change - the cube is only rotating on one axis, for instance, so there's not really any need to have variables for the other axes.
(c) Ben Chang