mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Wind arrow follows wind data
#story[1276]
This commit is contained in:
@@ -11,6 +11,7 @@ import java.util.Random;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
import javafx.beans.property.ReadOnlyDoubleWrapper;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -82,6 +83,7 @@ public class GameState implements Runnable {
|
|||||||
|
|
||||||
private static Long previousUpdateTime;
|
private static Long previousUpdateTime;
|
||||||
public static Double windDirection;
|
public static Double windDirection;
|
||||||
|
public static ReadOnlyDoubleWrapper windDirectionProperty = new ReadOnlyDoubleWrapper();
|
||||||
private static Double windSpeed;
|
private static Double windSpeed;
|
||||||
private static Double serverSpeedMultiplier;
|
private static Double serverSpeedMultiplier;
|
||||||
|
|
||||||
@@ -108,6 +110,7 @@ public class GameState implements Runnable {
|
|||||||
|
|
||||||
public GameState() {
|
public GameState() {
|
||||||
windDirection = 180d;
|
windDirection = 180d;
|
||||||
|
windDirectionProperty.set(windDirection);
|
||||||
windSpeed = 10000d;
|
windSpeed = 10000d;
|
||||||
yachts = new HashMap<>();
|
yachts = new HashMap<>();
|
||||||
tokensInPlay = new ArrayList<>();
|
tokensInPlay = new ArrayList<>();
|
||||||
@@ -191,6 +194,7 @@ public class GameState implements Runnable {
|
|||||||
|
|
||||||
public static void setWindDirection(Double newWindDirection) {
|
public static void setWindDirection(Double newWindDirection) {
|
||||||
windDirection = newWindDirection;
|
windDirection = newWindDirection;
|
||||||
|
windDirectionProperty.set(newWindDirection);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setWindSpeed(Double newWindSpeed) {
|
public static void setWindSpeed(Double newWindSpeed) {
|
||||||
@@ -509,6 +513,7 @@ public class GameState implements Runnable {
|
|||||||
Double optimalAngle = PolarTable.getOptimalAngle();
|
Double optimalAngle = PolarTable.getOptimalAngle();
|
||||||
Double heading = yacht.getHeading();
|
Double heading = yacht.getHeading();
|
||||||
windDirection = (double) Math.floorMod(Math.round(heading + optimalAngle), 360L);
|
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) {
|
public static void setTokensEnabled (boolean tokensEnabled) {
|
||||||
GameState.tokensEnabled = tokensEnabled;
|
GameState.tokensEnabled = tokensEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ReadOnlyDoubleWrapper getWindDirectionProperty() {
|
||||||
|
return windDirectionProperty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -215,10 +215,10 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
windCell.init(player);
|
||||||
windCell.setCamera(gameView.getView().getCamera());
|
windCell.setCamera(gameView.getView().getCamera());
|
||||||
gameView.getView().cameraProperty()
|
gameView.getView().cameraProperty()
|
||||||
.addListener((obs, oldVal, newVal) -> windCell.setCamera(newVal));
|
.addListener((obs, oldVal, newVal) -> windCell.setCamera(newVal));
|
||||||
System.out.println(windCell);
|
|
||||||
|
|
||||||
windArrowVBox.getChildren().add(windCell.getAssets());
|
windArrowVBox.getChildren().add(windCell.getAssets());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package seng302.visualiser.controllers.cells;
|
|||||||
|
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.geometry.Point3D;
|
||||||
import javafx.scene.Camera;
|
import javafx.scene.Camera;
|
||||||
import javafx.scene.Group;
|
import javafx.scene.Group;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
@@ -9,8 +10,11 @@ import javafx.scene.PerspectiveCamera;
|
|||||||
import javafx.scene.SceneAntialiasing;
|
import javafx.scene.SceneAntialiasing;
|
||||||
import javafx.scene.SubScene;
|
import javafx.scene.SubScene;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
|
import javafx.scene.transform.Rotate;
|
||||||
import javafx.scene.transform.Transform;
|
import javafx.scene.transform.Transform;
|
||||||
import javafx.scene.transform.Translate;
|
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.Model;
|
||||||
import seng302.visualiser.fxObjects.assets_3D.ModelFactory;
|
import seng302.visualiser.fxObjects.assets_3D.ModelFactory;
|
||||||
|
|
||||||
@@ -33,21 +37,34 @@ public class WindCell {
|
|||||||
private PerspectiveCamera camera = null;
|
private PerspectiveCamera camera = null;
|
||||||
private ObservableList<Transform> cameraTransforms;
|
private ObservableList<Transform> cameraTransforms;
|
||||||
|
|
||||||
|
private Model windArrowModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise WindCell fxml and load 3D wind arrow into a group.
|
* Initialise WindCell fxml and load 3D wind arrow into a group.
|
||||||
*/
|
*/
|
||||||
public void initialize() {
|
public void init(ClientYacht playerYacht) {
|
||||||
camera = new PerspectiveCamera();
|
camera = new PerspectiveCamera();
|
||||||
camera.setFarClip(1000);
|
camera.setFarClip(1000);
|
||||||
camera.setNearClip(0.1);
|
camera.setNearClip(0.1);
|
||||||
camera.setFieldOfView(60);
|
camera.setFieldOfView(60);
|
||||||
this.cameraTransforms = camera.getTransforms();
|
this.cameraTransforms = camera.getTransforms();
|
||||||
initialiseWindView();
|
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() {
|
private void initialiseWindView() {
|
||||||
gameObjects = new Group();
|
gameObjects = new Group();
|
||||||
System.out.println(windPane);
|
|
||||||
windPane.getChildren().add(gameObjects);
|
windPane.getChildren().add(gameObjects);
|
||||||
|
|
||||||
root3D = new Group(camera, gameObjects);
|
root3D = new Group(camera, gameObjects);
|
||||||
@@ -56,7 +73,7 @@ public class WindCell {
|
|||||||
);
|
);
|
||||||
view.setCamera(camera);
|
view.setCamera(camera);
|
||||||
|
|
||||||
Model windArrowModel = ModelFactory.makeWindArrow();
|
windArrowModel = ModelFactory.makeWindArrow();
|
||||||
|
|
||||||
gameObjects.getChildren().addAll(
|
gameObjects.getChildren().addAll(
|
||||||
windArrowModel.getAssets()
|
windArrowModel.getAssets()
|
||||||
@@ -74,5 +91,9 @@ public class WindCell {
|
|||||||
this.camera.getTransforms().add(t);
|
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));
|
Rotate animationRotate = new Rotate(0, new Point3D(0, 1, 0));
|
||||||
assets.getTransforms().addAll(
|
assets.getTransforms().addAll(
|
||||||
new Translate(0, 0, 0),
|
new Translate(0, 0, 0),
|
||||||
new Scale(4, 4, 4),
|
new Scale(5, 5, 5),
|
||||||
|
new Rotate(270, new Point3D(1, 0, 0)),
|
||||||
animationRotate
|
animationRotate
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user