Wind arrow follows wind data

#story[1276]
This commit is contained in:
Zhi You Tan
2017-09-28 14:37:46 +13:00
parent d3e8a21d2f
commit 22fbb529ef
4 changed files with 36 additions and 5 deletions
@@ -11,6 +11,7 @@ import java.util.Random;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import javafx.beans.property.ReadOnlyDoubleWrapper;
import javafx.scene.paint.Color;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -82,6 +83,7 @@ public class GameState implements Runnable {
private static Long previousUpdateTime;
public static Double windDirection;
public static ReadOnlyDoubleWrapper windDirectionProperty = new ReadOnlyDoubleWrapper();
private static Double windSpeed;
private static Double serverSpeedMultiplier;
@@ -108,6 +110,7 @@ public class GameState implements Runnable {
public GameState() {
windDirection = 180d;
windDirectionProperty.set(windDirection);
windSpeed = 10000d;
yachts = new HashMap<>();
tokensInPlay = new ArrayList<>();
@@ -191,6 +194,7 @@ public class GameState implements Runnable {
public static void setWindDirection(Double newWindDirection) {
windDirection = newWindDirection;
windDirectionProperty.set(newWindDirection);
}
public static void setWindSpeed(Double newWindSpeed) {
@@ -509,6 +513,7 @@ public class GameState implements Runnable {
Double optimalAngle = PolarTable.getOptimalAngle();
Double heading = yacht.getHeading();
windDirection = (double) Math.floorMod(Math.round(heading + optimalAngle), 360L);
windDirectionProperty.set(windDirection);
}
@@ -1058,4 +1063,8 @@ public class GameState implements Runnable {
public static void setTokensEnabled (boolean tokensEnabled) {
GameState.tokensEnabled = tokensEnabled;
}
public static ReadOnlyDoubleWrapper getWindDirectionProperty() {
return windDirectionProperty;
}
}
@@ -215,10 +215,10 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
e.printStackTrace();
}
windCell.init(player);
windCell.setCamera(gameView.getView().getCamera());
gameView.getView().cameraProperty()
.addListener((obs, oldVal, newVal) -> windCell.setCamera(newVal));
System.out.println(windCell);
windArrowVBox.getChildren().add(windCell.getAssets());
}
@@ -2,6 +2,7 @@ package seng302.visualiser.controllers.cells;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.geometry.Point3D;
import javafx.scene.Camera;
import javafx.scene.Group;
import javafx.scene.Node;
@@ -9,8 +10,11 @@ import javafx.scene.PerspectiveCamera;
import javafx.scene.SceneAntialiasing;
import javafx.scene.SubScene;
import javafx.scene.layout.Pane;
import javafx.scene.transform.Rotate;
import javafx.scene.transform.Transform;
import javafx.scene.transform.Translate;
import seng302.gameServer.GameState;
import seng302.model.ClientYacht;
import seng302.visualiser.fxObjects.assets_3D.Model;
import seng302.visualiser.fxObjects.assets_3D.ModelFactory;
@@ -33,21 +37,34 @@ public class WindCell {
private PerspectiveCamera camera = null;
private ObservableList<Transform> cameraTransforms;
private Model windArrowModel;
/**
* Initialise WindCell fxml and load 3D wind arrow into a group.
*/
public void initialize() {
public void init(ClientYacht playerYacht) {
camera = new PerspectiveCamera();
camera.setFarClip(1000);
camera.setNearClip(0.1);
camera.setFieldOfView(60);
this.cameraTransforms = camera.getTransforms();
initialiseWindView();
GameState.getWindDirectionProperty().addListener(
(obs, oldValue, newValue) -> {
// if (camera instanceof IsometricCamera) {
windArrowModel.getAssets().getTransforms().clear();
windArrowModel.getAssets().getTransforms().addAll(
new Rotate(newValue.doubleValue(),
new Point3D(0, 0, 1))
);
// }
});
}
private void initialiseWindView() {
gameObjects = new Group();
System.out.println(windPane);
windPane.getChildren().add(gameObjects);
root3D = new Group(camera, gameObjects);
@@ -56,7 +73,7 @@ public class WindCell {
);
view.setCamera(camera);
Model windArrowModel = ModelFactory.makeWindArrow();
windArrowModel = ModelFactory.makeWindArrow();
gameObjects.getChildren().addAll(
windArrowModel.getAssets()
@@ -74,5 +91,9 @@ public class WindCell {
this.camera.getTransforms().add(t);
}
}
Translate t = new Translate(-55, -60, 0);
this.camera.getTransforms().add(t);
windArrowModel.getAssets().getTransforms().clear();
}
}
@@ -294,7 +294,8 @@ public class ModelFactory {
Rotate animationRotate = new Rotate(0, new Point3D(0, 1, 0));
assets.getTransforms().addAll(
new Translate(0, 0, 0),
new Scale(4, 4, 4),
new Scale(5, 5, 5),
new Rotate(270, new Point3D(1, 0, 0)),
animationRotate
);