-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnilamp.java
156 lines (142 loc) · 5.27 KB
/
Anilamp.java
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
/* I declare that this code is my own work */
/* Author <Junxiang Chen> <[email protected]> */
/*
the main class that will be run
*/
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.awt.GLCanvas;
import com.jogamp.opengl.util.FPSAnimator;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class Anilamp extends JFrame implements ActionListener {
private static final int WIDTH = 1280;
private static final int HEIGHT = 720;
private static final Dimension dimension = new Dimension(WIDTH, HEIGHT);
private static GLCanvas glCanvas;
private static Anilamp_GLEventListener glEventListener;
private final FPSAnimator fpsAnimator;
private Camera camera;
public JButton light1Control, light2Control, lightBulbControl, randomPoseButton, resetButton, jumpButton;
/**
* constructor
*
* @param textForTitleBar the text displays in the title bar
*/
public Anilamp(String textForTitleBar) {
super(textForTitleBar);
GLCapabilities glCapabilities = new GLCapabilities(GLProfile.get(GLProfile.GL3));
glCanvas = new GLCanvas(glCapabilities);
camera = new Camera(Camera.DEFAULT_POSITION, Camera.DEFAULT_TARGET, Camera.DEFAULT_UP);
glEventListener = new Anilamp_GLEventListener(camera);
glCanvas.addGLEventListener(glEventListener);
glCanvas.addKeyListener(new MyKeyboardInput(camera));
glCanvas.addMouseMotionListener(new MyMouseInput(camera));
getContentPane().add(glCanvas, BorderLayout.CENTER);
/*
jMenuBar
*/
JMenuBar jMenuBar = new JMenuBar();
this.setJMenuBar(jMenuBar);
JMenu fileMenu = new JMenu("File");
JMenuItem quitItem = new JMenuItem("Quit");
quitItem.addActionListener(this);
fileMenu.add(quitItem);
jMenuBar.add(fileMenu);
/*
jPanel and jButton
*/
JPanel jPanel = new JPanel();
light1Control = new JButton("Light 1 On/Off");
light1Control.addActionListener(this);
light2Control = new JButton("Light 2 On/Off");
light2Control.addActionListener(this);
lightBulbControl = new JButton("Lamp On/Off");
lightBulbControl.addActionListener(this);
randomPoseButton = new JButton("Random Pose");
randomPoseButton.addActionListener(this);
resetButton = new JButton("Reset");
resetButton.addActionListener(this);
jumpButton = new JButton("Jump");
jumpButton.addActionListener(this);
jPanel.add(light1Control);
jPanel.add(light2Control);
jPanel.add(lightBulbControl);
jPanel.add(randomPoseButton);
jPanel.add(resetButton);
jPanel.add(jumpButton);
this.add(jPanel, BorderLayout.SOUTH);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
fpsAnimator.stop();
remove(glCanvas);
dispose();
System.exit(0);
}
});
fpsAnimator = new FPSAnimator(glCanvas, 60);
fpsAnimator.start();
}
/**
* MAIN
*
* @param args default argument in the main function
*/
public static void main(String[] args) {
Anilamp aniLamp = new Anilamp("ANILAMP -- Final Scene");
aniLamp.getContentPane().setPreferredSize(dimension);
aniLamp.pack();
aniLamp.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
/*
buttons control lights
*/
if (e.getActionCommand().equalsIgnoreCase("Lamp On/Off")) {
glEventListener.LAMP_ON = !glEventListener.LAMP_ON;
}
if (e.getActionCommand().equalsIgnoreCase("Light 1 On/Off")) {
glEventListener.LIGHT1_ON = !glEventListener.LIGHT1_ON;
}
if (e.getActionCommand().equalsIgnoreCase("Light 2 On/Off")) {
glEventListener.LIGHT2_ON = !glEventListener.LIGHT2_ON;
}
/*
handle the disable of "Random Pose" and "Jump" button for 2.5 seconds
*/
int delay = 2500;
Timer timer = new Timer(delay, new ActionListener() {
public void actionPerformed(ActionEvent e) {
randomPoseButton.setEnabled(true);
jumpButton.setEnabled(true);
}
});
timer.setRepeats(false);
/*
buttons control lamp poses and jump motion
*/
if (e.getActionCommand().equalsIgnoreCase("Random Pose")) {
glEventListener.setRandomPoseBegin();
randomPoseButton.setEnabled(false);
jumpButton.setEnabled(false);
timer.start();
}
if (e.getActionCommand().equalsIgnoreCase("Reset")) {
glEventListener.resetPose();
}
if (e.getActionCommand().equalsIgnoreCase("Jump")) {
glEventListener.resetPose();
glEventListener.setAnimationBegin();
jumpButton.setEnabled(false);
randomPoseButton.setEnabled(false);
timer.start();
}
}
}