summaryrefslogtreecommitdiff
path: root/src/tesseract/objects
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2011-02-11 03:45:01 +0000
committerJesse Morgan <jesse@jesterpm.net>2011-02-11 03:45:01 +0000
commit14dcf5b2488c4429e50f76e6cef339cac2653430 (patch)
treea8fbec11d52e74ac4b0b9dc2cb5377d3c36fc240 /src/tesseract/objects
parent418587987e3b424667db57bd1aec30178448a72a (diff)
Some of the grabbing code.
Diffstat (limited to 'src/tesseract/objects')
-rw-r--r--src/tesseract/objects/CollidableObject.java5
-rw-r--r--src/tesseract/objects/ForceableObject.java3
-rw-r--r--src/tesseract/objects/Particle.java4
-rw-r--r--src/tesseract/objects/Physical.java7
-rw-r--r--src/tesseract/objects/PhysicalObject.java76
5 files changed, 83 insertions, 12 deletions
diff --git a/src/tesseract/objects/CollidableObject.java b/src/tesseract/objects/CollidableObject.java
index 3ab00af..96248ac 100644
--- a/src/tesseract/objects/CollidableObject.java
+++ b/src/tesseract/objects/CollidableObject.java
@@ -2,25 +2,22 @@ package tesseract.objects;
import javax.vecmath.Vector3f;
-public class CollidableObject extends PhysicalObject implements Collidable {
+public abstract class CollidableObject extends PhysicalObject implements Collidable {
public CollidableObject(Vector3f position) {
super(position);
}
- @Override
public CollisionInfo calculateCollision(Physical obj) {
// TODO Auto-generated method stub
return null;
}
- @Override
public boolean hasCollision(Physical obj) {
// TODO Auto-generated method stub
return false;
}
- @Override
public void resolveCollision(Physical obj, CollisionInfo collision) {
// TODO Auto-generated method stub
diff --git a/src/tesseract/objects/ForceableObject.java b/src/tesseract/objects/ForceableObject.java
index 3100a5a..b918452 100644
--- a/src/tesseract/objects/ForceableObject.java
+++ b/src/tesseract/objects/ForceableObject.java
@@ -9,7 +9,8 @@ import javax.vecmath.Vector3f;
*
* @author Jesse Morgan
*/
-public class ForceableObject extends PhysicalObject implements Forceable {
+public abstract class ForceableObject
+ extends PhysicalObject implements Forceable {
/**
* The inverse of the object's mass.
*/
diff --git a/src/tesseract/objects/Particle.java b/src/tesseract/objects/Particle.java
index 8307c55..b2f66e4 100644
--- a/src/tesseract/objects/Particle.java
+++ b/src/tesseract/objects/Particle.java
@@ -74,7 +74,7 @@ public class Particle extends ForceableObject {
cAttr = new ColoringAttributes(color, ColoringAttributes.FASTEST);
Appearance appearance = new Appearance();
appearance.setColoringAttributes(cAttr);
- return new Sphere(RADIUS, 0, DIVISIONS, appearance);
+ return new Sphere(RADIUS, Sphere.ENABLE_GEOMETRY_PICKING,
+ DIVISIONS, appearance);
}
-
}
diff --git a/src/tesseract/objects/Physical.java b/src/tesseract/objects/Physical.java
index abf8c0f..40d50ee 100644
--- a/src/tesseract/objects/Physical.java
+++ b/src/tesseract/objects/Physical.java
@@ -13,4 +13,11 @@ public interface Physical {
* @return The position of the object in the world.
*/
Vector3f getPosition();
+
+ /**
+ * Set the object's position.
+ *
+ * @param position The new position.
+ */
+ void setPosition(Vector3f position);
}
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()));
+ }
+ }
}