diff options
author | Jesse Morgan <jesse@jesterpm.net> | 2011-03-05 22:07:10 +0000 |
---|---|---|
committer | Jesse Morgan <jesse@jesterpm.net> | 2011-03-05 22:07:10 +0000 |
commit | c96d5df01b431742f88fc6b6618fc9f1f9fea01a (patch) | |
tree | ba3e4bb7c53d5ff722aa7ff0af5ac64aeab8b6c1 | |
parent | 1a7bbcdb8b68631219d171f0953d80436a4b2fcc (diff) |
Added copy constructor to collidableobject so that any collidableobject could become a physical object.
-rw-r--r-- | src/common/CollidableObject.java | 30 | ||||
-rw-r--r-- | src/tesseract/World.java | 26 | ||||
-rw-r--r-- | src/tesseract/objects/PhysicalObject.java | 6 |
3 files changed, 47 insertions, 15 deletions
diff --git a/src/common/CollidableObject.java b/src/common/CollidableObject.java index 4c04281..5ec49f3 100644 --- a/src/common/CollidableObject.java +++ b/src/common/CollidableObject.java @@ -38,6 +38,36 @@ public abstract class CollidableObject implements Serializable { // The inverse inertia tensor in world coordinates
transient private Matrix3f inverseInertiaTensorCache;
+ /**
+ * Copy Constructor
+ * @param The CollidableObject to copy.
+ */
+ protected CollidableObject(CollidableObject o) {
+ inverseMass = o.inverseMass;
+ centerOfMass = o.centerOfMass;
+ position = o.position;
+ previousPosition = o.previousPosition;
+ velocity = o.velocity;
+ previousVelocity = o.previousVelocity;
+ forceAccumulator = o.forceAccumulator;
+ orientation = o.orientation;
+ angularVelocity = o.angularVelocity;
+ previousRotationalVelocity = o.previousRotationalVelocity;
+ torqueAccumulator = o.torqueAccumulator;
+ inverseInertiaTensor = o.inverseInertiaTensor;
+ coefficientOfRestitution = o.coefficientOfRestitution;
+ penetrationCorrection = o.penetrationCorrection;
+ dynamicFriction = o.dynamicFriction;
+ rotationalFriction = o.rotationalFriction;
+ BG = o.BG;
+ TG = o.TG;
+ node = o.node;
+ vertexCache = o.vertexCache;
+ triangleCache = o.triangleCache;
+ boundsCache = o.boundsCache;
+ inverseInertiaTensorCache = o.inverseInertiaTensorCache;
+ }
+
public CollidableObject() {
this(1);
}
diff --git a/src/tesseract/World.java b/src/tesseract/World.java index a7d1f85..7953491 100644 --- a/src/tesseract/World.java +++ b/src/tesseract/World.java @@ -48,7 +48,7 @@ public class World implements Observer { /** * A list of the objects in the world. */ - private List<CollidableObject> myObjects; + private List<PhysicalObject> myObjects; /** * A list of the forces in the world. @@ -96,7 +96,7 @@ public class World implements Observer { myPeer.addObserver(this); myForces = new LinkedList<Force>(); - myObjects = new LinkedList<CollidableObject>(); + myObjects = new LinkedList<PhysicalObject>(); // TODO: Should this go here? myScene = new BranchGroup(); @@ -194,7 +194,7 @@ public class World implements Observer { */ public void tick() { // Iterate over objects in the world. - Iterator<CollidableObject> itr = myObjects.iterator(); + Iterator<PhysicalObject> itr = myObjects.iterator(); List<PhysicalObject> children = new LinkedList<PhysicalObject>(); @@ -202,22 +202,18 @@ public class World implements Observer { CollidableObject obj = itr.next(); // Apply forces - if (obj instanceof PhysicalObject) { - for (Force force : myForces) { - force.applyForceTo((PhysicalObject) obj); - } + for (Force force : myForces) { + force.applyForceTo((PhysicalObject) obj); } // Update the object's state. obj.updateState(1f / UPDATE_RATE); // Spawn new objects? - if (obj instanceof PhysicalObject) { - List<PhysicalObject> newChildren = - ((PhysicalObject) obj).spawnChildren(1f / UPDATE_RATE); - if (newChildren != null) { - children.addAll(newChildren); - } + List<PhysicalObject> newChildren = + ((PhysicalObject) obj).spawnChildren(1f / UPDATE_RATE); + if (newChildren != null) { + children.addAll(newChildren); } // If it leaves the bounds of the world, DESTROY IT @@ -340,7 +336,7 @@ public class World implements Observer { * * @param obj The object to add */ - public void addObject(final CollidableObject obj) { + public void addObject(final PhysicalObject obj) { myScene.addChild(obj.getGroup()); myObjects.add(obj); } @@ -390,7 +386,7 @@ public class World implements Observer { addObject((PhysicalObject) obj); } else if (obj instanceof CollidableObject) { - addObject((CollidableObject) obj); + addObject(new PhysicalObject((CollidableObject) obj)); } } } diff --git a/src/tesseract/objects/PhysicalObject.java b/src/tesseract/objects/PhysicalObject.java index 7b699e3..4c19381 100644 --- a/src/tesseract/objects/PhysicalObject.java +++ b/src/tesseract/objects/PhysicalObject.java @@ -29,6 +29,12 @@ public class PhysicalObject extends CollidableObject { 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); |