From d3b71c17fb5bac19b71ca6a486291bb65c55bec6 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Mon, 7 Mar 2011 22:37:17 +0000 Subject: The moving side code is almost right... --- src/common/Peer.java | 7 +++++++ src/tesseract/World.java | 3 +-- src/tesseract/objects/PhysicalObject.java | 11 +++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/common/Peer.java b/src/common/Peer.java index 2ba0d83..9fe4560 100644 --- a/src/common/Peer.java +++ b/src/common/Peer.java @@ -353,6 +353,13 @@ public class Peer extends Observable { public int getPeerSize() { return peers.size(); } + + /** + * Get the PeerInformation. + */ + public PeerInformation getPeerInformation() { + return this.myInfo; + } /** * A method that sends a CollidableObject to all diff --git a/src/tesseract/World.java b/src/tesseract/World.java index 648f537..da385e1 100644 --- a/src/tesseract/World.java +++ b/src/tesseract/World.java @@ -279,8 +279,7 @@ public class World implements Observer { PeerInformation peer = myPeer.getPeerInDirection(o.getVelocity().x, -o.getVelocity().z); if (peer != null) { - o.switchX(); - o.switchZ(); + o.rotateForTransmission(myPeer.getPeerInformation(), peer); myPeer.sendPayloadToPeer(peer, o); o.detach(); myObjects.remove(o); diff --git a/src/tesseract/objects/PhysicalObject.java b/src/tesseract/objects/PhysicalObject.java index 34cbec9..96c9bfa 100644 --- a/src/tesseract/objects/PhysicalObject.java +++ b/src/tesseract/objects/PhysicalObject.java @@ -11,6 +11,7 @@ import javax.vecmath.Vector3f; import com.sun.j3d.utils.geometry.Primitive; import common.CollidableObject; +import common.PeerInformation; /** * This class is the parent of all objects in the world. @@ -129,6 +130,16 @@ public class PhysicalObject extends CollidableObject { position.x = -x; } + /** + * Move the object to the correct side of the new world. + */ + public void rotateForTransmission(PeerInformation a, PeerInformation b) { + double angle = /*Math.atan(-velocity.z / velocity.x) + */ Math.PI + Math.atan((b.location.getY() - a.location.getY()) / (b.location.getX() - a.location.getX())); + + position.x = (float) (position.x * Math.cos(angle) - position.z * Math.sin(angle)); + position.z = (float) (position.z * Math.cos(angle) + position.x * Math.sin(angle)); + } + /** * @return The orientation of the object. */ -- cgit v1.2.3