From 8ec649062727bd7882183f14f31fa1caf4c7b9e0 Mon Sep 17 00:00:00 2001 From: Kusal Ekanayake Date: Sun, 13 Aug 2017 17:02:35 +1200 Subject: [PATCH] Started trying to get the zoomed in gave view to follow the boat. Can easily make the boat stay put at the origin. can make it perfectly center, also weary of the weird jittery effect that is present when tracking. Tracking is active when the zoom scale is greater than 1. #story[1121] --- .../java/seng302/visualiser/GameClient.java | 3 +- .../java/seng302/visualiser/GameView.java | 31 +++++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/main/java/seng302/visualiser/GameClient.java b/src/main/java/seng302/visualiser/GameClient.java index cf4590ca..6246eef3 100644 --- a/src/main/java/seng302/visualiser/GameClient.java +++ b/src/main/java/seng302/visualiser/GameClient.java @@ -215,6 +215,7 @@ public class GameClient { * Updates the position of a boat. Boat and position are given in the provided data. */ private void updatePosition(PositionUpdateData positionData) { + raceView.getGameView().trackBoat(); if (positionData.getType() == DeviceType.YACHT_TYPE) { if (allXMLReceived() && allBoatsMap.containsKey(positionData.getDeviceId())) { Yacht yacht = allBoatsMap.get(positionData.getDeviceId()); @@ -306,11 +307,9 @@ public class GameClient { //TODO Allow a zoom in and zoom out methods case Z: // zoom in raceView.getGameView().zoomIn(); - System.out.println("Zoom in"); break; case X: // zoom out raceView.getGameView().zoomOut(); - System.out.println("Zoom out"); break; } } diff --git a/src/main/java/seng302/visualiser/GameView.java b/src/main/java/seng302/visualiser/GameView.java index 1f0a6ceb..f984186a 100644 --- a/src/main/java/seng302/visualiser/GameView.java +++ b/src/main/java/seng302/visualiser/GameView.java @@ -88,15 +88,15 @@ public class GameView extends Pane { double scaleFactor = 1; public void zoomOut() { - scaleFactor = 0.95; - this.setScaleX(this.getScaleX() * scaleFactor); - this.setScaleY(this.getScaleY() * scaleFactor); + scaleFactor = 0.05; + this.setScaleX(this.getScaleX() - scaleFactor); + this.setScaleY(this.getScaleY() - scaleFactor); } public void zoomIn() { - scaleFactor = 1.05; - this.setScaleX(this.getScaleX() * scaleFactor); - this.setScaleY(this.getScaleY() * scaleFactor); + scaleFactor = 0.05; + this.setScaleX(this.getScaleX() + scaleFactor); + this.setScaleY(this.getScaleY() + scaleFactor); } private enum ScaleDirection { @@ -104,6 +104,25 @@ public class GameView extends Pane { VERTICAL } + public void trackBoat() { + if (this.getScaleX() > 1) { + double x = boatObjects.get(playerYacht).getBoatLayoutX(); + double y = boatObjects.get(playerYacht).getBoatLayoutY(); +// System.out.println("x = " + x); +// System.out.println("y = " + y); +// this.setRotate(-playerYacht.getHeading()); + Point2D displacementX = findScaledXY(maxLonPoint); + Point2D displacementY = findScaledXY(maxLatPoint); + this.setLayoutX(-x + 250 + canvasWidth/2); + this.setLayoutY(-y + canvasHeight/2); + } else { + this.setLayoutX(0); + this.setLayoutY(0); + } + System.out.println("boatObjects = " + boatObjects.get(playerYacht).getBoatLayoutX()); + System.out.println("boatObjects = " + boatObjects.get(playerYacht).getBoatLayoutY()); + } + public GameView () { gameObjects = this.getChildren(); // create image view for map, bind panel size to image