|
|
|
@ -5,22 +5,30 @@ import javafx.scene.canvas.GraphicsContext;
|
|
|
|
import javafx.scene.paint.Color;
|
|
|
|
import javafx.scene.paint.Color;
|
|
|
|
import javafx.scene.paint.Paint;
|
|
|
|
import javafx.scene.paint.Paint;
|
|
|
|
import javafx.scene.transform.Rotate;
|
|
|
|
import javafx.scene.transform.Rotate;
|
|
|
|
|
|
|
|
import seng302.GPSCoordinate;
|
|
|
|
import seng302.GraphCoordinate;
|
|
|
|
import seng302.GraphCoordinate;
|
|
|
|
import seng302.RaceMap;
|
|
|
|
import seng302.RaceMap;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Created by fwy13 on 17/03/17.
|
|
|
|
* Created by fwy13 on 17/03/17.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class ResizableRaceCanvas extends Canvas {
|
|
|
|
public class ResizableRaceCanvas extends Canvas {
|
|
|
|
GraphicsContext gc;
|
|
|
|
GraphicsContext gc;
|
|
|
|
RaceMap map;
|
|
|
|
RaceMap map;
|
|
|
|
|
|
|
|
private BoatInRace[] boats;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setBoats(BoatInRace[] boats) {
|
|
|
|
|
|
|
|
this.boats = boats;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ResizableRaceCanvas(RaceMap map) {
|
|
|
|
public ResizableRaceCanvas(RaceMap map) {
|
|
|
|
this.map = map;
|
|
|
|
this.map = map;
|
|
|
|
gc = this.getGraphicsContext2D();
|
|
|
|
gc = this.getGraphicsContext2D();
|
|
|
|
// Redraw canvas when size changes.
|
|
|
|
// Redraw canvas when size changes.
|
|
|
|
widthProperty().addListener(evt -> draw());
|
|
|
|
widthProperty().addListener(evt -> drawRaceMap());
|
|
|
|
heightProperty().addListener(evt -> draw());
|
|
|
|
heightProperty().addListener(evt -> drawRaceMap());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ResizableRaceCanvas(){
|
|
|
|
public ResizableRaceCanvas(){
|
|
|
|
@ -31,7 +39,7 @@ public class ResizableRaceCanvas extends Canvas {
|
|
|
|
this.map = map;
|
|
|
|
this.map = map;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void displayBoat(GraphCoordinate graphCoordinate, Paint paint){
|
|
|
|
public void displayMark(GraphCoordinate graphCoordinate, Paint paint){
|
|
|
|
gc.setFill(paint);
|
|
|
|
gc.setFill(paint);
|
|
|
|
gc.fillOval(graphCoordinate.getX(), graphCoordinate.getY(), 15, 15);
|
|
|
|
gc.fillOval(graphCoordinate.getX(), graphCoordinate.getY(), 15, 15);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -44,7 +52,6 @@ public class ResizableRaceCanvas extends Canvas {
|
|
|
|
gc.strokeLine(graphCoordinateA.getX(), graphCoordinateA.getY(), graphCoordinateB.getX(), graphCoordinateB.getY());
|
|
|
|
gc.strokeLine(graphCoordinateA.getX(), graphCoordinateA.getY(), graphCoordinateB.getX(), graphCoordinateB.getY());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void displayPoint(GraphCoordinate graphCoordinate, Paint paint){
|
|
|
|
public void displayPoint(GraphCoordinate graphCoordinate, Paint paint){
|
|
|
|
gc.setFill(paint);
|
|
|
|
gc.setFill(paint);
|
|
|
|
gc.fillOval(graphCoordinate.getX(), graphCoordinate.getY(), 10, 10);
|
|
|
|
gc.fillOval(graphCoordinate.getX(), graphCoordinate.getY(), 10, 10);
|
|
|
|
@ -65,20 +72,20 @@ public class ResizableRaceCanvas extends Canvas {
|
|
|
|
gc.setTransform(r.getMxx(), r.getMyx(), r.getMxy(), r.getMyy(), r.getTx(), r.getTy());
|
|
|
|
gc.setTransform(r.getMxx(), r.getMyx(), r.getMxy(), r.getMyy(), r.getTx(), r.getTy());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void draw() {
|
|
|
|
|
|
|
|
|
|
|
|
public void drawRaceMap() {
|
|
|
|
|
|
|
|
|
|
|
|
double width = getWidth();
|
|
|
|
double width = getWidth();
|
|
|
|
double height = getHeight();
|
|
|
|
double height = getHeight();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gc.clearRect(0, 0, width, height);
|
|
|
|
System.out.println("Race Map Canvas Width: "+ width + ", Height:" + height);
|
|
|
|
System.out.println("Race Map Canvas Width: "+ width + ", Height:" + height);
|
|
|
|
this.map = new RaceMap(32.320989, -64.863, 32.278, -64.821, (int)width, (int)height);
|
|
|
|
this.map = new RaceMap(32.320989, -64.863, 32.278, -64.821, (int)width, (int)height);
|
|
|
|
|
|
|
|
|
|
|
|
if (map == null){
|
|
|
|
if (map == null){
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
System.out.println("Drawing");
|
|
|
|
|
|
|
|
gc.clearRect(0, 0, width, height);
|
|
|
|
|
|
|
|
//boat
|
|
|
|
|
|
|
|
GraphCoordinate boat1coord = this.map.convertGPS(32.296577, -64.854304);
|
|
|
|
|
|
|
|
displayBoat(boat1coord, Color.AQUAMARINE);
|
|
|
|
|
|
|
|
//finish line
|
|
|
|
//finish line
|
|
|
|
gc.setLineWidth(2);
|
|
|
|
gc.setLineWidth(2);
|
|
|
|
GraphCoordinate finishLineCoord1 = this.map.convertGPS(32.317379, -64.839291);
|
|
|
|
GraphCoordinate finishLineCoord1 = this.map.convertGPS(32.317379, -64.839291);
|
|
|
|
@ -90,19 +97,33 @@ public class ResizableRaceCanvas extends Canvas {
|
|
|
|
GraphCoordinate southGate2 = this.map.convertGPS(32.280164, -64.847591);
|
|
|
|
GraphCoordinate southGate2 = this.map.convertGPS(32.280164, -64.847591);
|
|
|
|
GraphCoordinate northGate1 = this.map.convertGPS(32.309693, -64.835249);
|
|
|
|
GraphCoordinate northGate1 = this.map.convertGPS(32.309693, -64.835249);
|
|
|
|
GraphCoordinate northGate2 = this.map.convertGPS(32.308046, -64.831785);
|
|
|
|
GraphCoordinate northGate2 = this.map.convertGPS(32.308046, -64.831785);
|
|
|
|
displayBoat(boat1coord, Color.AQUAMARINE);
|
|
|
|
displayMark(markCoord, Color.GOLD);
|
|
|
|
displayBoat(markCoord, Color.GOLD);
|
|
|
|
|
|
|
|
displayLine(southGate1, southGate2, Color.DARKCYAN);
|
|
|
|
displayLine(southGate1, southGate2, Color.DARKCYAN);
|
|
|
|
displayLine(northGate1, northGate2, Color.DARKVIOLET);
|
|
|
|
displayLine(northGate1, northGate2, Color.DARKVIOLET);
|
|
|
|
//start line
|
|
|
|
//start line
|
|
|
|
GraphCoordinate startline1 = this.map.convertGPS(32.296577, -64.854304);
|
|
|
|
GraphCoordinate startline1 = this.map.convertGPS(32.296577, -64.854304);
|
|
|
|
GraphCoordinate startline2 = this.map.convertGPS(32.293771, -64.855242);
|
|
|
|
GraphCoordinate startline2 = this.map.convertGPS(32.293771, -64.855242);
|
|
|
|
|
|
|
|
|
|
|
|
displayLine(startline1, startline2, Color.GREEN);
|
|
|
|
displayLine(startline1, startline2, Color.GREEN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (boats != null) {
|
|
|
|
|
|
|
|
for (BoatInRace boat : boats) {
|
|
|
|
|
|
|
|
System.out.print("Drawing Boat At: " + boat.getCurrentPosition());
|
|
|
|
|
|
|
|
displayMark(this.map.convertGPS(boat.getCurrentPosition()), boat.getColour());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//display wind direction arrow - specify origin point and angle
|
|
|
|
//display wind direction arrow - specify origin point and angle
|
|
|
|
displayArrow(new GraphCoordinate(500, 20), 100);
|
|
|
|
displayArrow(new GraphCoordinate(500, 20), 100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void drawBoat(Color colour, GPSCoordinate gpsCoordinates) {
|
|
|
|
|
|
|
|
GraphCoordinate graphCoordinate = this.map.convertGPS(gpsCoordinates);
|
|
|
|
|
|
|
|
System.out.println("DrawingBoat" + gpsCoordinates.getLongitude());
|
|
|
|
|
|
|
|
displayPoint(graphCoordinate, colour);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean isResizable() {
|
|
|
|
public boolean isResizable() {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
|