Sails are displayed correctly for all wind and active boat directions.
- Figured out the different situations that can occur using accurate points of sail - Mathed out the rotation angle for each situation - Manual testing carried out by running simulations - Manual testing carried out using pen and paper #story[1098]
This commit is contained in:
@@ -324,38 +324,54 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
|||||||
double yPos = boatPos.getY() - 6; // y pos of sail (on boat)
|
double yPos = boatPos.getY() - 6; // y pos of sail (on boat)
|
||||||
double boatBearing = boat.getBearing().degrees();
|
double boatBearing = boat.getBearing().degrees();
|
||||||
double windDirection = visualiserRace.getWindDirection().degrees();
|
double windDirection = visualiserRace.getWindDirection().degrees();
|
||||||
windDirection = 0; // set to 0 for now - will be removed
|
double sailRotateAngle = 0; // rotation for correct sail display
|
||||||
double sailRotateAngle; // required rotation for correct sail display
|
Image sailImage = null;
|
||||||
Image sailImage;
|
Boolean rightSail = true;
|
||||||
|
|
||||||
// remove when method is finished
|
// Getting the correct Points of Sail
|
||||||
sailRotateAngle = 0;
|
if (ThisBoat.getInstance().isSailsOut()){
|
||||||
sailImage = null;
|
// correct sail and sailRotateAngle start depending on wind+bearing
|
||||||
|
if ((windDirection + 180) > 360) {
|
||||||
gc.save();
|
if ((boatBearing < windDirection) &&
|
||||||
if (ThisBoat.getInstance().isSailsOut()) {
|
(boatBearing > windDirection - 180)) {
|
||||||
if (boatBearing < 180) { // right half of points of sail
|
rightSail = false;
|
||||||
sailImage = sailsRight;
|
} else {
|
||||||
sailRotateAngle = boatBearing * 0.5; // math
|
if (boatBearing < 180) {
|
||||||
xPos -= 1; // right align to boat edge on canvas
|
sailRotateAngle = -180;
|
||||||
// System.out.println("right side -- boat: " + boatBearing +
|
}
|
||||||
// "|| rotate: " + sailRotateAngle);
|
}
|
||||||
|
} else {
|
||||||
|
if (!((boatBearing > windDirection) &&
|
||||||
|
(boatBearing < windDirection + 180))) {
|
||||||
|
rightSail = false;
|
||||||
|
if (boatBearing > 180) {
|
||||||
|
sailRotateAngle = -180;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else { // left half of points of sail
|
|
||||||
|
if (rightSail) {
|
||||||
|
sailImage = sailsRight;
|
||||||
|
xPos -= 1; // right align sail to boat edge on canvas
|
||||||
|
} else {
|
||||||
sailImage = sailsLeft;
|
sailImage = sailsLeft;
|
||||||
sailRotateAngle = -(360 - boatBearing) * 0.5; // math
|
xPos -= 5; // left align sail to boat edge on canvas
|
||||||
xPos -= 5; // left align to boat edge on canvas
|
|
||||||
// System.out.println("left side -- boat: " + boatBearing +
|
|
||||||
// "|| rotate: " + sailRotateAngle);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// TODO: display luffing sail
|
// TODO: display luffing sail
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sailRotateAngle += ((boatBearing + windDirection) * 0.5);
|
||||||
|
// System.out.println("boat: " + boatBearing + " || rotate: " +
|
||||||
|
// sailRotateAngle + " || wind angle: " + windDirection);
|
||||||
|
|
||||||
|
gc.save();
|
||||||
|
|
||||||
// rotate sails based on boats current heading
|
// rotate sails based on boats current heading
|
||||||
rotate(sailRotateAngle, boatPos.getX(), boatPos.getY());
|
rotate(sailRotateAngle, boatPos.getX(), boatPos.getY());
|
||||||
gc.drawImage(sailImage, xPos, yPos);
|
gc.drawImage(sailImage, xPos, yPos);
|
||||||
|
|
||||||
gc.restore();
|
gc.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user