Created new yacht shape and altered the number of lights.

#implement
This commit is contained in:
Calum
2017-09-05 17:17:42 +12:00
parent 81afad1bcc
commit 04518c35b0
14 changed files with 498 additions and 135 deletions
+14 -16
View File
@@ -15,6 +15,7 @@ import javafx.collections.ObservableList;
import javafx.geometry.Point2D;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.PointLight;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
@@ -25,6 +26,7 @@ import javafx.scene.paint.Paint;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Polygon;
import javafx.scene.text.Text;
import javafx.scene.transform.Translate;
import javafx.util.Duration;
import seng302.gameServer.messages.RoundingSide;
import seng302.model.ClientYacht;
@@ -139,6 +141,17 @@ public class GameView extends Pane {
public GameView () {
gameObjects = this.getChildren();
PointLight pointLight = new PointLight(Color.WHITE);
pointLight.setLightOn(true);
pointLight.getTransforms().add(new Translate(100, 100, -100));
gameObjects.add(pointLight);
pointLight = new PointLight(Color.WHITE);
pointLight.setLightOn(true);
pointLight.getTransforms().add(new Translate(900, 900, -100));
gameObjects.add(pointLight);
// AmbientLight ambientLight = new AmbientLight(new Color(1,1,1,0.4));
//// ambientLight.setOpacity(0.5);
// gameObjects.add(ambientLight);
// create image view for map, bind panel size to image
gameObjects.add(mapImage);
gameObjects.add(raceBorder);
@@ -183,10 +196,7 @@ public class GameView extends Pane {
lastTime = now;
}
}
boatObjects.forEach((boat, boatObject) -> boatObject.updateLocation());
// for (Cylinder c : mapTokens) {
// c.getTransforms().add(new Rotate(1, new Point3D(45, 45, 45)));
// }
// boatObjects.forEach((boat, boatObject) -> boatObject.updateLocation());
}
};
}
@@ -445,24 +455,12 @@ public class GameView extends Pane {
* @param newTokens the tokens to be put on the course.
*/
public void updateTokens(List<Token> newTokens) {
// List<Marker> mapTokens = new ArrayList<>();
//
// for (Token token : newTokens) {
// Point2D location = findScaledXY(token.getLat(), token.getLng());
// Marker thisMarker = new Marker(Color.YELLOW);
// thisMarker.setLayoutX(location.getX());
// thisMarker.setLayoutY(location.getY());
// mapTokens.add(thisMarker);
// }
mapTokens = new ArrayList<>();
for (Token token : newTokens) {
Point2D location = findScaledXY(token.getLat(), token.getLng());
Node tokenObject = new VelocityPickup();
// tokenObject.getTransforms().add(new Rotate(45, new Point3D(45, 45, 45)));
tokenObject.setLayoutX(location.getX());
tokenObject.setLayoutY(location.getY());
// tokenObject.setMaterial(new PhongMaterial(Color.YELLOW));
mapTokens.add(tokenObject);
}
@@ -31,6 +31,7 @@ import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Line;
import javafx.scene.shape.Polyline;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
@@ -47,6 +48,7 @@ import seng302.visualiser.controllers.annotations.ImportantAnnotationController;
import seng302.visualiser.controllers.annotations.ImportantAnnotationDelegate;
import seng302.visualiser.controllers.annotations.ImportantAnnotationsState;
import seng302.visualiser.fxObjects.BoatObject;
import seng302.visualiser.fxObjects.WindArrow;
/**
* Controller class that manages the display of a race
@@ -66,7 +68,9 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
@FXML
private AnchorPane contentAnchorPane;
@FXML
private Text windArrowText, windDirectionText;
private Text windDirectionText;
@FXML
private AnchorPane windArrowHolder;
@FXML
private Slider annotationSlider;
@FXML
@@ -89,6 +93,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
private Timer timer = new Timer();
private List<Series<String, Double>> sparkLineData = new ArrayList<>();
private ImportantAnnotationsState importantAnnotations;
private Polyline windArrow = new WindArrow(Color.LIGHTGRAY);
public void initialize() {
// Load a default important annotation state
@@ -105,6 +110,9 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
positionVbox.getStylesheets().add(getClass().getResource("/css/master.css").toString());
selectAnnotationBtn.setOnAction(event -> loadSelectAnnotationView());
windArrowHolder.getChildren().addAll(windArrow);
windArrow.setLayoutX(windArrowHolder.getWidth() / 2);
windArrow.setLayoutY(windArrowHolder.getHeight() / 2);
}
public void loadRace (
@@ -148,13 +156,15 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
raceState.addCollisionListener(gameView::drawCollision);
raceState.windDirectionProperty().addListener((obs, oldDirection, newDirection) -> {
gameView.setWindDir(newDirection.doubleValue());
updateWindDirection(newDirection.doubleValue());
Platform.runLater(() -> updateWindDirection(newDirection.doubleValue()));
});
raceState.windSpeedProperty().addListener((obs, oldSpeed, newSpeed) -> {
updateWindSpeed(newSpeed.doubleValue());
raceState.windSpeedProperty().addListener((obs, oldSpeed, newSpeed) ->
Platform.runLater(() -> updateWindSpeed(newSpeed.doubleValue()))
);
Platform.runLater(() -> {
updateWindDirection(raceState.windDirectionProperty().doubleValue());
updateWindSpeed(raceState.getWindSpeed());
});
updateWindDirection(raceState.windDirectionProperty().doubleValue());
updateWindSpeed(raceState.getWindSpeed());
gameView.setWindDir(raceState.windDirectionProperty().doubleValue());
}
@@ -383,7 +393,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
*/
private void updateWindDirection(double direction) {
windDirectionText.setText(String.format("%.1f°", direction));
windArrowText.setRotate(direction);
windArrow.setRotate(direction);
}
/**
@@ -8,15 +8,16 @@ import javafx.geometry.Point2D;
import javafx.geometry.Point3D;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.PointLight;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.DrawMode;
import javafx.scene.shape.Line;
import javafx.scene.shape.MeshView;
import javafx.scene.shape.Polygon;
import javafx.scene.shape.Polyline;
import javafx.scene.shape.Shape3D;
import javafx.scene.transform.Rotate;
import javafx.scene.transform.Scale;
/**
* BoatGroup is a javafx group that by default contains a graphical objects for representing a 2
@@ -66,6 +67,7 @@ public class BoatObject extends Group {
private Color colour = Color.BLACK;
private Boolean isSelected = false, destinationSet; //All boats are initialised as selected
private boolean isPlayer = false;
private Rotate rotation = new Rotate(0,0,1);
private List<SelectedBoatListener> selectedBoatListenerListeners = new ArrayList<>();
@@ -97,6 +99,13 @@ public class BoatObject extends Group {
*/
private void initChildren(double... points) {
boatPoly = makeBoatPolygon();
boatPoly.getTransforms().addAll(
new Rotate(-40, new Point3D(1,0,0)),
rotation,
new Rotate(180, new Point3D(0, 0, 1))
);
boatPoly.getTransforms().add(new Scale(10, 10, 10));
boatPoly.setDrawMode(DrawMode.FILL);
// boatPoly.setFill(colour);
// boatPoly.setFill(this.colour);
// boatPoly.setMaterial(new PhongMaterial(this.colour));
@@ -133,92 +142,27 @@ public class BoatObject extends Group {
sail.setFill(Color.TRANSPARENT);
sail.setCache(true);
super.getChildren().clear();
super.getChildren().addAll(boatPoly, sail);
super.getChildren().addAll(boatPoly);//, sail);
}
public void setFill (Color value) {
PointLight pointLight = new PointLight();
// pointLight.setTranslateX(VIEWPORT_SIZE*3/4);
// pointLight.setTranslateY(VIEWPORT_SIZE/2);
// pointLight.setTranslateZ(VIEWPORT_SIZE/2);
// PointLight pointLight2 = new PointLight(lightColor);
// pointLight2.setTranslateX(VIEWPORT_SIZE*1/4);
// pointLight2.setTranslateY(VIEWPORT_SIZE*3/4);
// pointLight2.setTranslateZ(VIEWPORT_SIZE*3/4);
// PointLight pointLight3 = new PointLight(lightColor);
// pointLight3.setTranslateX(VIEWPORT_SIZE*5/8);
// pointLight3.setTranslateY(VIEWPORT_SIZE/2);
// pointLight3.setTranslateZ(0);
//
// Color ambientColor = Color.rgb(80, 80, 80, 0);
// AmbientLight ambient = new AmbientLight(ambientColor);
this.getChildren().add(pointLight);
// this.getChildren().add(pointLight2);
// this.getChildren().add(pointLight3);
// this.getChildren().add(ambient);
this.colour = value;
PhongMaterial pm = new PhongMaterial(this.colour);
// pm.setSpecularPower(16);
// pm.setSpecularColor(lightColor);
pm.setSpecularPower(0.5);
boatPoly.setMaterial(pm);
trail.setStroke(colour);
}
public Shape3D makeBoatPolygon () {
StlMeshImporter importer = new StlMeshImporter();
// System.out.println(BoatObject.class.getResource("simpleboat.stl").toString());
System.out.println(BoatObject.class.getResource("/views/StartScreenView.fxml").toString());
importer.read(getClass().getResource("/simpleboat.stl").toString());
importer.read(getClass().getResource("/meshes/simple_yacht.stl").toString());
// importer.read(getClass().getResource("/cube.stl").toString());
// importer.read(getClass().getResource("/meshes/simple_yacht.stl").toString());
// ObjModelImporter importer = new ObjModelImporter();
// ColModelImporter importer = new ColModelImporter();
// importer.read(getClass().getResource("/meshes/simple_yacht.dae"));
// MeshView mesh = importer.getImport()[0];
return new MeshView(importer.getImport());
// MeshView boat = new MeshView();
// TriangleMesh boatMesh = new TriangleMesh();
//// -BOAT_WIDTH / 2, BOAT_HEIGHT / 2,
//// 0.0, -BOAT_HEIGHT / 2,
//// BOAT_WIDTH / 2, BOAT_HEIGHT / 2
// boatMesh.getPoints().addAll(
// -BOAT_WIDTH / 2, BOAT_HEIGHT / 2, 0,
// 0, -BOAT_HEIGHT / 2,0,
// BOAT_WIDTH / 2, BOAT_HEIGHT / 2, 0
// );
// boatMesh.getTexCoords().addAll(0.5f,0,0,1,1,1);
// boatMesh.getFaces().addAll(
// 0,0,1,1,2,2//,
//// 1,1,2,2,3,3,
//// 0,0,2,2,3,3,
//// 1,1,0,0,3,3
// );
// boat.setMesh(boatMesh);
//// boat.setDrawMode(DrawMode.LINE);
// return boat;
//// Box b = new Box();
//// TriangleMesh planeMesh = new TriangleMesh();
//// float[] points = {
//// -10, 10, 5,
//// -10, -10, 10,
//// 10, 10, 15,
//// 10, 10, 20
//// };
//// float[] texCoords = {
//// 0, 0,
//// 0, 1,
//// 1, 0,
//// 1, 1
//// };
//// int[] faces = {
//// 0, 0, 1, 1, 2, 2,
//// 2, 2, 3, 3, 1, 1
//// };
//// planeMesh.getPoints().addAll(points);
//// planeMesh.getTexCoords().addAll(texCoords);
//// planeMesh.getFaces().addAll(faces);
//// MeshView meshView = new MeshView(planeMesh);
// meshView.setMaterial(new PhongMaterial(Color.BLACK));
// return meshView;
}
/**
@@ -279,7 +223,7 @@ public class BoatObject extends Group {
private void rotateTo(double heading, boolean sailsIn, double windDir) {
// boatPoly.getTransforms().add(new Rotate(heading, new Point3D(0,0,1)));
rotation.setAngle(heading);
if (sailsIn) {
Double sailWindOffset = 30.0;
Double upwindAngleLimit = 15.0;
@@ -333,7 +277,7 @@ public class BoatObject extends Group {
}
public void updateLocation() {
boatPoly.getTransforms().add(new Rotate(2, new Point3D(1,1,1)));
// boatPoly.getTransforms().add(new Rotate(2, new Point3D(1,1,1)));
// double dx = xVelocity / 60;
// double dy = yVelocity / 60;
//
@@ -469,7 +413,7 @@ public class BoatObject extends Group {
public void setTrajectory(double heading, double velocity, double windDir) {
wake.setRotation(lastHeading - heading, velocity);
rotateTo(heading, false, windDir);
// rotateTo(heading, false, windDir);
xVelocity = Math.cos(Math.toRadians(heading)) * velocity;
yVelocity = Math.sin(Math.toRadians(heading)) * velocity;
lastHeading = heading;
@@ -1,31 +1,31 @@
package seng302.visualiser.fxObjects;
import com.interactivemesh.jfx.importer.stl.StlMeshImporter;
import javafx.animation.AnimationTimer;
import javafx.application.Platform;
import javafx.geometry.Point3D;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.MeshView;
import javafx.scene.shape.Cylinder;
import javafx.scene.transform.Rotate;
import javafx.scene.transform.Scale;
/**
* Created by cir27 on 3/09/17.
*/
public class VelocityPickup extends MeshView {
public class VelocityPickup extends Cylinder {
public double rotation = 0;
public Rotate timerRotation = new Rotate(0, new Point3D(0,0,1));
public Rotate timerRotation = new Rotate(0, new Point3D(1,1,1));
public VelocityPickup () {
StlMeshImporter importer = new StlMeshImporter();
importer.read(getClass().getResource("/velocity_pickup.stl").toString());
this.setMesh(importer.getImport());
// StlMeshImporter importer = new StlMeshImporter();
// importer.read(getClass().getResource("/velocity_pickup.stl").toString());
// this.setMesh(importer.getImport());
this.setRadius(10);
this.setHeight(10);
this.setMaterial(new PhongMaterial(Color.YELLOW));
this.getTransforms().add(new Scale(30,30,30));
this.getTransforms().add(new Rotate(30, new Point3D(1,0, 0)));
this.getTransforms().add(new Rotate(90, new Point3D(0,1, 0)));
// this.getTransforms().add(new Scale(30,30,30));
// this.getTransforms().add(new Rotate(30, new Point3D(1,0, 0)));
// this.getTransforms().add(new Rotate(90, new Point3D(0,1, 0)));
this.getTransforms().add(timerRotation);
AnimationTimer at = new AnimationTimer() {
@Override
@@ -0,0 +1,25 @@
package seng302.visualiser.fxObjects;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Polyline;
import javafx.scene.shape.StrokeLineCap;
import javafx.scene.shape.StrokeLineJoin;
/**
* Created by cir27 on 5/09/17.
*/
public class WindArrow extends Polyline {
public WindArrow(Paint fill) {
this.getPoints().addAll(
-10d, 15d,
0d, 25d,
0d, -25d,
0d, 25d,
10d, 15d
);
this.setStrokeLineCap(StrokeLineCap.ROUND);
this.setStroke(fill);
this.setStrokeWidth(5);
this.setStrokeLineJoin(StrokeLineJoin.ROUND);
}
}