|
|
|
|
@ -2,16 +2,25 @@ package visualiser.Controllers;
|
|
|
|
|
|
|
|
|
|
import com.interactivemesh.jfx.importer.stl.StlMeshImporter;
|
|
|
|
|
import javafx.animation.AnimationTimer;
|
|
|
|
|
import javafx.collections.FXCollections;
|
|
|
|
|
import javafx.collections.ObservableList;
|
|
|
|
|
import javafx.fxml.FXML;
|
|
|
|
|
import javafx.geometry.Point3D;
|
|
|
|
|
import javafx.scene.AmbientLight;
|
|
|
|
|
import javafx.scene.control.Label;
|
|
|
|
|
import javafx.scene.layout.Pane;
|
|
|
|
|
import javafx.scene.layout.StackPane;
|
|
|
|
|
import javafx.scene.paint.Color;
|
|
|
|
|
import javafx.scene.paint.PhongMaterial;
|
|
|
|
|
import javafx.scene.shape.Cylinder;
|
|
|
|
|
import javafx.scene.shape.MeshView;
|
|
|
|
|
import javafx.scene.shape.Shape3D;
|
|
|
|
|
import javafx.scene.transform.Rotate;
|
|
|
|
|
import shared.model.Bearing;
|
|
|
|
|
import shared.model.CompoundMark;
|
|
|
|
|
import shared.model.GPSCoordinate;
|
|
|
|
|
import visualiser.layout.Subject3D;
|
|
|
|
|
import visualiser.layout.View3D;
|
|
|
|
|
import visualiser.model.VisualiserBoat;
|
|
|
|
|
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
@ -20,13 +29,16 @@ import java.util.Observer;
|
|
|
|
|
|
|
|
|
|
public class NextMarkController {
|
|
|
|
|
private @FXML StackPane arrowStackPane2d;
|
|
|
|
|
private @FXML StackPane arrowStackPane3d;
|
|
|
|
|
private @FXML Pane pane2d;
|
|
|
|
|
private @FXML Pane pane3d;
|
|
|
|
|
private @FXML Label nextMarkLabel;
|
|
|
|
|
|
|
|
|
|
private VisualiserBoat boat;
|
|
|
|
|
|
|
|
|
|
public void initialiseArrowView(VisualiserBoat boat) {
|
|
|
|
|
this.boat = boat;
|
|
|
|
|
this.nextMarkLabel.setVisible(false);
|
|
|
|
|
pane2d.setVisible(true);
|
|
|
|
|
pane3d.setVisible(false);
|
|
|
|
|
initialise2dArrowView();
|
|
|
|
|
@ -46,13 +58,36 @@ public class NextMarkController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initialise3dArrowView() {
|
|
|
|
|
ObservableList<Subject3D> viewSubjects = FXCollections.observableArrayList();
|
|
|
|
|
URL asset = this.getClass().getClassLoader().getResource("assets/arrow V1.0.4.stl");
|
|
|
|
|
StlMeshImporter importer = new StlMeshImporter();
|
|
|
|
|
importer.read(asset);
|
|
|
|
|
|
|
|
|
|
MeshView arrow = new MeshView(importer.getImport());
|
|
|
|
|
PhongMaterial arrowMat = new PhongMaterial(Color.RED);
|
|
|
|
|
PhongMaterial arrowMat = new PhongMaterial(Color.GREEN);
|
|
|
|
|
arrow.setMaterial(arrowMat);
|
|
|
|
|
|
|
|
|
|
AmbientLight ambientLight = new AmbientLight(Color.web("#777777"));
|
|
|
|
|
ambientLight.setLightOn(true);
|
|
|
|
|
|
|
|
|
|
arrow.setScaleX(50);
|
|
|
|
|
arrow.setScaleY(50);
|
|
|
|
|
arrow.setScaleZ(300);
|
|
|
|
|
arrow.setRotationAxis(new Point3D(1,0,0));
|
|
|
|
|
|
|
|
|
|
arrowStackPane3d.getChildren().add(arrow);
|
|
|
|
|
arrowStackPane3d.getChildren().add(ambientLight);
|
|
|
|
|
|
|
|
|
|
AnimationTimer arrow3d = new AnimationTimer() {
|
|
|
|
|
@Override
|
|
|
|
|
public void handle(long now) {
|
|
|
|
|
arrow.getTransforms().clear();
|
|
|
|
|
double zRotation = calculateZRotate();
|
|
|
|
|
arrow.setRotate(calculateXRotate(zRotation));
|
|
|
|
|
arrow.getTransforms().add(new Rotate(zRotation, new Point3D(0, 0, 1)));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
arrow3d.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void show2d() {
|
|
|
|
|
@ -64,4 +99,24 @@ public class NextMarkController {
|
|
|
|
|
pane2d.setVisible(false);
|
|
|
|
|
pane3d.setVisible(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private double calculateZRotate() {
|
|
|
|
|
CompoundMark target = boat.getCurrentLeg().getEndCompoundMark();
|
|
|
|
|
Bearing headingToMark = GPSCoordinate.calculateBearing(boat.getPosition(), target.getAverageGPSCoordinate());
|
|
|
|
|
return -headingToMark.degrees() + boat.getBearing().degrees();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private double calculateXRotate(double zRotation) {
|
|
|
|
|
if (zRotation > 360) {
|
|
|
|
|
zRotation -=360;
|
|
|
|
|
} else if (zRotation < 0) {
|
|
|
|
|
zRotation += 360;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (zRotation > 180) {
|
|
|
|
|
zRotation = 360 - zRotation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 90 - 20 * Math.cos(Math.toRadians(zRotation));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|