-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoom.java
More file actions
111 lines (91 loc) · 4.03 KB
/
Room.java
File metadata and controls
111 lines (91 loc) · 4.03 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
import gmaths.*;
import com.jogamp.opengl.*;
public final class Room {
private Model floor, wall, window, glass;
private Camera camera;
private Light light;
public Room(GL3 gl, Camera camera, Light light){
//this.plane = new Plane(gl, camera, light);
this.camera = camera;
this.light = light;
int[] textureId0 = TextureLibrary.loadTexture(gl, "./textures/wall.jpg");
int[] textureId1 = TextureLibrary.loadTexture(gl, "./textures/floor.jpg");
floor = initFloor(gl, textureId1);
wall = initWall(gl, textureId0);
window = initWindowWall(gl, textureId0);
//glass = initWindowGlass(gl);
floor.setModelMatrix(getMfloor());
//floor.render(gl);
wall.setModelMatrix(getMnorthWall());
//wall.render(gl);
window.setModelMatrix(getMwindowWall());
//window.render(gl);
//glass.setModelMatrix(getMwindowWall());
}
private Model initFloor(GL3 gl, int[] t){
Mesh m = new Mesh(gl, Plane.vertices.clone(), Plane.indices.clone());
Shader shader = new Shader(gl, "./shaders/vs_plane.txt", "./shaders/fs_plane.txt");
Material material = new Material(new Vec3(0.3f, 0.3f, 0.3f), new Vec3(0.3f, 0.3f, 0.3f), new Vec3(0.3f, 0.3f, 0.3f), 1.0f);
Model plane = new Model(gl, camera, light, shader, material, new Mat4(1), m, t);
return plane;
}
private Model initWall(GL3 gl, int[] t){
Mesh m = new Mesh(gl, Plane.vertices.clone(), Plane.indices.clone());
Shader shader = new Shader(gl, "./shaders/vs_plane.txt", "./shaders/fs_plane.txt");
Material material = new Material(new Vec3(0.2f, 0.2f, 0.2f), new Vec3(0.8f, 0.8f, 0.8f), new Vec3(0.3f, 0.3f, 0.3f), 1.0f);
Model plane = new Model(gl, camera, light, shader, material, new Mat4(1), m, t);
return plane;
}
private Model initWindowWall(GL3 gl, int[] t){
Mesh m = new Mesh(gl, Window.vertices.clone(), Window.indicesWall.clone());
Shader shader = new Shader(gl, "./shaders/vs_plane.txt", "./shaders/fs_plane.txt");
Material material = new Material(new Vec3(0.2f, 0.2f, 0.2f), new Vec3(0.8f, 0.8f, 0.8f), new Vec3(0.3f, 0.3f, 0.3f), 1.0f);
Model window = new Model(gl, camera, light, shader, material, new Mat4(1), m, t);
return window;
}
private Model initWindowGlass(GL3 gl){
Mesh m = new Mesh(gl, Window.verticesGlass.clone(), Window.indicesWindow.clone());
Shader shader = new Shader(gl, "./shaders/vs_plane.txt", "./shaders/fs_plane.txt");
Material material = new Material(new Vec3(1.0f, 1.0f, 1.0f), new Vec3(1.0f, 1.0f, 1.0f), new Vec3(1.0f, 1.0f, 1.0f), 1.0f);
//gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
//gl.glEnable( GL.GL_BLEND ); // default is 'back', assuming CCW
Model window = new Model(gl, camera, light, shader, material, new Mat4(1), m);
return window;
}
private Mat4 getMfloor(){
float size = 4f;
Mat4 modelMatrix = new Mat4(1);
modelMatrix = Mat4.multiply(Mat4Transform.scale(size,1f,size), modelMatrix);
return modelMatrix;
}
private Mat4 getMnorthWall(){
float size = 4f;
Mat4 modelMatrix = new Mat4(1);
modelMatrix = Mat4.multiply(Mat4Transform.scale(size,1f,size), modelMatrix);
modelMatrix = Mat4.multiply(Mat4Transform.rotateAroundX(90), modelMatrix);
modelMatrix = Mat4.multiply(Mat4Transform.translate(0,size*0.5f,-size*0.5f), modelMatrix);
return modelMatrix;
}
private Mat4 getMwindowWall(){
float size = 4f;
Mat4 modelMatrix = new Mat4(1);
modelMatrix = Mat4.multiply(Mat4Transform.scale(size,1f,size), modelMatrix);
modelMatrix = Mat4.multiply(Mat4Transform.rotateAroundY(-90), modelMatrix);
modelMatrix = Mat4.multiply(Mat4Transform.rotateAroundZ(90), modelMatrix);
modelMatrix = Mat4.multiply(Mat4Transform.translate(-size*0.5f,size*0.5f,0), modelMatrix);
return modelMatrix;
}
//private Mat4 getMwindowGlass(){}
public void render(GL3 gl){
floor.render(gl);
window.render(gl);
wall.render(gl);
//glass.render(gl);
}
public void dispose(GL3 gl){
floor.dispose(gl);
wall.dispose(gl);
window.dispose(gl);
//glass.dispose(gl);
}
}