3D arrow added for zoomed view. Shows relative direction to mark. #story[1299]

main
Joseph 8 years ago
parent 4cf9b67db8
commit bf6282c697

@ -2,16 +2,25 @@ package visualiser.Controllers;
import com.interactivemesh.jfx.importer.stl.StlMeshImporter; import com.interactivemesh.jfx.importer.stl.StlMeshImporter;
import javafx.animation.AnimationTimer; import javafx.animation.AnimationTimer;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML; 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.Pane;
import javafx.scene.layout.StackPane; import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial; import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Cylinder; import javafx.scene.shape.Cylinder;
import javafx.scene.shape.MeshView; import javafx.scene.shape.MeshView;
import javafx.scene.shape.Shape3D;
import javafx.scene.transform.Rotate;
import shared.model.Bearing; import shared.model.Bearing;
import shared.model.CompoundMark; import shared.model.CompoundMark;
import shared.model.GPSCoordinate; import shared.model.GPSCoordinate;
import visualiser.layout.Subject3D;
import visualiser.layout.View3D;
import visualiser.model.VisualiserBoat; import visualiser.model.VisualiserBoat;
import java.net.URL; import java.net.URL;
@ -20,13 +29,16 @@ import java.util.Observer;
public class NextMarkController { public class NextMarkController {
private @FXML StackPane arrowStackPane2d; private @FXML StackPane arrowStackPane2d;
private @FXML StackPane arrowStackPane3d;
private @FXML Pane pane2d; private @FXML Pane pane2d;
private @FXML Pane pane3d; private @FXML Pane pane3d;
private @FXML Label nextMarkLabel;
private VisualiserBoat boat; private VisualiserBoat boat;
public void initialiseArrowView(VisualiserBoat boat) { public void initialiseArrowView(VisualiserBoat boat) {
this.boat = boat; this.boat = boat;
this.nextMarkLabel.setVisible(false);
pane2d.setVisible(true); pane2d.setVisible(true);
pane3d.setVisible(false); pane3d.setVisible(false);
initialise2dArrowView(); initialise2dArrowView();
@ -46,13 +58,36 @@ public class NextMarkController {
} }
private void initialise3dArrowView() { private void initialise3dArrowView() {
ObservableList<Subject3D> viewSubjects = FXCollections.observableArrayList();
URL asset = this.getClass().getClassLoader().getResource("assets/arrow V1.0.4.stl"); URL asset = this.getClass().getClassLoader().getResource("assets/arrow V1.0.4.stl");
StlMeshImporter importer = new StlMeshImporter(); StlMeshImporter importer = new StlMeshImporter();
importer.read(asset); importer.read(asset);
MeshView arrow = new MeshView(importer.getImport()); MeshView arrow = new MeshView(importer.getImport());
PhongMaterial arrowMat = new PhongMaterial(Color.RED); PhongMaterial arrowMat = new PhongMaterial(Color.GREEN);
arrow.setMaterial(arrowMat); 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() { public void show2d() {
@ -64,4 +99,24 @@ public class NextMarkController {
pane2d.setVisible(false); pane2d.setVisible(false);
pane3d.setVisible(true); 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));
}
} }

@ -229,7 +229,6 @@ public class RaceViewController extends Controller {
try { try {
nextMarkController.initialiseArrowView(race.getVisualiserRaceState().getBoat(race.getVisualiserRaceState().getPlayerBoatID())); nextMarkController.initialiseArrowView(race.getVisualiserRaceState().getBoat(race.getVisualiserRaceState().getPlayerBoatID()));
System.out.println("hi");
} catch (BoatNotFoundException e) { } catch (BoatNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} }

@ -1,15 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.*?> <?import javafx.geometry.Insets?>
<?import javafx.geometry.*?> <?import javafx.scene.control.Label?>
<?import javafx.scene.control.*?> <?import javafx.scene.image.Image?>
<?import javafx.scene.shape.*?> <?import javafx.scene.image.ImageView?>
<?import javafx.scene.text.*?> <?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.image.*?> <?import javafx.scene.layout.GridPane?>
<?import java.lang.*?> <?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.shape.Circle?>
<?import javafx.scene.text.Font?>
<GridPane fx:id="arrowGridPane" alignment="TOP_CENTER" maxHeight="-Infinity" maxWidth="-Infinity" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.NextMarkController"> <GridPane fx:id="arrowGridPane" alignment="TOP_CENTER" maxHeight="-Infinity" maxWidth="-Infinity" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.NextMarkController">
<children> <children>
<Pane fx:id="pane2d" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="125.0" prefWidth="125.0"> <Pane fx:id="pane2d" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="125.0" prefWidth="125.0">
<children> <children>
@ -22,10 +25,10 @@
</ImageView> </ImageView>
</children> </children>
</StackPane> </StackPane>
<Circle fx:id="circle" fill="#1f93ff00" layoutX="63.0" layoutY="63.0" radius="60.0" stroke="BLACK" strokeType="INSIDE" strokeWidth="3.0" /> <Circle fx:id="circle" fill="#1f93ff00" layoutX="63.0" layoutY="63.0" radius="60.0" stroke="BLACK" strokeType="INSIDE" strokeWidth="3.0" visible="false" />
</children> </children>
</Pane> </Pane>
<Label text="Next Mark" GridPane.halignment="CENTER" GridPane.hgrow="NEVER" GridPane.rowIndex="1"> <Label fx:id="nextMarkLabel" text="Next Mark" GridPane.halignment="CENTER" GridPane.hgrow="NEVER" GridPane.rowIndex="1">
<font> <font>
<Font name="System Bold" size="16.0" /> <Font name="System Bold" size="16.0" />
</font> </font>
@ -33,7 +36,11 @@
<Insets /> <Insets />
</GridPane.margin> </GridPane.margin>
</Label> </Label>
<Pane fx:id="pane3d" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="125.0" prefWidth="125.0" /> <Pane fx:id="pane3d" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="125.0" prefWidth="125.0">
<children>
<StackPane fx:id="arrowStackPane3d" prefHeight="125.0" prefWidth="125.0" />
</children>
</Pane>
</children> </children>
<columnConstraints> <columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" /> <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />

Loading…
Cancel
Save