Java Reference
In-Depth Information
Figure 4. First code segment for KeyBoardNavigation.java
1.
public void initialize()
2.
{
3.
events[0]=new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED); // set initial wakeup condition
4.
this.wakeupOn(new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED));
5.
allEvents=new WakeupOr(events);
6.
wakeupOn(allEvents);
7.
comMat.m00 = 1.0f; comMat.m01 = 0.0f; comMat.m02 = 0.0f;
8.
comMat.m10 = 0.0f; comMat.m11 = 1.0f; comMat.m12 = 0.0f;
9.
comMat.m20 = 0.0f; comMat.m21 = 0.0f; comMat.m22 = 1.0f;
10. }
11.
12. private Matrix3f coMatrix(int mode, float angle)
13. {
14. Matrix3f tempMat = new Matrix3f();
15. switch (mode)
16. {
17. case 1:
18. tempMat.m00 = Math.cos(angle); tempMat.m01 = 0.0f; tempMat.m02 = Math.sin(angle);
19. tempMat.m10 = 0.0f; tempMat.m11 = 1.0f; tempMat.m12 = 0.0f;
20. tempMat.m20 = -Math.sin(angle); tempMat.m21 = 0.0f; tempMat.m22 = Math.cos(angle);
21. break;
22. case 2:
23. tempMat.m00 = 1.0f; tempMat.m01 = 0.0f; tempMat.m02 = 0.0f;
24. tempMat.m10 = 0.0f; tempMat.m11 = Math.cos(angle); tempMat.m12 = Math.sin(angle);
25. tempMat.m20 = 0.0f; tempMat.m21 = -Math.sin(angle); tempMat.m22 = Math.cos(angle);
26. break;
27. case 3:
28. tempMat.m00 = Math.cos(angle); tempMat.m01 = -Math.sin(angle); tempMat.m02 = 0.0f;
29. tempMat.m10 = Math.sin(angle); tempMat.m11 = Math.cos(angle); tempMat.m12 = 0.0f;
30. tempMat.m20 = 0.0f; tempMat.m21 = 0.0f; tempMat.m22 = 1.0f;
31. break;
32.
default:
33.
}
34.
return tempMat;
35. }
The keys to be used for this user-defined keyboard based navigation example are defined
in lines 58 and 59 in Figure 6. Lines 85 to 88 use the setRotation3D function described to
give rise a rotational movement of the ViewPlatform, while lines 89 to 94 use the seTrans-
lation3D function to give a translation movement.
The initialize method from lines 74 to 80 sets the keyboard event conditions that will
wakeup this navigational behavior. Specifically, WakeupOnAWTEvent will enable the
behavior to receive any keyboard event stimulus. Lastly, the processStimulus function will
Search WWH ::




Custom Search