diff options
Diffstat (limited to 'src/tesseract/objects/PhysicalObject.java')
-rw-r--r-- | src/tesseract/objects/PhysicalObject.java | 201 |
1 files changed, 46 insertions, 155 deletions
diff --git a/src/tesseract/objects/PhysicalObject.java b/src/tesseract/objects/PhysicalObject.java index 23da734..2634ca2 100644 --- a/src/tesseract/objects/PhysicalObject.java +++ b/src/tesseract/objects/PhysicalObject.java @@ -1,19 +1,18 @@ package tesseract.objects; -import java.util.Enumeration; +import java.util.ArrayList; 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.Transform3D; -import javax.media.j3d.TransformGroup; -import javax.media.j3d.WakeupOnTransformChange; -import javax.vecmath.Point3d; -import javax.vecmath.Point3f; +import javax.media.j3d.GeometryArray; +import javax.media.j3d.Node; +import javax.media.j3d.Shape3D; import javax.vecmath.Vector3f; +import alden.CollidableObject; +import alden.CollisionInfo; + +import com.sun.j3d.utils.geometry.Primitive; + /** * This class is the parent of all objects in the world. * @@ -22,162 +21,54 @@ import javax.vecmath.Vector3f; * * @author Jesse Morgan */ -public abstract class PhysicalObject extends TransformGroup 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; - - /** - * - */ - 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 = 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 class PhysicalObject extends CollidableObject { + public PhysicalObject(final Vector3f thePosition, final float mass) { + super(mass); + this.position.set(thePosition); } - 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. - */ - public Vector3f getPosition() { - return myPosition; - } - - /** - * 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() { - return myTransformGroup; + public List<PhysicalObject> spawnChildren(final float duration) { + return null; } - - /** - * @return Get the BranchGroup. - */ - public BranchGroup getGroup() { - return myBranchGroup; + public void addForce(final Vector3f force) { + this.forceAccumulator.add(force); } - /** - * Remove the object from the world. - */ - public void detach() { - myBranchGroup.detach(); - myExistance = false; + public void updateState(final float duration) { + super.updateState(duration); + this.updateTransformGroup(); } - /** - * Does this object still exist. - * @return true if it exists. - */ - public boolean isExisting() { - return myExistance; - } + public void setShape(final Node node) { + node.setCapability(javax.media.j3d.Node.ALLOW_BOUNDS_READ); + node.setCapability(javax.media.j3d.Node.ALLOW_LOCAL_TO_VWORLD_READ); - /** - * Update the TransformGroup to the new position. - */ - protected void updateTransformGroup() { - Transform3D tmp = new Transform3D(); - tmp.setTranslation(myPosition); - - skipTGUpdates++; - super.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; - } - - 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))); - } + 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); - public void initialize() { - wakeupOn(new WakeupOnTransformChange(getTransformGroup())); - } + for (int i = 0; i < shape.numGeometries(); i++) { + shape.getGeometry(i).setCapability( + GeometryArray.ALLOW_COUNT_READ); + shape.getGeometry(i).setCapability( + GeometryArray.ALLOW_COORDINATE_READ); + } - 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())); } + + super.setShape(node); } -} + + public void resolveCollisions(final PhysicalObject other) { + if (this.node != null && other.node != null) { + super.resolveCollisions(other); + } + }
+}
\ No newline at end of file |