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. the position 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 (position(1 -1 1))
object cube (file(cube.pfb),position(-10 10 0))

timer (startValues(-10 10 0),endValues(10 8 5),duration(5),start,
	when(changed,cube.position($value $value1 $value2)))
	

You can even connect one timer to more than one message at once. This example has a timer with 9 variables.
$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 (position(1 -1 1))
object cube (file(cube.pfb),position(-10 10 0))
timer (startValues(-10 10 0 0 0 0 1 1 1),endValues(10 10 0 0 360 0 1 1 3),start,
	when(changed,cube.position($value $value1 $value2),
		cube.orientation($value3 $value4 $value5),
		cube.size($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