@ -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 ;
// remove when method is finished
sailRotateAngle = 0 ;
sailImage = null ;
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 ;
}
}
}
gc . save ( ) ;
if ( ThisBoat . getInstance ( ) . isSailsOut ( ) ) {
if ( boatBearing < 180 ) { // right half of points of sail
if ( rightSail ) {
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);
}
else { // left half of points of sail
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 ( ) ;
}