diff options
Diffstat (limited to 'src/tesseract')
-rw-r--r-- | src/tesseract/TesseractServer.java | 34 | ||||
-rw-r--r-- | src/tesseract/TesseractUI.java | 29 | ||||
-rw-r--r-- | src/tesseract/World.java | 83 | ||||
-rw-r--r-- | src/tesseract/objects/PhysicalObject.java | 10 |
4 files changed, 102 insertions, 54 deletions
diff --git a/src/tesseract/TesseractServer.java b/src/tesseract/TesseractServer.java new file mode 100644 index 0000000..3518c38 --- /dev/null +++ b/src/tesseract/TesseractServer.java @@ -0,0 +1,34 @@ +package tesseract; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +import alden.Peer; + +/** + * This class is not part of the deliverable. This class is simply a server to + * help peers get into the network. + * + * @author jesse + */ +public class TesseractServer { + public static void main(String[] args) { + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + Peer server = new Peer(); + server.createNetwork(); + + try { + Thread.sleep(2000); + } catch (InterruptedException e1) { + } + while (true) { + System.out.print("Enter text to send: "); + try { + String input = in.readLine(); + server.sendExtraToAllPeers(input); + } catch (IOException e) { + } + } + } +} diff --git a/src/tesseract/TesseractUI.java b/src/tesseract/TesseractUI.java index 1d6a5cc..85f46a1 100644 --- a/src/tesseract/TesseractUI.java +++ b/src/tesseract/TesseractUI.java @@ -42,10 +42,9 @@ import tesseract.newmenu.NewParticleMenuItem; import tesseract.newmenu.NewPlanarPolygonMenuItem; import tesseract.newmenu.NewSurfBoardMenuItem; import tesseract.newmenu.NewToroidMenuItem; -import tesseract.objects.Box; -import tesseract.objects.ChainLink2; import tesseract.objects.PhysicalObject; import tesseract.objects.Sphere; +import alden.Peer; import com.sun.j3d.utils.picking.PickCanvas; import com.sun.j3d.utils.picking.PickResult; @@ -84,6 +83,11 @@ public class TesseractUI extends JFrame { private World myWorld; /** + * The Peer Object + */ + private Peer myPeer; + + /** * The Canvas. */ private Canvas3D myCanvas; @@ -121,9 +125,12 @@ public class TesseractUI extends JFrame { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + myPeer = new Peer(true); + myWorld = new World( new BoundingBox(new Point3d(-UNIT / 2, -UNIT / 2, -UNIT / 2), - new Point3d(UNIT / 2, UNIT / 2, UNIT / 2))); + new Point3d(UNIT / 2, UNIT / 2, UNIT / 2)), + myPeer); myCurrentObject = null; @@ -150,20 +157,8 @@ public class TesseractUI extends JFrame { // THIS IS WHERE OBJECTS ARE FORCED INTO EXISTANCE // TODO: REMOVE TEST CODE - // Lookie! Linked chainlinks! - //myWorld.addObject(new ChainLink2(new Vector3f(0.15f, 0, 0), 1)); - //ChainLink2 o = new ChainLink2(new Vector3f(), 1); - //o.setRotation(); - - //myWorld.addForce(new AirDrag()); - - //World.addObject(new Box(0.18f, 0.1f, 0.25f, new Vector3f(0.1f, -0.10f, 0))); - //myWorld.addObject(new Box(0.18f, 0.25f, 0.1f, new Vector3f(-0.1f, 0, 0))); - PhysicalObject s = new Sphere(.05f, new Vector3f()); - s.setAngularVelocity(new Vector3f(0, 2, 0)); - myWorld.addObject(s); - - //myWorld.addObject(o); + myPeer.connectToNetwork("127.0.0.1"); + //myPeer.createNetwork(); } /** diff --git a/src/tesseract/World.java b/src/tesseract/World.java index e898a27..eb9d26b 100644 --- a/src/tesseract/World.java +++ b/src/tesseract/World.java @@ -3,12 +3,13 @@ package tesseract; import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.Observable; +import java.util.Observer; import javax.media.j3d.BoundingBox; import javax.media.j3d.BoundingLeaf; import javax.media.j3d.BoundingSphere; import javax.media.j3d.BranchGroup; -import javax.media.j3d.Canvas3D; import javax.media.j3d.DirectionalLight; import javax.media.j3d.IndexedLineArray; import javax.media.j3d.Light; @@ -19,20 +20,17 @@ import javax.vecmath.Point3d; import javax.vecmath.Vector3f; import tesseract.forces.Force; -import tesseract.objects.PhysicalObject; - import tesseract.objects.HalfSpace; - -import com.sun.j3d.utils.picking.PickTool; -import com.sun.j3d.utils.picking.behaviors.PickTranslateBehavior; -import com.sun.j3d.utils.picking.behaviors.PickZoomBehavior; +import tesseract.objects.PhysicalObject; +import alden.CollidableObject; +import alden.Peer; /** * Model of the 3D world. * * @author Jesse Morgan */ -public class World { +public class World implements Observer { /** * Root element of the world. */ @@ -46,25 +44,17 @@ public class World { /** * A list of the objects in the world. */ - private List<PhysicalObject> myObjects; + private List<CollidableObject> myObjects; /** * A list of the forces in the world. */ private List<Force> myForces; - //private List<ParticleEmitter> emitters; - //private boolean enableEmitters; - - // A list of all the particles in the world - //private List<Particle> particles; - - // A list of all the objects particles may collide with - //private List<ParticleCollidableObject> collidables; - - // Available forces - //private static final ParticleForceGenerator forces[] = {new Gravity(0.4f)}; - //private boolean activeForces[]; + /** + * The peer object for this world. + */ + private Peer myPeer; /** * Update rate for the world. @@ -76,11 +66,13 @@ public class World { * * @param bounds The bounding box of the world. */ - public World(final BoundingBox bounds) { + public World(final BoundingBox bounds, final Peer peer) { myVirtualWorldBounds = bounds; - + myPeer = peer; + myPeer.addObserver(this); + myForces = new LinkedList<Force>(); - myObjects = new LinkedList<PhysicalObject>(); + myObjects = new LinkedList<CollidableObject>(); // TODO: Should this go here? myScene = new BranchGroup(); @@ -174,25 +166,30 @@ public class World { */ public void tick() { // Iterate over objects in the world. - Iterator<PhysicalObject> itr = myObjects.iterator(); + Iterator<CollidableObject> itr = myObjects.iterator(); List<PhysicalObject> children = new LinkedList<PhysicalObject>(); while (itr.hasNext()) { - PhysicalObject obj = itr.next(); + CollidableObject obj = itr.next(); // Apply forces - for (Force force : myForces) { - force.applyForceTo(obj); + if (obj instanceof PhysicalObject) { + for (Force force : myForces) { + force.applyForceTo((PhysicalObject) obj); + } } // Update the object's state. obj.updateState(1f / UPDATE_RATE); // Spawn new objects? - List<PhysicalObject> newChildren = obj.spawnChildren(1f / UPDATE_RATE); - if (newChildren != null) { - children.addAll(newChildren); + if (obj instanceof PhysicalObject) { + 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 @@ -212,7 +209,7 @@ public class World { } } - // Add new children to thr world. + // Add new children to the world. for (PhysicalObject obj : children) { myScene.addChild(obj.getGroup()); } @@ -232,7 +229,7 @@ public class World { * * @param obj The object to add */ - public void addObject(final PhysicalObject obj) { + public void addObject(final CollidableObject obj) { myScene.addChild(obj.getGroup()); myObjects.add(obj); } @@ -261,11 +258,29 @@ public class World { public void resetWorld() { myForces.clear(); - for (PhysicalObject obj : myObjects) { + for (CollidableObject obj : myObjects) { obj.detach(); } myObjects.clear(); addHalfspaces(); } + + /** + * Observer Callback. + * Called when a PAYLOAD or EXTRA peer message is recieved. + * + * @param peer The network peer. + * @param obj The object from the network. + */ + public void update(final Observable peer, final Object obj) { + if (obj != null) { + if (obj instanceof PhysicalObject) { + addObject((PhysicalObject) obj); + + } else if (obj instanceof CollidableObject) { + addObject((CollidableObject) obj); + } + } + } } diff --git a/src/tesseract/objects/PhysicalObject.java b/src/tesseract/objects/PhysicalObject.java index c743e8e..d4e4e3b 100644 --- a/src/tesseract/objects/PhysicalObject.java +++ b/src/tesseract/objects/PhysicalObject.java @@ -2,7 +2,6 @@ package tesseract.objects; import java.util.List; -import javax.media.j3d.GeometryArray; import javax.media.j3d.Node; import javax.media.j3d.Shape3D; import javax.media.j3d.TransformGroup; @@ -20,12 +19,17 @@ import com.sun.j3d.utils.geometry.Primitive; * 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(final Vector3f thePosition, final float mass) { super(mass); this.position.set(thePosition); |