-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSGNode.java
61 lines (48 loc) · 1.41 KB
/
SGNode.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
/* This code is from exercise sheet written by Dr. Steve Maddock */
import gmaths.*;
import java.util.ArrayList;
import com.jogamp.opengl.*;
public class SGNode {
protected String name;
protected ArrayList<SGNode> children;
protected Mat4 worldTransform;
public SGNode(String name) {
children = new ArrayList<SGNode>();
this.name = name;
worldTransform = new Mat4(1);
}
public void addChild(SGNode child) {
children.add(child);
}
public void update() {
update(worldTransform);
}
protected void update(Mat4 t) {
worldTransform = t;
for (int i = 0; i < children.size(); i++) {
children.get(i).update(t);
}
}
protected String getIndentString(int indent) {
String s = "" + indent + " ";
for (int i = 0; i < indent; ++i) {
s += " ";
}
return s;
}
public void print(int indent, boolean inFull) {
System.out.println(getIndentString(indent) + "Name: " + name);
if (inFull) {
System.out.println("worldTransform");
System.out.println(worldTransform);
}
for (int i = 0; i < children.size(); i++) {
children.get(i).print(indent + 1, inFull);
}
}
public void draw(GL3 gl3) {
for (int i = 0; i < children.size(); i++) {
children.get(i).draw(gl3);
}
}
}