< Zurück | Inhalt | Weiter >

SwitchValueInterpolator


The SwitchValueInterpolator is used to cycle through the children of a Switch Node based on the output from an Alpha object. The SwitchValueInterpolator maps the output from the Alpha into a current visible child Node using the following algorithm:


float f = alpha.value(); int i = firstSwitchIndex +

(int)(f * (float)(childCount − 1) + 0.5F); target.setWhichChild(i);


Note that the Switch Node passed to the SwitchInterpolator must have the

Switch.ALLOW_SWITCH_WRITE capability.


//create the Switch Node

Switch switchNode = new Switch();


//set the WRITE capability

switchNode.setCapability( Switch.ALLOW_SWITCH_WRITE );


//add children to switchNode here…

//create the Alpha for the Interpolator Alpha alpha = new Alpha( −1,

Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 500,

100,

5000,

2000,

1000,

5000,

2000,

500 );


//create the SwitchInterpolator and pass the Alpha

//and a Switch Node

Interpolator switchInterpolator =

new SwitchValueInterpolator( alpha, switchNode );


//add the Interpolator to a parent BranchGroup

//and set Scheduling Bounds BranchGroup bg = new BranchGroup(); bg.addChild( interpolator );

interpolator.setSchedulingBounds( getApplicationBounds() );