Boat sails now luff and stay when in the direction of the wind #story[1297]
This commit is contained in:
@@ -299,18 +299,47 @@ public class RaceViewController extends Controller {
|
||||
}
|
||||
// Position and add each boat to view
|
||||
for(VisualiserBoat boat: race.getVisualiserRaceState().getBoats()) {
|
||||
MeshView mesh;
|
||||
if(boat.getSourceID() == race.getVisualiserRaceState().getPlayerBoatID()) {
|
||||
/*if(boat.getSourceID() == race.getVisualiserRaceState().getPlayerBoatID()) {
|
||||
mesh = new MeshView(importer.getImport());
|
||||
} else {
|
||||
mesh = new MeshView(importerBurgerBoat.getImport());
|
||||
}
|
||||
}*/
|
||||
Shape3D mesh = Assets3D.getBoat();
|
||||
|
||||
PhongMaterial boatColorMat = new PhongMaterial(boat.getColor());
|
||||
mesh.setMaterial(boatColorMat);
|
||||
Subject3D boatModel = new Subject3D(mesh, boat.getSourceID());
|
||||
|
||||
viewSubjects.add(boatModel);
|
||||
|
||||
//add sail
|
||||
Sails3D sails3D = new Sails3D();
|
||||
Subject3D sailsSubject = new Subject3D(sails3D, 0);
|
||||
sails3D.setMaterial(boatColorMat);
|
||||
sailsSubject.setXRot(0d);
|
||||
|
||||
viewSubjects.add(sailsSubject);
|
||||
|
||||
AnimationTimer sailsFollowBoat = new AnimationTimer() {
|
||||
@Override
|
||||
public void handle(long now) {
|
||||
if (boat.isSailsOut()) {
|
||||
sailsSubject.setHeading(visualiserRace.getVisualiserRaceState().getWindDirection().degrees() + 90);
|
||||
if (sails3D.isLuffing()) {
|
||||
sails3D.stopLuffing();
|
||||
}
|
||||
} else {
|
||||
sailsSubject.setHeading(visualiserRace.getVisualiserRaceState().getWindDirection().degrees());
|
||||
if (!sails3D.isLuffing()){
|
||||
sails3D.startLuffing();
|
||||
}
|
||||
}
|
||||
sailsSubject.setX(gpsConverter.convertGPS(boat.getPosition()).getX());
|
||||
sailsSubject.setZ(gpsConverter.convertGPS(boat.getPosition()).getY());
|
||||
}
|
||||
};
|
||||
sailsFollowBoat.start();
|
||||
|
||||
// Track this boat's movement with the new subject
|
||||
AnimationTimer trackBoat = new AnimationTimer() {
|
||||
@Override
|
||||
|
||||
@@ -8,7 +8,8 @@ import javafx.scene.shape.MeshView;
|
||||
* Created by Gondr on 21/09/2017.
|
||||
*/
|
||||
public class Sails3D extends MeshView {
|
||||
int index = 0;
|
||||
private int index = 0;
|
||||
private boolean isLuffing = false;
|
||||
|
||||
public Sails3D() {
|
||||
setMesh(Assets3D.sails[0].getMesh());
|
||||
@@ -24,11 +25,16 @@ public class Sails3D extends MeshView {
|
||||
|
||||
public void startLuffing(){
|
||||
luff.start();
|
||||
isLuffing = true;
|
||||
}
|
||||
|
||||
public void stopLuffing(){
|
||||
luff.stop();
|
||||
isLuffing = false;
|
||||
setMesh(Assets3D.sails[0].getMesh());
|
||||
}
|
||||
|
||||
public boolean isLuffing() {
|
||||
return isLuffing;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user