Recovered stable rotation of the player's boat
- Uses AnimationTimer rather than listeners - Reduced pre-start time to speed up testing #story[1261]
This commit is contained in:
@@ -36,15 +36,15 @@ public class Constants {
|
||||
public static final int RaceTimeScale = 2;//10;
|
||||
|
||||
/**
|
||||
* The race pre-start time, in milliseconds. 3 minutes.
|
||||
* The race pre-start time, in milliseconds. 3 minutes (30 seconds for development).
|
||||
*/
|
||||
public static final long RacePreStartTime = 3 * 60 * 1000;
|
||||
public static final long RacePreStartTime = 30 * 1000;
|
||||
|
||||
|
||||
/**
|
||||
* The race preparatory time, in milliseconds. 1 minute.
|
||||
*/
|
||||
public static final long RacePreparatoryTime = 1 * 60 * 1000;
|
||||
public static final long RacePreparatoryTime = 60 * 1000;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -16,9 +16,13 @@ import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.shape.MeshView;
|
||||
import javafx.scene.shape.Sphere;
|
||||
import javafx.util.Callback;
|
||||
import network.Messages.Enums.RaceStatusEnum;
|
||||
import shared.exceptions.BoatNotFoundException;
|
||||
import shared.exceptions.MarkNotFoundException;
|
||||
import shared.model.Leg;
|
||||
import shared.model.Mark;
|
||||
import visualiser.app.App;
|
||||
import visualiser.gameController.ControllerClient;
|
||||
import visualiser.gameController.Keys.ControlKey;
|
||||
@@ -93,7 +97,6 @@ public class RaceController extends Controller {
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
// KeyFactory keyFactory = KeyFactory.getFactory();
|
||||
infoTableShow = true;
|
||||
|
||||
// Initialise keyboard handler
|
||||
@@ -172,37 +175,37 @@ public class RaceController extends Controller {
|
||||
}
|
||||
|
||||
private void initialiseView3D(VisualiserRaceEvent race) {
|
||||
ObservableList<Subject3D> subjects = FXCollections.observableArrayList();
|
||||
|
||||
view3D = new View3D();
|
||||
view3D.setItems(subjects);
|
||||
canvasBase.getChildren().add(0, view3D);
|
||||
|
||||
URL asset = HostController.class.getClassLoader().getResource("assets/V1.2 Complete Boat.stl");
|
||||
|
||||
StlMeshImporter importer = new StlMeshImporter();
|
||||
importer.read(asset);
|
||||
|
||||
List<VisualiserBoat> boats = race.getVisualiserRaceState().getBoats();
|
||||
viewSubjects = FXCollections.observableArrayList();
|
||||
|
||||
//Create View3D
|
||||
view3D = new View3D();
|
||||
view3D.setItems(viewSubjects);
|
||||
for(VisualiserBoat boat: boats) {
|
||||
System.out.println("Adding " + boat.getCountry());
|
||||
Subject3D subject = new Subject3D(new MeshView(importer.getImport()));
|
||||
viewSubjects.add(subject);
|
||||
view3D.setPivot(subject); // Filthy hack makes last added boat the pivot
|
||||
|
||||
boat.positionProperty().addListener((o, prev, curr) -> {
|
||||
System.out.println(boat.getCountry() + " is at " + curr.toString());
|
||||
});
|
||||
subjects.add(subject);
|
||||
|
||||
boat.bearingProperty().addListener((o, prev, curr) -> {
|
||||
subject.setHeading(curr.degrees());
|
||||
});
|
||||
}
|
||||
|
||||
// Display View3D
|
||||
view3D.setVisible(true);
|
||||
view3D.setPivot(subject);
|
||||
view3D.setDistance(50);
|
||||
view3D.setYaw(45);
|
||||
view3D.setPitch(20);
|
||||
canvasBase.getChildren().add(0, view3D);
|
||||
|
||||
try {
|
||||
VisualiserBoat boat = race.getVisualiserRaceState().getBoat(race.getVisualiserRaceState().getPlayerBoatID());
|
||||
AnimationTimer rotate = new AnimationTimer() {
|
||||
@Override
|
||||
public void handle(long now) {
|
||||
subject.setHeading(boat.getBearing().degrees());
|
||||
}
|
||||
};
|
||||
rotate.start();
|
||||
} catch(BoatNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -39,34 +39,34 @@ public class Subject3D {
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return this.position.getX();
|
||||
return position.getTx();
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return this.position.getY();
|
||||
return position.getTy();
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return this.position.getZ();
|
||||
return position.getTz();
|
||||
}
|
||||
|
||||
public void setX(double x) {
|
||||
this.position.setX(x);
|
||||
position.setX(x);
|
||||
}
|
||||
|
||||
public void setY(double y) {
|
||||
this.position.setY(y);
|
||||
position.setY(y);
|
||||
}
|
||||
|
||||
public void setZ(double z) {
|
||||
this.position.setZ(z);
|
||||
position.setZ(z);
|
||||
}
|
||||
|
||||
public double getHeading() {
|
||||
return this.heading.getAngle();
|
||||
return heading.getAngle();
|
||||
}
|
||||
|
||||
public void setHeading(double angle) {
|
||||
this.heading.setAngle(angle);
|
||||
heading.setAngle(angle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,8 @@ public class View3D extends Pane {
|
||||
*/
|
||||
private Rotate pitch;
|
||||
|
||||
private PerspectiveCamera camera;
|
||||
|
||||
/**
|
||||
* Default constructor for View3D. Sets up Scene and PerspectiveCamera.
|
||||
*/
|
||||
@@ -86,6 +88,7 @@ public class View3D extends Pane {
|
||||
pitch = new Rotate(0, Rotate.X_AXIS);
|
||||
camera.getTransforms().addAll(pivot, yaw, pitch, distance);
|
||||
|
||||
this.camera = camera;
|
||||
return camera;
|
||||
}
|
||||
|
||||
@@ -142,4 +145,8 @@ public class View3D extends Pane {
|
||||
public void setPitch(double pitch) {
|
||||
this.pitch.setAngle(-pitch);
|
||||
}
|
||||
|
||||
public PerspectiveCamera getCamera() {
|
||||
return camera;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user