-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHatch.java
More file actions
159 lines (144 loc) · 4.93 KB
/
Copy pathHatch.java
File metadata and controls
159 lines (144 loc) · 4.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import gmaths.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.jogamp.opengl.*;
import com.jogamp.opengl.awt.GLCanvas;
import com.jogamp.opengl.util.FPSAnimator;
public class Hatch extends JFrame implements ActionListener {
private static final int WIDTH = 1024;
private static final int HEIGHT = 768;
private static final Dimension dimension = new Dimension(WIDTH, HEIGHT);
private GLCanvas canvas;
private Hatch_GLEventListener glEventListener;
private final FPSAnimator animator;
private Camera camera;
public static void main(String[] args) {
Hatch b1 = new Hatch("Hatch");
b1.getContentPane().setPreferredSize(dimension);
b1.pack();
b1.setVisible(true);
}
public Hatch(String textForTitleBar) {
super(textForTitleBar);
GLCapabilities glcapabilities = new GLCapabilities(GLProfile.get(GLProfile.GL3));
canvas = new GLCanvas(glcapabilities);
camera = new Camera(Camera.DEFAULT_POSITION, Camera.DEFAULT_TARGET, Camera.DEFAULT_UP);
glEventListener = new Hatch_GLEventListener(camera);
canvas.addGLEventListener(glEventListener);
canvas.addMouseMotionListener(new MyMouseInput(camera));
canvas.addKeyListener(new MyKeyboardInput(camera));
getContentPane().add(canvas, BorderLayout.CENTER);
JMenuBar menuBar=new JMenuBar();
this.setJMenuBar(menuBar);
JMenu fileMenu = new JMenu("File");
JMenuItem quitItem = new JMenuItem("Quit");
quitItem.addActionListener(this);
fileMenu.add(quitItem);
menuBar.add(fileMenu);
JPanel p = new JPanel();
JButton b = new JButton("lamp1 pose1");
b.addActionListener(this);
p.add(b);
b = new JButton("lamp1 pose2");
b.addActionListener(this);
p.add(b);
b = new JButton("lamp1 pose3");
b.addActionListener(this);
p.add(b);
b = new JButton("lamp2 pose1");
b.addActionListener(this);
p.add(b);
b = new JButton("lamp2 pose2");
b.addActionListener(this);
p.add(b);
b = new JButton("lamp2 pose3");
b.addActionListener(this);
p.add(b);
b = new JButton("lights on");
b.addActionListener(this);
p.add(b);
this.add(p, BorderLayout.SOUTH);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
animator.stop();
remove(canvas);
dispose();
System.exit(0);
}
});
animator = new FPSAnimator(canvas, 60);
animator.start();
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equalsIgnoreCase("lamp1 pose1")) {
glEventListener.originalPose1();
}
else if (e.getActionCommand().equalsIgnoreCase("lamp1 pose2")) {
glEventListener.firstPose1();
}
else if(e.getActionCommand().equalsIgnoreCase("lamp1 pose3")) {
glEventListener.secondPose1();
}
else if(e.getActionCommand().equalsIgnoreCase("lamp2 pose1")) {
glEventListener.originalPose2();
}
else if(e.getActionCommand().equalsIgnoreCase("lamp2 pose2")) {
glEventListener.firstPose2();
}
else if(e.getActionCommand().equalsIgnoreCase("lamp2 pose3")) {
glEventListener.secondPose2();
}
else if(e.getActionCommand().equalsIgnoreCase("lights on")) {
glEventListener.lightSwitch();
}
}
}
class MyKeyboardInput extends KeyAdapter {
private Camera camera;
public MyKeyboardInput(Camera camera) {
this.camera = camera;
}
public void keyPressed(KeyEvent e) {
Camera.Movement m = Camera.Movement.NO_MOVEMENT;
switch (e.getKeyCode()) {
case KeyEvent.VK_LEFT: m = Camera.Movement.LEFT; break;
case KeyEvent.VK_RIGHT: m = Camera.Movement.RIGHT; break;
case KeyEvent.VK_UP: m = Camera.Movement.UP; break;
case KeyEvent.VK_DOWN: m = Camera.Movement.DOWN; break;
case KeyEvent.VK_A: m = Camera.Movement.FORWARD; break;
case KeyEvent.VK_Z: m = Camera.Movement.BACK; break;
}
camera.keyboardInput(m);
}
}
class MyMouseInput extends MouseMotionAdapter {
private Point lastpoint;
private Camera camera;
public MyMouseInput(Camera camera) {
this.camera = camera;
}
/**
* mouse is used to control camera position
*
* @param e instance of MouseEvent
*/
public void mouseDragged(MouseEvent e) {
Point ms = e.getPoint();
float sensitivity = 0.001f;
float dx=(float) (ms.x-lastpoint.x)*sensitivity;
float dy=(float) (ms.y-lastpoint.y)*sensitivity;
//System.out.println("dy,dy: "+dx+","+dy);
if (e.getModifiers()==MouseEvent.BUTTON1_MASK)
camera.updateYawPitch(dx, -dy);
lastpoint = ms;
}
/**
* mouse is used to control camera position
*
* @param e instance of MouseEvent
*/
public void mouseMoved(MouseEvent e) {
lastpoint = e.getPoint();
}
}