-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTable.java
158 lines (139 loc) · 6.91 KB
/
Table.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
157
158
/* I declare that this code is my own work */
/* Author <Junxiang Chen> <jchen115@sheffield.ac.uk> */
/*
sub class of SceneGraphObject
*/
import com.jogamp.opengl.GL3;
import gmaths.Mat4;
import gmaths.Mat4Transform;
import gmaths.Vec3;
public class Table extends SceneGraphObject {
private Model table_body, table_leg;
private NameNode tableRoot, tableBodyName, tableLegLeftTop, tableLegLeftBtm, tableLegRightTop, tableLegRightBtm;
private TransformNode tableTranslate, tableBodyScale, tableLegTransform,
ltTranslate, lbTranslate, rtTranslate, rbTranslate;
private ModelNode tableBodyNode, tableLeg_LT_Node, tableLeg_LB_Node, tableLeg_RT_Node, tableLeg_RB_Node;
private float TABLE_X_POSITION;
private float TABLE_Y_POSITION;
private float TABLE_Z_POSITION;
private float TABLE_BODY_LENGTH;
private float TABLE_BODY_WIDTH;
private float TABLE_BODY_HEIGHT;
private float TABLE_LEG_LENGTH;
private float TABLE_LEG_WIDTH;
private float TABLE_LEG_HEIGHT;
private int[] textureId_Body01;
private int[] textureId_Leg01;
public Table(GL3 gl3, Camera camera, Light light1, Light light2, MovingLight movingLight,
float TABLE_X_POSITION, float TABLE_Y_POSITION, float TABLE_Z_POSITION,
float TABLE_BODY_LENGTH, float TABLE_BODY_WIDTH, float TABLE_BODY_HEIGHT,
float TABLE_LEG_LENGTH, float TABLE_LEG_WIDTH, float TABLE_LEG_HEIGHT,
int[] textureId_Body01, int[] textureId_Leg01
) {
super(gl3, camera, light1, light2, movingLight);
this.TABLE_X_POSITION = TABLE_X_POSITION;
this.TABLE_Y_POSITION = TABLE_Y_POSITION;
this.TABLE_Z_POSITION = TABLE_Z_POSITION;
this.TABLE_BODY_LENGTH = TABLE_BODY_LENGTH;
this.TABLE_BODY_WIDTH = TABLE_BODY_WIDTH;
this.TABLE_BODY_HEIGHT = TABLE_BODY_HEIGHT;
this.TABLE_LEG_LENGTH = TABLE_LEG_LENGTH;
this.TABLE_LEG_WIDTH = TABLE_LEG_WIDTH;
this.TABLE_LEG_HEIGHT = TABLE_LEG_HEIGHT;
this.textureId_Body01 = textureId_Body01;
this.textureId_Leg01 = textureId_Leg01;
}
@Override
void initialise() {
tableRoot = new NameNode("table root");
tableTranslate = new TransformNode(
"table transform", Mat4Transform.translate(TABLE_X_POSITION, TABLE_Y_POSITION, TABLE_Z_POSITION)
);
Mesh tableBodyMesh = new Mesh(gl3, Cube.vertices.clone(), Cube.indices.clone());
Shader tableBodyShader = new Shader(
gl3, "shader/vs_table_body.txt", "shader/fs_table_body.txt"
);
Material tableBodyMaterial = new Material(
new Vec3(0.36f, 0.36f, 0.36f),
new Vec3(1.0f, 1.0f, 1.0f),
new Vec3(0.2f, 0.15f, 0.15f), 32.0f
);
table_body = new Model(
gl3, camera, light1, light2, movingLight,
tableBodyShader, tableBodyMaterial, new Mat4(1), tableBodyMesh, textureId_Body01
);
Mat4 tableBodyModelMatrix = Mat4Transform.scale(TABLE_BODY_LENGTH, TABLE_BODY_HEIGHT, TABLE_BODY_WIDTH);
tableBodyScale = new TransformNode("table body scale", tableBodyModelMatrix);
tableBodyName = new NameNode("body");
tableBodyNode = new ModelNode("table body", table_body);
Mesh tableLegMesh = new Mesh(gl3, Cube.vertices.clone(), Cube.indices.clone());
Shader tableLegShader = new Shader(
gl3, "shader/vs_table_leg.txt", "shader/fs_table_leg.txt"
);
Material tableLegMaterial = new Material(
new Vec3(0.56f, 0.56f, 0.56f),
new Vec3(1.0f, 1.0f, 1.0f),
new Vec3(0.15f, 0.15f, 0.15f), 32.0f
);
table_leg = new Model(
gl3, camera, light1, light2, movingLight,
tableLegShader, tableLegMaterial, tableBodyModelMatrix, tableLegMesh, textureId_Leg01
);
tableLeg_LT_Node = new ModelNode("table leg", table_leg);
tableLeg_LB_Node = new ModelNode("table leg", table_leg);
tableLeg_RT_Node = new ModelNode("table leg", table_leg);
tableLeg_RB_Node = new ModelNode("table leg", table_leg);
Mat4 tableLegTransformMatrix = Mat4Transform.scale(TABLE_LEG_LENGTH, TABLE_LEG_HEIGHT, TABLE_LEG_WIDTH);
tableLegTransformMatrix = Mat4.multiply(Mat4Transform.translate(
0, -4, 0), tableLegTransformMatrix
);
tableLegTransform = new TransformNode(
"table leg transform (scale then translate)", tableLegTransformMatrix
);
tableLegLeftTop = new NameNode("table leg left top");
Mat4 ltTranslateMatrix = Mat4Transform.translate(-TABLE_BODY_LENGTH / 1.6f, 0, -TABLE_BODY_WIDTH / 2);
ltTranslate = new TransformNode("table leg left top translate", ltTranslateMatrix);
tableLegLeftBtm = new NameNode("table let left bottom");
Mat4 lbTranslateMatrix = Mat4Transform.translate(-TABLE_BODY_LENGTH / 1.6f, 0, TABLE_BODY_WIDTH / 2);
lbTranslate = new TransformNode("table leg left bottom translate", lbTranslateMatrix);
tableLegRightTop = new NameNode("table leg right top");
Mat4 rtTranslateMatrix = Mat4Transform.translate(TABLE_BODY_LENGTH / 1.6f, 0, -TABLE_BODY_WIDTH / 2);
rtTranslate = new TransformNode("table leg right top translate", rtTranslateMatrix);
tableLegRightBtm = new NameNode("table let right bottom");
Mat4 rbTranslateMatrix = Mat4Transform.translate(TABLE_BODY_LENGTH / 1.6f, 0, TABLE_BODY_WIDTH / 2);
rbTranslate = new TransformNode("table leg right bottom translate", rbTranslateMatrix);
}
@Override
void buildTree() {
tableRoot.addChild(tableTranslate);
tableTranslate.addChild(tableBodyName);
tableBodyName.addChild(tableBodyScale);
tableBodyScale.addChild(tableBodyNode);
tableBodyName.addChild(tableLegTransform);
tableLegTransform.addChild(tableLegLeftTop);
tableLegLeftTop.addChild(ltTranslate);
ltTranslate.addChild(tableLeg_LT_Node);
tableLegTransform.addChild(tableLegLeftBtm);
tableLegLeftBtm.addChild(lbTranslate);
lbTranslate.addChild(tableLeg_LB_Node);
tableLegTransform.addChild(tableLegRightTop);
tableLegRightTop.addChild(rtTranslate);
rtTranslate.addChild(tableLeg_RT_Node);
tableLegTransform.addChild(tableLegRightBtm);
tableLegRightBtm.addChild(rbTranslate);
rbTranslate.addChild(tableLeg_RB_Node);
}
@Override
void update() {
tableRoot.update();
}
@Override
void dispose(GL3 gl3) {
table_body.dispose(gl3);
table_leg.dispose(gl3);
}
@Override
public void draw(GL3 gl3) {
tableRoot.draw(gl3);
}
}