1:import java.util.*;
2:import javax.media.j3d.*;
3:
4:public class MorphBehavior extends Behavior{
5:
6: private Morph targetMorph;
7: private Alpha alpha;
8: private double[] weights = {0,0};
9: private WakeupCondition trigger = new WakeupOnElapsedFrames(0);
10:
11: //create MorphBeavior
12: MorphBehavior(Morph targetMorph, Alpha alpha){
13: this.targetMorph = targetMorph;
14: this.alpha = alpha;
15: }
16:
17: public void initialize(){
18: //set initial wakeup condition
19: this.wakeupOn(trigger);
20: }
21:
22: public void processStimulus(Enumeration criteria){
23:
24: weights[0] = 0; weights[1] = 0;
25:
26: float alphaValue = 2f*alpha.value(); //get alpha
27: int alphaIndex = (int) alphaValue; //which Geom object
28: weights[alphaIndex] = (double) alphaValue - (double) alphaIndex;
29: if(alphaIndex < 1){
30: weights[alphaIndex + 1] = 1.0 - weights[alphaIndex];
31: }else{
32: weights[0] = 1.0 - weights[alphaIndex];
33: }
34: targetMorph.setWeights(weights);
35:
36: this.wakeupOn(trigger); //set next wakeup condition
37: }
38:
39:}
previous
start
toc
next