Java Reference
In-Depth Information
to determine the extent the corresponding GeometryArray objects will contribute to the
rendered shape at any specified time. The index of the array weights should thus be the same
as the index of the GeometryArray array. Also, the weights must all add up to unity.
Figure 20. Morph behavior and result
1. public class MorphBehaviour extends Behavior
2. {
3. private Morph objMorph;
4. private Alpha alpha;
5. private double[] weights = new double [4];
6. private WakeupCondition trigger = new WakeupOnElapsedFrames(0);
7.
8. MorphBehaviour(Morph objMorph, Alpha alpha)
9. {
10. this.objMorph = objMorph;
11. this.alpha = alpha;
12. }
13.
14. public void initialize() this.wakeupOn(trigger);
15.
16. public void processStimulus(Enumeration criteria)
17. {
18. weights[0] = 0;
//initialize all weights to 0
19. weights[1] = 0;
20. weights[2] = 0;
21. weights[3] = 0;
22. float alphaValue = 4f*alpha.value(); // multiply by 4f to spread the alpha duration equally
23. // between the 4 trapezium states
24. int alphaIndex = (int)alphaValue;
25.
26. //morphing between the current state and next state
27. if (alphaIndex>3) // upper limits to prevent alphaIndex from going above 3
28. weights[3] = 1.0;
29. else if (alphaIndex<=0) // lower limits to prevent alphaIndex from going below 0
30. {
31. weights[0] = (double)(alphaValue - (double)alphaIndex);
32. weights[3] = 1.0 - weights[alphaIndex];
33. }
34. else
35. {
36. weights[alphaIndex] = (double)(alphaValue - (double)alphaIndex);
37. weights[alphaIndex-1] = 1.0 - weights[alphaIndex];
38. }
39.
40. objMorph.setWeights(weights);
41. this.wakeupOn(trigger);
42. }
43. }
Search WWH ::




Custom Search