Added 3D wind arrow and it also rotates #story[1306]
This commit is contained in:
@@ -61,6 +61,7 @@ public class RaceViewController extends Controller {
|
||||
private boolean isTutorial = false;
|
||||
private String keyToPress;
|
||||
private View3D view3D;
|
||||
private WindCompass windCompass;
|
||||
private ObservableList<Subject3D> viewSubjects;
|
||||
private ResizableRaceCanvas raceCanvas;
|
||||
private boolean mapToggle = true;
|
||||
@@ -268,6 +269,9 @@ public class RaceViewController extends Controller {
|
||||
view3D.addPointLight(pointLight);
|
||||
canvasBase.add(view3D, 0, 0);
|
||||
|
||||
windCompass = new WindCompass(view3D, this.raceState.windProperty());
|
||||
arrowPane.getChildren().add(windCompass);
|
||||
|
||||
// Set up projection from GPS to view
|
||||
RaceDataSource raceData = visualiserRace.getVisualiserRaceState().getRaceDataSource();
|
||||
final GPSConverter gpsConverter = new GPSConverter(raceData, 450, 450);
|
||||
|
||||
@@ -16,9 +16,12 @@ import java.net.URL;
|
||||
public class Assets3D {
|
||||
|
||||
public static MeshView[] sails;
|
||||
public static Subject3D windArrow;
|
||||
public static Subject3D compass;
|
||||
|
||||
public static void loadAssets(){
|
||||
loadSails();
|
||||
loadWindArrow();
|
||||
}
|
||||
|
||||
private static void loadSails(){
|
||||
@@ -39,15 +42,26 @@ public class Assets3D {
|
||||
}
|
||||
|
||||
public static Shape3D getBoat(){
|
||||
X3dModelImporter x3dModelImporter = new X3dModelImporter();
|
||||
String path = "assets/V1.3 Complete Boat without Sail and Rotated.x3d";
|
||||
return loadX3d(path);
|
||||
}
|
||||
|
||||
private static void loadWindArrow(){
|
||||
String compassPath = "assets/wind_compass.x3d";
|
||||
compass = new Annotation3D(loadX3d(compassPath));
|
||||
String arrowPath = "assets/wind_arrow.x3d";
|
||||
windArrow = new Annotation3D(loadX3d(arrowPath));
|
||||
}
|
||||
|
||||
private static Shape3D loadX3d(String path){
|
||||
X3dModelImporter x3dModelImporter = new X3dModelImporter();
|
||||
URL asset = Assets3D.class.getClassLoader().getResource(path);
|
||||
x3dModelImporter.read(asset);
|
||||
if (x3dModelImporter.getImport().length > 0) {
|
||||
//if (x3dModelImporter.getImport()[0] instanceof MeshView) {
|
||||
Group g = (Group)((Group)((Group) x3dModelImporter.getImport()[0]).getChildren().get(0)).getChildren().get(0);
|
||||
Shape3D boat = (Shape3D)g.getChildren().get(0);
|
||||
return boat;
|
||||
Shape3D shape = (Shape3D)g.getChildren().get(0);
|
||||
return shape;
|
||||
/*} else {
|
||||
System.err.println("Boat is not a Mesh View 0.0");
|
||||
}*/
|
||||
|
||||
@@ -288,6 +288,10 @@ public class View3D extends Pane {
|
||||
this.yaw.setAngle(yaw);
|
||||
}
|
||||
|
||||
public double getYaw(){
|
||||
return this.yaw.getAngle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set elevation of camera
|
||||
* @param pitch in degrees
|
||||
@@ -296,6 +300,10 @@ public class View3D extends Pane {
|
||||
this.pitch.setAngle(-pitch);
|
||||
}
|
||||
|
||||
public double getPitch(){
|
||||
return this.pitch.getAngle();
|
||||
}
|
||||
|
||||
public void addAmbientLight(AmbientLight ambientLight) {
|
||||
this.world.getChildren().add(ambientLight);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package visualiser.layout;
|
||||
|
||||
import javafx.animation.AnimationTimer;
|
||||
import javafx.beans.property.Property;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import shared.model.Wind;
|
||||
|
||||
/**
|
||||
* Created by Gondr on 25/09/2017.
|
||||
*/
|
||||
public class WindCompass extends View3D {
|
||||
Subject3D compass;
|
||||
Subject3D windArrow;
|
||||
View3D view3D;
|
||||
Property<Wind> wind;
|
||||
|
||||
AnimationTimer followView3D = new AnimationTimer() {
|
||||
@Override
|
||||
public void handle(long now) {
|
||||
setYaw(180+ view3D.getYaw());
|
||||
setPitch(30 - view3D.getPitch());
|
||||
windArrow.setHeading(wind.getValue().getWindDirection().degrees());
|
||||
}
|
||||
};
|
||||
|
||||
public WindCompass(View3D view3D, Property<Wind> wind){
|
||||
super();
|
||||
this.wind = wind;
|
||||
this.view3D = view3D;
|
||||
this.followView3D.start();
|
||||
ObservableList<Subject3D> subjects = FXCollections.observableArrayList();
|
||||
this.setItems(subjects);
|
||||
compass = Assets3D.compass;
|
||||
windArrow = Assets3D.windArrow;
|
||||
subjects.addAll(compass, windArrow);
|
||||
this.setDistance(30);
|
||||
this.setPitch(90);
|
||||
this.setYaw(180);
|
||||
}
|
||||
|
||||
public void setHeading(double heading){
|
||||
windArrow.setHeading(heading);
|
||||
}
|
||||
|
||||
public void setCompassPitch(double pitch){
|
||||
setPitch(90d + pitch);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user