blob: 11ae9d200cd2d6e6b56c35c84b472272e41d478c (
plain)
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
|
package tesseract.objects;
import java.util.List;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Group;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Vector3f;
/**
* This class is the parent of all objects in the world.
*
* Note: The constructor of a child class must add its shape
* to the transform group for it to be visible.
*
* @author Jesse Morgan
*/
public abstract class PhysicalObject implements Physical {
/**
* The object's current position.
*/
protected Vector3f myPosition;
/**
* BranchGroup of the object.
*/
private BranchGroup myBranchGroup;
/**
* TransformGroup for the object.
*/
private TransformGroup myTransformGroup;
/**
* Does the object still exist in the world.
*/
protected boolean myExistance;
/**
* Constructor for a PhysicalObject.
*
* @param position Initial position.
*/
public PhysicalObject(final Vector3f position) {
myPosition = new Vector3f(position);
myExistance = true;
myTransformGroup = new TransformGroup();
myTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
myBranchGroup = new BranchGroup();
myBranchGroup.setCapability(BranchGroup.ALLOW_DETACH);
myBranchGroup.addChild(myTransformGroup);
updateTransformGroup();
}
/**
* @return The object's position.
*/
public Vector3f getPosition() {
return myPosition;
}
/**
* @return The transform group of the object.
*/
protected TransformGroup getTransformGroup() {
return myTransformGroup;
}
/**
* @return Get the BranchGroup.
*/
public Group getGroup() {
return myBranchGroup;
}
/**
* Remove the object from the world.
*/
public void detach() {
myBranchGroup.detach();
myExistance = false;
}
/**
* Does this object still exist.
* @return true if it exists.
*/
public boolean isExisting() {
return myExistance;
}
/**
* Update the TransformGroup to the new position.
*/
protected void updateTransformGroup() {
Transform3D tmp = new Transform3D();
tmp.setTranslation(myPosition);
myTransformGroup.setTransform(tmp);
}
/**
* Update the state of the object.
* @param duration How much time has passed.
* @return New objects to add to the world.
*/
public List<PhysicalObject> updateState(final float duration) {
return null;
}
}
|