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]
main
Jessica Syder 8 years ago
parent ace1252c1d
commit ce973fecfe

@ -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) {
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;
}
}
}
gc.save(); if (rightSail) {
if (ThisBoat.getInstance().isSailsOut()) {
if (boatBearing < 180) { // right half of points of sail
sailImage = sailsRight; sailImage = sailsRight;
sailRotateAngle = boatBearing * 0.5; // math xPos -= 1; // right align sail to boat edge on canvas
xPos -= 1; // right align to boat edge on canvas } else {
// System.out.println("right side -- boat: " + boatBearing +
// "|| rotate: " + sailRotateAngle);
}
else { // left half of points of sail
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();
} }

Loading…
Cancel
Save