-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathModel.java
More file actions
104 lines (98 loc) · 2.64 KB
/
Copy pathModel.java
File metadata and controls
104 lines (98 loc) · 2.64 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
package javaforce.gl;
import java.util.*;
import javaforce.*;
/** Model is a set of Object3's that all share the same base orientation (rotation, translation, scale).
*
* Each object can also have its own orientation.
*
* See javaforce.gl.model for import/export classes.
*/
public class Model implements Cloneable {
public ArrayList<Object3> ol; //obj list
public ArrayList<String> textures;
public Matrix m; //translation, rotation, scale matrix for all sub-objects
public boolean visible = true;
public int refcnt;
public static boolean debug = false;
public Model() {
m = new Matrix();
m.setIdentity();
ol = new ArrayList<Object3>();
textures = new ArrayList<String>();
}
private Model(Matrix m) { //for clone()
this.m = m;
ol = new ArrayList<Object3>();
}
/**
* Clones deep enough so that the cloned object will include seperate GLObjects, but share vertex, vertex point,
* and animation data (except for the frame position).
*/
public Object clone() {
Model c = new Model((Matrix)m.clone());
int objs = ol.size();
for(int a=0;a<objs;a++) c.ol.add((Object3)ol.get(a).clone());
c.textures = textures;
return c;
}
public void setVisible(boolean state) {visible = state;}
public void addObject(Object3 obj) {
ol.add(obj);
}
public Object3 getObject(String name) {
for(int a=0;a<ol.size();a++) {
Object3 o = ol.get(a);
if (o.name.equals(name)) {
return o;
}
}
if (debug) JFLog.log("Model:Could not find object:" + name);
return null;
}
public void setIdentity() {
m.setIdentity();
}
//these are additive
public void rotate(float angle, float x, float y, float z) {
m.addRotate(angle, x, y, z);
}
public void translate(float x, float y, float z) {
m.addTranslate(x, y, z);
}
public void scale(float x, float y, float z) {
m.addScale(x, y, z);
}
public void nextFrame() {
Object3 obj;
int size = ol.size();
for(int i=0;i<size;i++) {
obj = ol.get(i);
obj.nextFrame();
}
}
public void setFrame(int idx) {
Object3 obj;
int size = ol.size();
for(int i=0;i<size;i++) {
obj = ol.get(i);
obj.setFrame(idx);
}
}
/** Adds a texture filename and returns index. */
public int addTexture(String fn) {
for(int a=0;a<textures.size();a++) {
if (textures.get(a).equals(fn)) return a;
}
textures.add(fn);
return textures.size() - 1;
}
public String getTexture(int idx) {
return textures.get(idx);
}
public void print() {
System.out.println("Model data");
for(int a=0;a<ol.size();a++) {
ol.get(a).print(this);
}
}
}