mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
@@ -2,12 +2,12 @@ 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;
|
||||
import javafx.animation.AnimationTimer;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.geometry.Point2D;
|
||||
import javafx.geometry.Point3D;
|
||||
import javafx.scene.Camera;
|
||||
@@ -24,7 +24,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;
|
||||
@@ -66,6 +70,8 @@ public class GameView3D extends GameView{
|
||||
/* Note that if either of these is null then values for it have not been added and the other
|
||||
should be used as the limits of the map. */
|
||||
private Map<Mark, Marker3D> markerObjects;
|
||||
|
||||
private BoatObject playerBoat;
|
||||
private Map<ClientYacht, BoatObject> boatObjects = new HashMap<>();
|
||||
private Group wakesGroup = new Group();
|
||||
private Group boatObjectGroup = new Group();
|
||||
@@ -331,9 +337,35 @@ public class GameView3D extends GameView{
|
||||
ViewManager.getInstance().getGameClient().getServerThread().getClientId())) {
|
||||
((ChaseCamera) chaseCam).setPlayerBoat(newBoat);
|
||||
((TopDownCamera) topDownCam).setPlayerBoat(newBoat);
|
||||
|
||||
newBoat.setMarkIndicator(ModelFactory.importSTL("mark_pointer.stl"));
|
||||
playerBoat = newBoat;
|
||||
|
||||
}
|
||||
}
|
||||
Platform.runLater(() -> {
|
||||
ClientYacht playerYacht = ViewManager.getInstance().getGameClient().getAllBoatsMap()
|
||||
.get(ViewManager.getInstance().getGameClient().getServerThread().getClientId());
|
||||
|
||||
for (ObservableValue o : Arrays
|
||||
.asList(playerBoat.layoutXProperty(), playerBoat.layoutXProperty())) {
|
||||
o.addListener((obs, oldVal, newVal) -> {
|
||||
|
||||
List<Mark> marks = course.get(playerYacht.getLegNumber()).getMarks();
|
||||
Point2D midPoint = new Point2D(0, 0);
|
||||
if (marks.size() == 1) {
|
||||
midPoint = scaledPoint.findScaledXY(marks.get(0));
|
||||
} else if (marks.size() == 2) {
|
||||
midPoint = (scaledPoint.findScaledXY(marks.get(0)))
|
||||
.midpoint(scaledPoint.findScaledXY(marks.get(1)));
|
||||
}
|
||||
|
||||
if (midPoint != null) {
|
||||
playerBoat.updateMarkIndicator(midPoint);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
gameObjects.getChildren().addAll(wakes);
|
||||
gameObjects.getChildren().addAll(boatObjectGroup);
|
||||
});
|
||||
@@ -529,4 +561,4 @@ public class GameView3D extends GameView{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,14 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.ReadOnlyDoubleWrapper;
|
||||
import javafx.geometry.Point2D;
|
||||
import javafx.geometry.Point3D;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.paint.PhongMaterial;
|
||||
import javafx.scene.shape.MeshView;
|
||||
import javafx.scene.transform.Rotate;
|
||||
import javafx.scene.transform.Translate;
|
||||
|
||||
/**
|
||||
* BoatGroup is a javafx group that by default contains a graphical objects for representing a 2
|
||||
@@ -30,9 +34,10 @@ public class BoatObject extends Group {
|
||||
private Color colour = Color.BLACK;
|
||||
private Boolean isSelected = false;
|
||||
private Rotate rotation = new Rotate(0, new Point3D(0,0,1));
|
||||
// private Rotate tilt = new Rotate(0, new Point3D(0, 1, 0));
|
||||
private double previousRotation = 0;
|
||||
|
||||
// This stuff only matters to the players boat object.
|
||||
private MeshView markIndicator;
|
||||
private MeshView playerIndicator;
|
||||
private ReadOnlyDoubleWrapper rotationProperty;
|
||||
|
||||
private List<SelectedBoatListener> selectedBoatListenerListeners = new ArrayList<>();
|
||||
@@ -81,6 +86,19 @@ public class BoatObject extends Group {
|
||||
});
|
||||
}
|
||||
|
||||
public void updateMarkIndicator(Point2D markPoint) {
|
||||
Point2D boatLoc = new Point2D(this.getLayoutX(), this.getLayoutY());
|
||||
Double angle = Math.toDegrees(
|
||||
Math.atan2(boatLoc.getY() - markPoint.getY(), boatLoc.getX() - markPoint.getX())) - 90;
|
||||
|
||||
Double radius = 0.5;
|
||||
markIndicator.getTransforms().clear();
|
||||
markIndicator.getTransforms().addAll(
|
||||
new Rotate(angle, new Point3D(0, 0, 1)),
|
||||
new Translate(0, -radius, 0)
|
||||
);
|
||||
}
|
||||
|
||||
private Double normalizeHeading(double heading, double windDirection) {
|
||||
Double normalizedHeading = heading - windDirection;
|
||||
normalizedHeading = (double) Math.floorMod(normalizedHeading.longValue(), 360L);
|
||||
@@ -91,14 +109,6 @@ public class BoatObject extends Group {
|
||||
private void rotateTo(double heading, boolean sailsIn, double windDir) {
|
||||
rotationProperty.set(heading);
|
||||
rotation.setAngle(heading);
|
||||
// if (heading == previousRotation) {
|
||||
// tilt.setAngle(0);
|
||||
// } else if (heading < previousRotation) {
|
||||
// tilt.setAngle(-10);
|
||||
// } else {
|
||||
// tilt.setAngle(10);
|
||||
// }
|
||||
// previousRotation = heading;
|
||||
wake.getTransforms().setAll(new Rotate(heading, new Point3D(0,0,1)));
|
||||
if (sailsIn) {
|
||||
boatAssets.showSail();
|
||||
@@ -128,6 +138,26 @@ public class BoatObject extends Group {
|
||||
}
|
||||
}
|
||||
|
||||
public void setMarkIndicator(MeshView indicator) {
|
||||
this.markIndicator = indicator;
|
||||
this.getChildren().add(markIndicator);
|
||||
createPlayerIndicator();
|
||||
setIndicatorColor();
|
||||
}
|
||||
|
||||
private void createPlayerIndicator() {
|
||||
MeshView torus = ModelFactory.importSTL("player_circle.stl");
|
||||
playerIndicator = torus;
|
||||
this.getChildren().add(torus);
|
||||
}
|
||||
|
||||
public void setIndicatorColor() {
|
||||
Platform.runLater(() -> {
|
||||
markIndicator.setMaterial(new PhongMaterial(Color.DARKORANGE));
|
||||
playerIndicator.setMaterial(new PhongMaterial(colour));
|
||||
});
|
||||
}
|
||||
|
||||
public Group getWake () {
|
||||
return wake;
|
||||
}
|
||||
|
||||
@@ -115,9 +115,9 @@ public class ModelFactory {
|
||||
private static Group getUnmodifiedBoatModel(BoatMeshType boatType, Color primaryColour) {
|
||||
|
||||
Group boatAssets = new Group();
|
||||
MeshView hull = importSTL(boatType.hullFile);
|
||||
MeshView hull = importBoatSTL(boatType.hullFile);
|
||||
hull.setMaterial(new PhongMaterial(primaryColour));
|
||||
MeshView sail = importSTL(boatType.sailFile);
|
||||
MeshView sail = importBoatSTL(boatType.sailFile);
|
||||
sail.setMaterial(
|
||||
new PhongMaterial(boatType == BoatMeshType.PARROT ? Color.BLACK : Color.WHITE)
|
||||
);
|
||||
@@ -125,13 +125,13 @@ public class ModelFactory {
|
||||
boatAssets.getChildren().addAll(hull, sail);
|
||||
|
||||
if (boatType.mastFile != null) {
|
||||
MeshView mast = importSTL(boatType.mastFile);
|
||||
MeshView mast = importBoatSTL(boatType.mastFile);
|
||||
mast.setMaterial(new PhongMaterial(primaryColour));
|
||||
boatAssets.getChildren().add(mast);
|
||||
}
|
||||
|
||||
if (boatType.jibFile != null) {
|
||||
MeshView jib = importSTL(boatType.jibFile);
|
||||
MeshView jib = importBoatSTL(boatType.jibFile);
|
||||
sail.setMaterial(
|
||||
new PhongMaterial(boatType == BoatMeshType.PARROT ? Color.DARKGRAY : Color.WHITE)
|
||||
);
|
||||
@@ -141,9 +141,13 @@ public class ModelFactory {
|
||||
return boatAssets;
|
||||
}
|
||||
|
||||
private static MeshView importSTL(String fileName) {
|
||||
private static MeshView importBoatSTL(String fileName) {
|
||||
return importSTL("boatSTLs/" + fileName);
|
||||
}
|
||||
|
||||
public static MeshView importSTL(String fileName) {
|
||||
StlMeshImporter importer = new StlMeshImporter();
|
||||
importer.read(ModelFactory.class.getResource("/meshes/boatSTLs/" + fileName));
|
||||
importer.read(ModelFactory.class.getResource("/meshes/" + fileName));
|
||||
MeshView importedFile = new MeshView(importer.getImport());
|
||||
importedFile.setCache(true);
|
||||
importedFile.setCacheHint(CacheHint.SCALE_AND_ROTATE);
|
||||
@@ -162,6 +166,10 @@ public class ModelFactory {
|
||||
assets.setCacheHint(CacheHint.SCALE_AND_ROTATE);
|
||||
}
|
||||
switch (tokenType) {
|
||||
case PLAYER_IDENTIFIER_TORUS:
|
||||
return makeIdentifierTorus(assets);
|
||||
case NEXT_MARK_INDICATOR:
|
||||
return makeNextMarkIndicator(assets);
|
||||
case VELOCITY_PICKUP:
|
||||
case BUMPER_PICKUP:
|
||||
case RANDOM_PICKUP:
|
||||
@@ -196,6 +204,16 @@ public class ModelFactory {
|
||||
}
|
||||
}
|
||||
|
||||
private static Model makeIdentifierTorus(Group assets) {
|
||||
// assets.getChildren().add(new AmbientLight());
|
||||
return new Model(new Group(assets), null);
|
||||
}
|
||||
|
||||
private static Model makeNextMarkIndicator(Group assets) {
|
||||
// assets.getChildren().add(new AmbientLight());
|
||||
return new Model(new Group(assets), null);
|
||||
}
|
||||
|
||||
private static Model makeTokenPickup(Group assets) {
|
||||
Rotate animationRotate = new Rotate(0, new Point3D(0, 0, 1));
|
||||
assets.getTransforms().addAll(
|
||||
|
||||
@@ -28,7 +28,9 @@ public enum ModelType {
|
||||
START_ARROW ("start_arrow.dae"),
|
||||
FINISH_ARROW ("finish_arrow.dae"),
|
||||
LAND("land.dae"),
|
||||
LAND_SMOOTH("land_smooth.dae");
|
||||
LAND_SMOOTH("land_smooth.dae"),
|
||||
NEXT_MARK_INDICATOR("indicator_arrow.dae"),
|
||||
PLAYER_IDENTIFIER_TORUS("torus.dae");
|
||||
|
||||
final String filename;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user