summaryrefslogtreecommitdiff
path: root/src/tesseract/objects/PhysicalObject.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/tesseract/objects/PhysicalObject.java')
-rw-r--r--src/tesseract/objects/PhysicalObject.java76
1 files changed, 71 insertions, 5 deletions
diff --git a/src/tesseract/objects/PhysicalObject.java b/src/tesseract/objects/PhysicalObject.java
index 11ae9d2..23da734 100644
--- a/src/tesseract/objects/PhysicalObject.java
+++ b/src/tesseract/objects/PhysicalObject.java
@@ -1,11 +1,17 @@
package tesseract.objects;
+import java.util.Enumeration;
import java.util.List;
+import javax.media.j3d.Behavior;
+import javax.media.j3d.BoundingBox;
+import javax.media.j3d.BoundingLeaf;
import javax.media.j3d.BranchGroup;
-import javax.media.j3d.Group;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
+import javax.media.j3d.WakeupOnTransformChange;
+import javax.vecmath.Point3d;
+import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;
/**
@@ -16,7 +22,7 @@ import javax.vecmath.Vector3f;
*
* @author Jesse Morgan
*/
-public abstract class PhysicalObject implements Physical {
+public abstract class PhysicalObject extends TransformGroup implements Physical {
/**
* The object's current position.
*/
@@ -38,26 +44,44 @@ public abstract class PhysicalObject implements Physical {
protected boolean myExistance;
/**
+ *
+ */
+ private int skipTGUpdates;
+
+ /**
* Constructor for a PhysicalObject.
*
* @param position Initial position.
*/
public PhysicalObject(final Vector3f position) {
+ skipTGUpdates = 0;
myPosition = new Vector3f(position);
myExistance = true;
- myTransformGroup = new TransformGroup();
+ myTransformGroup = this; //new TransformGroup();
myTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
+ myTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
+ myTransformGroup.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
+
myBranchGroup = new BranchGroup();
myBranchGroup.setCapability(BranchGroup.ALLOW_DETACH);
myBranchGroup.addChild(myTransformGroup);
+ //myBranchGroup.addChild(new TGUpdateBehavior(null));
updateTransformGroup();
}
+ public void setTransform(Transform3D t1) {
+ super.setTransform(t1);
+
+ Point3f pos = new Point3f(myPosition);
+ t1.transform(pos);
+ myPosition = new Vector3f(pos);
+ }
+
/**
* @return The object's position.
*/
@@ -66,6 +90,16 @@ public abstract class PhysicalObject implements Physical {
}
/**
+ * Update the object's position.
+ *
+ * @param position The new position.
+ */
+ public void setPosition(final Vector3f position) {
+ myPosition = new Vector3f(position);
+ updateTransformGroup();
+ }
+
+ /**
* @return The transform group of the object.
*/
protected TransformGroup getTransformGroup() {
@@ -76,7 +110,7 @@ public abstract class PhysicalObject implements Physical {
/**
* @return Get the BranchGroup.
*/
- public Group getGroup() {
+ public BranchGroup getGroup() {
return myBranchGroup;
}
@@ -102,7 +136,9 @@ public abstract class PhysicalObject implements Physical {
protected void updateTransformGroup() {
Transform3D tmp = new Transform3D();
tmp.setTranslation(myPosition);
- myTransformGroup.setTransform(tmp);
+
+ skipTGUpdates++;
+ super.setTransform(tmp);
}
/**
@@ -113,5 +149,35 @@ public abstract class PhysicalObject implements Physical {
public List<PhysicalObject> updateState(final float duration) {
return null;
}
+
+ private class TGUpdateBehavior extends Behavior {
+ public TGUpdateBehavior(final BoundingLeaf boundingLeaf) {
+ //setSchedulingBoundingLeaf(boundingLeaf);
+ setSchedulingBounds(new BoundingBox(new Point3d(-0.5, -0.5, -0.5),
+ new Point3d(0.5, 0.5, 0.5)));
+ }
+ public void initialize() {
+ wakeupOn(new WakeupOnTransformChange(getTransformGroup()));
+ }
+
+ public void processStimulus(final Enumeration e) {
+ if (skipTGUpdates == 0) {
+ System.out.println(myPosition);
+
+ Transform3D t3d = new Transform3D();
+ getTransformGroup().getTransform(t3d);
+
+ Point3f pos = new Point3f(myPosition);
+ t3d.transform(pos);
+ System.out.println(pos);
+ myPosition = new Vector3f(pos);
+ } else {
+ skipTGUpdates--;
+ System.out.println("Skip");
+ }
+
+ wakeupOn(new WakeupOnTransformChange(getTransformGroup()));
+ }
+ }
}