-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHatch_GLEventListener.java
More file actions
155 lines (134 loc) · 4.1 KB
/
Copy pathHatch_GLEventListener.java
File metadata and controls
155 lines (134 loc) · 4.1 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
import gmaths.*;
import java.nio.*;
import com.jogamp.common.nio.*;
import com.jogamp.opengl.*;
import com.jogamp.opengl.util.*;
import com.jogamp.opengl.util.awt.*;
import com.jogamp.opengl.util.glsl.*;
public class Hatch_GLEventListener implements GLEventListener {
private static final boolean DISPLAY_SHADERS = false;
private Camera camera;
private float xPosition = 0;
/* The constructor is not used to initialise anything */
public Hatch_GLEventListener(Camera camera) {
this.camera = camera;
this.camera.setPosition(new Vec3(-0.1f,23.3f,25.7f));
}
// ***************************************************
/*
* METHODS DEFINED BY GLEventListener
*/
/* Initialisation */
public void init(GLAutoDrawable drawable) {
GL3 gl = drawable.getGL().getGL3();
System.err.println("Chosen GLCapabilities: " + drawable.getChosenGLCapabilities());
gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
gl.glClearDepth(1.0f);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(GL.GL_LESS);
gl.glFrontFace(GL.GL_CCW); // default is 'CCW'
gl.glEnable(GL.GL_CULL_FACE); // default is 'not enabled' so needs to be enabled
gl.glCullFace(GL.GL_BACK); // default is 'back', assuming CCW
initialise(gl);
}
/* Called to indicate the drawing surface has been moved and/or resized */
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
GL3 gl = drawable.getGL().getGL3();
gl.glViewport(x, y, width, height);
float aspect = (float)width/(float)height;
camera.setPerspectiveMatrix(Mat4Transform.perspective(45, aspect));
}
/* Draw */
public void display(GLAutoDrawable drawable) {
GL3 gl = drawable.getGL().getGL3();
render(gl);
}
/* Clean up memory */
public void dispose(GLAutoDrawable drawable) {
GL3 gl = drawable.getGL().getGL3();
room.dispose(gl);
table.dispose(gl);
light.dispose(gl);
lamp1.dispose(gl);
lamp2.dispose(gl);
}
// ***************************************************
/* THE SCENE
* Now define all the methods to handle the scene.
* This will be added to in later examples.
*/
private Room room;
private Table table;
private Light light, light2;
private Lamp lamp1;
private Lamp2 lamp2;
private void initialise(GL3 gl) {
createRandomNumbers();
light = new Light(gl);
light.setCamera(camera);
light2 = new Light(gl);
light2.setCamera(camera);
room = new Room(gl, camera, light);
table = new Table(gl, camera, light);
lamp1 = new Lamp(gl, camera, light);
lamp2 = new Lamp2(gl, camera, light);
}
private void render(GL3 gl) {
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
light.setPosition(getLightPosition());
light.render(gl);
light2.setPosition(getLight2Position());
light2.render(gl);
room.render(gl);
table.render(gl);
lamp1.render(gl);
lamp2.render(gl);
}
// ***************************************************
/* An array of random numbers
*/
private int NUM_RANDOMS = 1000;
private float[] randoms;
private void createRandomNumbers() {
randoms = new float[NUM_RANDOMS];
for (int i=0; i<NUM_RANDOMS; ++i) {
randoms[i] = (float)Math.random();
}
}
private Vec3 getLightPosition() {
float x = -0.1f;
float y = 24.0f;
float z = 1.0f;
return new Vec3(x,y,z);
}
private Vec3 getLight2Position() {
float x = 0.5f;
float y = 24.0f;
float z = 1.0f;
return new Vec3(x,y,z);
}
// ***************************************************
/* INTERACTIONS
*/
public void originalPose1(){
lamp1.originalPose();
}
public void firstPose1() {
lamp1.firstPose();
}
public void secondPose1(){
lamp1.secondPose();
}
public void originalPose2(){
lamp2.originalPose();
}
public void firstPose2() {
lamp2.firstPose();
}
public void secondPose2(){
lamp2.secondPose();
}
public void lightSwitch(){
light.lightSwitch();
}
}