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 boatBearing = boat.getBearing().degrees();
|
||||
double windDirection = visualiserRace.getWindDirection().degrees();
|
||||
windDirection = 0; // set to 0 for now - will be removed
|
||||
double sailRotateAngle; // required rotation for correct sail display
|
||||
Image sailImage;
|
||||
double sailRotateAngle = 0; // rotation for correct sail display
|
||||
Image sailImage = null;
|
||||
Boolean rightSail = true;
|
||||
|
||||
// remove when method is finished
|
||||
sailRotateAngle = 0;
|
||||
sailImage = null;
|
||||
|
||||
gc.save();
|
||||
if (ThisBoat.getInstance().isSailsOut()) {
|
||||
if (boatBearing < 180) { // right half of points of sail
|
||||
sailImage = sailsRight;
|
||||
sailRotateAngle = boatBearing * 0.5; // math
|
||||
xPos -= 1; // right align to boat edge on canvas
|
||||
// System.out.println("right side -- boat: " + boatBearing +
|
||||
// "|| rotate: " + sailRotateAngle);
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
else { // left half of points of sail
|
||||
|
||||
if (rightSail) {
|
||||
sailImage = sailsRight;
|
||||
xPos -= 1; // right align sail to boat edge on canvas
|
||||
} else {
|
||||
sailImage = sailsLeft;
|
||||
sailRotateAngle = -(360 - boatBearing) * 0.5; // math
|
||||
xPos -= 5; // left align to boat edge on canvas
|
||||
// System.out.println("left side -- boat: " + boatBearing +
|
||||
// "|| rotate: " + sailRotateAngle);
|
||||
xPos -= 5; // left align sail to boat edge on canvas
|
||||
}
|
||||
}
|
||||
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(sailRotateAngle, boatPos.getX(), boatPos.getY());
|
||||
gc.drawImage(sailImage, xPos, yPos);
|
||||
|
||||
gc.restore();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user