|
|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package visualiser.model;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javafx.scene.image.Image;
|
|
|
|
|
import javafx.scene.paint.Color;
|
|
|
|
|
import javafx.scene.paint.LinearGradient;
|
|
|
|
|
import javafx.scene.paint.Paint;
|
|
|
|
|
@ -35,6 +36,10 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
|
|
|
|
*/
|
|
|
|
|
private RaceMap map;
|
|
|
|
|
|
|
|
|
|
private Image sailsRight = new Image("/images/sailsRight.png");
|
|
|
|
|
private Image sailsLeft = new Image("/images/sailsLeft.png");
|
|
|
|
|
private Image sailsLuff = new Image("/images/sailsLuff.gif", 25, 10, false, false);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The race we read data from and draw.
|
|
|
|
|
*/
|
|
|
|
|
@ -336,8 +341,6 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Draws a given boat on the canvas.
|
|
|
|
|
* @param boat The boat to draw.
|
|
|
|
|
@ -375,7 +378,9 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
|
|
|
|
gc.fillPolygon(x, y, x.length);
|
|
|
|
|
gc.restore();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (boat.getSourceID() == ThisBoat.getInstance().getSourceID()) {
|
|
|
|
|
drawSails(boat);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -413,6 +418,70 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Draws sails for a given boat on the canvas. Sail position is
|
|
|
|
|
* determined by the boats heading and the current wind direction
|
|
|
|
|
* according to the "points of sail".
|
|
|
|
|
* @param boat boat to display sails for
|
|
|
|
|
*/
|
|
|
|
|
private void drawSails(VisualiserBoat boat) {
|
|
|
|
|
GraphCoordinate boatPos =
|
|
|
|
|
this.map.convertGPS(boat.getPosition());
|
|
|
|
|
double xPos = boatPos.getX(); // x pos of sail (on boat)
|
|
|
|
|
double yPos = boatPos.getY() - 6; // y pos of sail (on boat)
|
|
|
|
|
double boatBearing = boat.getBearing().degrees();
|
|
|
|
|
double windDirection = 0; //visualiserRace.getWindDirection().degrees();
|
|
|
|
|
double sailRotateAngle = 0; // rotation for correct sail display
|
|
|
|
|
Image sailImage = null;
|
|
|
|
|
Boolean rightSail = true;
|
|
|
|
|
|
|
|
|
|
// Getting the correct Points of Sail
|
|
|
|
|
if (ThisBoat.getInstance().isSailsOut()){
|
|
|
|
|
// correct sail and sailRotateAngle start depending on wind+bearing
|
|
|
|
|
if ((windDirection + 180) > 360) {
|
|
|
|
|
if ((boatBearing < windDirection) &&
|
|
|
|
|
(boatBearing > windDirection - 180)) {
|
|
|
|
|
rightSail = false;
|
|
|
|
|
} else {
|
|
|
|
|
if (boatBearing < 180) {
|
|
|
|
|
sailRotateAngle = -180;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (!((boatBearing > windDirection) &&
|
|
|
|
|
(boatBearing < windDirection + 180))) {
|
|
|
|
|
rightSail = false;
|
|
|
|
|
if (boatBearing > 180) {
|
|
|
|
|
sailRotateAngle = -180;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rightSail) {
|
|
|
|
|
sailImage = sailsRight;
|
|
|
|
|
xPos -= 1; // right align sail to boat edge on canvas
|
|
|
|
|
} else {
|
|
|
|
|
sailImage = sailsLeft;
|
|
|
|
|
xPos -= 5; // left align sail to boat edge on canvas
|
|
|
|
|
}
|
|
|
|
|
sailRotateAngle += ((boatBearing + windDirection) * 0.5);
|
|
|
|
|
}
|
|
|
|
|
// Sails in = luffing sail
|
|
|
|
|
else {
|
|
|
|
|
xPos -= 6;
|
|
|
|
|
yPos += 1;
|
|
|
|
|
sailImage = sailsLuff;
|
|
|
|
|
sailRotateAngle = boatBearing + 90;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gc.save();
|
|
|
|
|
|
|
|
|
|
// rotate sails based on boats current heading
|
|
|
|
|
rotate(sailRotateAngle, boatPos.getX(), boatPos.getY());
|
|
|
|
|
gc.drawImage(sailImage, xPos, yPos);
|
|
|
|
|
|
|
|
|
|
gc.restore();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Draws the wake for a given boat.
|
|
|
|
|
@ -756,4 +825,4 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|