blob: 96c9bfa6443de2eaa461b8542286df62beac5a4f (
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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
package tesseract.objects;
import java.util.List;
import javax.media.j3d.Node;
import javax.media.j3d.Shape3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Quat4f;
import javax.vecmath.Vector3f;
import com.sun.j3d.utils.geometry.Primitive;
import common.CollidableObject;
import common.PeerInformation;
/**
* 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 class PhysicalObject extends CollidableObject {
/**
* Generated Serial UID
*/
private static final long serialVersionUID = -8418338503604062404L;
protected boolean collidable;
protected boolean mySelected;
public PhysicalObject(CollidableObject p) {
super(p);
collidable = true;
mySelected = false;
}
public PhysicalObject(final Vector3f thePosition, final float mass) {
super(mass);
this.position.set(thePosition);
collidable = true;
mySelected = false;
}
public List<PhysicalObject> spawnChildren(final float duration) {
return null;
}
public void addForce(final Vector3f force) {
this.forceAccumulator.add(force);
}
public void updateState(final float duration) {
if (!mySelected) {
super.updateState(duration);
this.updateTransformGroup();
}
}
public void setShape(final Node node) {
TG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
TG.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
node.setUserData(this);
node.setCapability(javax.media.j3d.Node.ALLOW_BOUNDS_READ);
node.setCapability(javax.media.j3d.Node.ALLOW_LOCAL_TO_VWORLD_READ);
if (node instanceof Primitive) {
Primitive prim = (Primitive) node;
int index = 0;
Shape3D shape;
while ((shape = prim.getShape(index++)) != null) {
shape.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
shape.setCapability(Node.ALLOW_LOCAL_TO_VWORLD_READ);
shape.setCapability(Node.ALLOW_LOCAL_TO_VWORLD_READ);
/*for (int i = 0; i < shape.numGeometries(); i++) {
shape.getGeometry(i).setCapability(
GeometryArray.ALLOW_COUNT_READ);
shape.getGeometry(i).setCapability(
GeometryArray.ALLOW_COORDINATE_READ);
}*/
}
}
super.setShape(node);
}
public void resolveCollisions(final PhysicalObject other) {
if (collidable && other.collidable) {
super.resolveCollisions(other);
}
}
/**
* TODO: Test code to mess with the orientation of an object.
*/
public void setRotation() {
this.orientation.x = (float) (Math.PI / 4);
this.orientation.w = 1;
//this.angularVelocity.x = 0.5f;
}
/**
* @return The position of the object.
*/
public Vector3f getPosition() {
return position;
}
/**
* Switches the z position of the object before transmission.
*/
public void switchZ() {
float z = position.getZ();
position.z = -z;
}
/**
* Switches the z position of the object before transmission.
*/
public void switchX() {
float x = position.getX();
position.x = -x;
}
/**
* Move the object to the correct side of the new world.
*/
public void rotateForTransmission(PeerInformation a, PeerInformation b) {
double angle = /*Math.atan(-velocity.z / velocity.x) + */ Math.PI + Math.atan((b.location.getY() - a.location.getY()) / (b.location.getX() - a.location.getX()));
position.x = (float) (position.x * Math.cos(angle) - position.z * Math.sin(angle));
position.z = (float) (position.z * Math.cos(angle) + position.x * Math.sin(angle));
}
/**
* @return The orientation of the object.
*/
public Quat4f getOrientation() {
return this.orientation;
}
/**
* When set to true, the object will ignore all updateState calls.
*
* @param b true to ignore updateState. False to heed.
*/
public void selected(final boolean b) {
mySelected = b;
}
/**
* Update the transform group after changing the position.
*/
public void updateTranformGroup() {
super.updateTransformGroup();
}
public Vector3f getVelocity() {
return this.velocity;
}
public Vector3f getCenterOfMass() {
return this.centerOfMass;
}
public boolean isCollidable() {
return collidable;
}
public boolean isNodeNull() {
return this.node == null;
}
public float getInverseMass() {
return this.inverseMass;
}
public void setAngularVelocity(final Vector3f velocity) {
this.angularVelocity = velocity;
}
}
|