import javax.media.j3d.*; import java.util.Enumeration; public class MorphBehavior extends Behavior { Morph targetMorph; Alpha alpha; int numWeights; double[] weights; WakeupCondition trigger = new WakeupOnElapsedFrames(0); MorphBehavior(Morph target, Alpha morphAlpha, int numWts) { targetMorph = target; alpha = morphAlpha; numWeights = numWts; weights = new double[numWeights]; } public void initialize() { wakeupOn(trigger); } /** * Defines the morphing parameters. See textbook for * details. */ public void processStimulus(Enumeration criteria) { for (int i = 0; i < numWeights; i ++) { weights[i] = 0.0; } float alphaValue = numWeights * alpha.value(); int alphaIndex = (int) alphaValue; weights[alphaIndex] = 1.0 - (alphaValue - alphaIndex); if(alphaIndex < numWeights - 1) { weights[alphaIndex + 1] = 1.0 - weights[alphaIndex]; } else { weights[0] = 1.0 - weights[alphaIndex]; } targetMorph.setWeights(weights); wakeupOn(trigger); } }