88
|
1 package alice.test.topology.movement;
|
|
2
|
|
3 import java.awt.event.KeyEvent;
|
|
4 import java.awt.event.KeyListener;
|
|
5
|
|
6 import javax.media.j3d.Transform3D;
|
|
7 import javax.media.j3d.TransformGroup;
|
|
8 import javax.vecmath.Vector3f;
|
|
9
|
|
10
|
|
11 public class KeyInput implements KeyListener{
|
|
12
|
|
13 int KeyCode = 0;
|
|
14 Vector3f vector;
|
|
15 Transform3D transform;
|
|
16 TransformGroup transformGroup;
|
|
17
|
|
18 public KeyInput(){
|
|
19 transform = new Transform3D();
|
|
20 transformGroup= new TransformGroup();
|
|
21 transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
|
|
22 vector = new Vector3f(0.0f,0.0f,0.0f);
|
93
|
23
|
88
|
24 }
|
|
25 @Override
|
|
26 public void keyPressed(KeyEvent event) {
|
|
27 // TODO Auto-generated method stub
|
|
28 KeyCode = event.getKeyCode();
|
|
29 switch(KeyCode)
|
|
30 {
|
|
31 case 37:
|
|
32 vector.x -= 0.1f;
|
|
33 break;
|
|
34 case 38:
|
|
35 vector.y += 0.1f;
|
|
36 break;
|
|
37 case 39:
|
|
38 vector.x += 0.1f;
|
|
39 break;
|
|
40 case 40:
|
|
41 vector.y -= 0.1f;
|
|
42 break;
|
|
43 }
|
|
44 transform.setTranslation(vector);
|
|
45 transformGroup.setTransform(transform);
|
|
46 }
|
|
47
|
|
48 @Override
|
|
49 public void keyReleased(KeyEvent arg0) {
|
|
50 // TODO Auto-generated method stub
|
|
51
|
|
52 }
|
|
53
|
|
54 @Override
|
|
55 public void keyTyped(KeyEvent arg0) {
|
|
56 // TODO Auto-generated method stub
|
|
57
|
|
58 }
|
|
59
|
|
60 } |