mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Made the windView observer the gameView camera
#story[1276] #pair[ajm412, zyt10]
This commit is contained in:
@@ -2,7 +2,6 @@ package seng302.visualiser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -24,7 +23,11 @@ import javafx.scene.transform.Scale;
|
||||
import javafx.scene.transform.Translate;
|
||||
import org.fxyz3d.scene.Skybox;
|
||||
import seng302.gameServer.messages.RoundingSide;
|
||||
import seng302.model.*;
|
||||
import seng302.model.ClientYacht;
|
||||
import seng302.model.GameKeyBind;
|
||||
import seng302.model.KeyAction;
|
||||
import seng302.model.Limit;
|
||||
import seng302.model.ScaledPoint;
|
||||
import seng302.model.mark.CompoundMark;
|
||||
import seng302.model.mark.Corner;
|
||||
import seng302.model.mark.Mark;
|
||||
@@ -75,6 +78,7 @@ public class GameView3D extends GameView{
|
||||
private Double windDir;
|
||||
private Skybox skybox;
|
||||
|
||||
|
||||
public GameView3D () {
|
||||
isometricCam = new IsometricCamera(DEFAULT_CAMERA_X, DEFAULT_CAMERA_Y);
|
||||
topDownCam = new TopDownCamera();
|
||||
@@ -343,6 +347,10 @@ public class GameView3D extends GameView{
|
||||
return view;
|
||||
}
|
||||
|
||||
public SubScene getView() {
|
||||
return view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the boatObjects color with that of the clientYachts object. Used in notification from
|
||||
* a listener on this attribute in clientYacht to re paint the boat mesh
|
||||
|
||||
@@ -9,26 +9,19 @@ import java.util.Map;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javafx.animation.RotateTransition;
|
||||
import javafx.animation.Timeline;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.ReadOnlyBooleanProperty;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.geometry.Point2D;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.SubScene;
|
||||
import javafx.scene.chart.LineChart;
|
||||
import javafx.scene.chart.NumberAxis;
|
||||
import javafx.scene.chart.XYChart;
|
||||
import javafx.scene.chart.XYChart.Data;
|
||||
import javafx.scene.chart.XYChart.Series;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.CheckBox;
|
||||
@@ -50,14 +43,11 @@ import javafx.scene.shape.Polyline;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.StageStyle;
|
||||
import javax.swing.ImageIcon;
|
||||
import seng302.model.ClientYacht;
|
||||
import seng302.model.ClientYacht.PowerUpListener;
|
||||
import seng302.model.RaceState;
|
||||
import seng302.model.mark.CompoundMark;
|
||||
import seng302.model.mark.Mark;
|
||||
import seng302.model.stream.xml.parser.RaceXMLData;
|
||||
import seng302.model.token.Token;
|
||||
import seng302.model.token.TokenType;
|
||||
import seng302.utilities.Sounds;
|
||||
import seng302.visualiser.GameView3D;
|
||||
@@ -69,8 +59,6 @@ import seng302.visualiser.controllers.dialogs.FinishDialogController;
|
||||
import seng302.visualiser.fxObjects.ChatHistory;
|
||||
import seng302.visualiser.fxObjects.assets_2D.WindArrow;
|
||||
import seng302.visualiser.fxObjects.assets_3D.BoatObject;
|
||||
import seng302.visualiser.fxObjects.assets_3D.ModelFactory;
|
||||
import seng302.visualiser.fxObjects.assets_3D.ModelType;
|
||||
|
||||
/**
|
||||
* Controller class that manages the display of a race
|
||||
@@ -132,6 +120,8 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
@FXML
|
||||
private VBox windArrowVBox;
|
||||
|
||||
|
||||
private WindCell windCell;
|
||||
//Race Data
|
||||
private Map<Integer, ClientYacht> participants;
|
||||
private Map<Integer, CompoundMark> markers;
|
||||
@@ -208,25 +198,29 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
|
||||
lastWindDirection = 0d;
|
||||
|
||||
initialiseWindArrow();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise wind arrow cell.
|
||||
*/
|
||||
private void initialiseWindArrow() {
|
||||
Pane pane = null;
|
||||
FXMLLoader loader = new FXMLLoader(
|
||||
getClass().getResource("/views/cells/WindCell.fxml"));
|
||||
loader.setController(new WindCell());
|
||||
windCell = new WindCell();
|
||||
loader.setController(windCell);
|
||||
|
||||
try {
|
||||
pane = loader.load();
|
||||
loader.load();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
windArrowVBox.getChildren().add(pane);
|
||||
windCell.setCamera(gameView.getView().getCamera());
|
||||
gameView.getView().cameraProperty()
|
||||
.addListener((obs, oldVal, newVal) -> windCell.setCamera(newVal));
|
||||
System.out.println(windCell);
|
||||
|
||||
windArrowVBox.getChildren().add(windCell.getAssets());
|
||||
}
|
||||
|
||||
public void showFinishDialog(ArrayList<ClientYacht> finishedBoats) {
|
||||
@@ -320,6 +314,12 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
});
|
||||
gameView.setWindDir(raceState.windDirectionProperty().doubleValue());
|
||||
Platform.runLater(this::initializeUpdateTimer);
|
||||
|
||||
Platform.runLater(() -> {
|
||||
//windCell.setCamera(gameView.getView().getCamera());
|
||||
|
||||
initialiseWindArrow();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
package seng302.visualiser.controllers.cells;
|
||||
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Camera;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.PerspectiveCamera;
|
||||
import javafx.scene.SceneAntialiasing;
|
||||
import javafx.scene.SubScene;
|
||||
import javafx.scene.layout.Pane;
|
||||
import seng302.visualiser.cameras.ChaseCamera;
|
||||
import seng302.visualiser.cameras.IsometricCamera;
|
||||
import seng302.visualiser.cameras.TopDownCamera;
|
||||
import javafx.scene.transform.Transform;
|
||||
import javafx.scene.transform.Translate;
|
||||
import seng302.visualiser.fxObjects.assets_3D.Model;
|
||||
import seng302.visualiser.fxObjects.assets_3D.ModelFactory;
|
||||
|
||||
@@ -19,26 +23,56 @@ public class WindCell {
|
||||
|
||||
private final double FOV = 60;
|
||||
private final double DEFAULT_CAMERA_X = 0;
|
||||
private final double DEFAULT_CAMERA_Y = 155;
|
||||
private final double DEFAULT_CAMERA_Y = 50;
|
||||
|
||||
private Group root3D;
|
||||
private SubScene view;
|
||||
private Group gameObjects;
|
||||
|
||||
// Cameras
|
||||
private PerspectiveCamera isometricCam;
|
||||
private PerspectiveCamera topDownCam;
|
||||
private PerspectiveCamera chaseCam;
|
||||
private PerspectiveCamera camera = null;
|
||||
private ObservableList<Transform> cameraTransforms;
|
||||
|
||||
/**
|
||||
* Initialise WindCell fxml and load 3D wind arrow into a group.
|
||||
*/
|
||||
public void initialize() {
|
||||
Group group = new Group();
|
||||
windPane.getChildren().add(group);
|
||||
Model windArrowModel = ModelFactory.makeWindArrow();
|
||||
group.getChildren().add(windArrowModel.getAssets());
|
||||
|
||||
isometricCam = new IsometricCamera(DEFAULT_CAMERA_X, DEFAULT_CAMERA_Y);
|
||||
topDownCam = new TopDownCamera();
|
||||
chaseCam = new ChaseCamera();
|
||||
camera = new PerspectiveCamera();
|
||||
camera.setFarClip(1000);
|
||||
camera.setNearClip(0.1);
|
||||
camera.setFieldOfView(60);
|
||||
this.cameraTransforms = camera.getTransforms();
|
||||
initialiseWindView();
|
||||
}
|
||||
|
||||
private void initialiseWindView() {
|
||||
gameObjects = new Group();
|
||||
System.out.println(windPane);
|
||||
windPane.getChildren().add(gameObjects);
|
||||
|
||||
root3D = new Group(camera, gameObjects);
|
||||
view = new SubScene(
|
||||
root3D, 110, 120, true, SceneAntialiasing.BALANCED
|
||||
);
|
||||
view.setCamera(camera);
|
||||
|
||||
Model windArrowModel = ModelFactory.makeWindArrow();
|
||||
|
||||
gameObjects.getChildren().addAll(
|
||||
windArrowModel.getAssets()
|
||||
);
|
||||
}
|
||||
|
||||
public Node getAssets() {
|
||||
return view;
|
||||
}
|
||||
|
||||
public void setCamera(Camera camera) {
|
||||
this.camera.getTransforms().clear();
|
||||
for (Transform t : camera.getTransforms()) {
|
||||
if (!(t instanceof Translate)) {
|
||||
this.camera.getTransforms().add(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,8 +293,8 @@ public class ModelFactory {
|
||||
|
||||
Rotate animationRotate = new Rotate(0, new Point3D(0, 1, 0));
|
||||
assets.getTransforms().addAll(
|
||||
new Translate(55, 60, 0),
|
||||
new Scale(5, 5, 5),
|
||||
new Translate(0, 0, 0),
|
||||
new Scale(4, 4, 4),
|
||||
animationRotate
|
||||
);
|
||||
|
||||
@@ -302,16 +302,6 @@ public class ModelFactory {
|
||||
new AmbientLight()
|
||||
);
|
||||
|
||||
return new Model(new Group(assets), new AnimationTimer() {
|
||||
|
||||
private double rotation = 0;
|
||||
private Rotate rotate = animationRotate;
|
||||
|
||||
@Override
|
||||
public void handle(long now) {
|
||||
rotation += 1;
|
||||
rotate.setAngle(rotation);
|
||||
}
|
||||
});
|
||||
return new Model(new Group(assets), null);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user