Implemented Finish Line
-Altered others drawing to utilise drawLine in RaceMap -Added Finish Line -Rescaled Canvas (To be fixed in the future). #story[11]
This commit is contained in:
@@ -4,8 +4,10 @@ import javafx.fxml.FXML;
|
|||||||
import javafx.scene.canvas.Canvas;
|
import javafx.scene.canvas.Canvas;
|
||||||
import javafx.scene.canvas.GraphicsContext;
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
import javafx.scene.control.TableView;
|
import javafx.scene.control.TableView;
|
||||||
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.paint.Paint;
|
import javafx.scene.paint.Paint;
|
||||||
|
import javafx.scene.shape.Line;
|
||||||
import seng302.Coordinate;
|
import seng302.Coordinate;
|
||||||
import seng302.RaceMap;
|
import seng302.RaceMap;
|
||||||
|
|
||||||
@@ -20,6 +22,8 @@ public class RaceController extends Controller{
|
|||||||
Canvas raceMap;
|
Canvas raceMap;
|
||||||
@FXML
|
@FXML
|
||||||
TableView boatInfoTable;
|
TableView boatInfoTable;
|
||||||
|
@FXML
|
||||||
|
AnchorPane canvasBase;
|
||||||
|
|
||||||
private GraphicsContext gc;
|
private GraphicsContext gc;
|
||||||
private RaceMap map;
|
private RaceMap map;
|
||||||
@@ -29,22 +33,49 @@ public class RaceController extends Controller{
|
|||||||
gc.fillOval(coordinate.getX(), coordinate.getY(), 15, 15);
|
gc.fillOval(coordinate.getX(), coordinate.getY(), 15, 15);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void displayLine(Coordinate coordinateA, Coordinate coordinateB, Paint paint){
|
||||||
|
gc.setStroke(paint);
|
||||||
|
gc.setFill(paint);
|
||||||
|
gc.fillOval(coordinateA.getX() - 3, coordinateA.getY() - 3, 6, 6);
|
||||||
|
gc.fillOval(coordinateB.getX() - 3, coordinateB.getY() - 3, 6, 6);
|
||||||
|
gc.strokeLine(coordinateA.getX(), coordinateA.getY(), coordinateB.getX(), coordinateB.getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void displayPoint(Coordinate coordinate, Paint paint){
|
||||||
|
gc.setFill(paint);
|
||||||
|
gc.fillOval(coordinate.getX(), coordinate.getY(), 10, 10);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {/*
|
||||||
|
raceMap.widthProperty().bind(canvasBase.widthProperty());
|
||||||
|
raceMap.heightProperty().bind(canvasBase.heightProperty());*/
|
||||||
this.gc = raceMap.getGraphicsContext2D();
|
this.gc = raceMap.getGraphicsContext2D();
|
||||||
this.map = new RaceMap(32.321989, -64.866142, 32.273089, -64.814987, (int)raceMap.getWidth(), (int)raceMap.getHeight());
|
this.map = new RaceMap(32.321989, -64.8553, 32.246, -64.831, (int)raceMap.getWidth(), (int)raceMap.getHeight());
|
||||||
|
//boat
|
||||||
Coordinate boat1coord = this.map.convertGPS(32.296577, -64.854304);
|
Coordinate boat1coord = this.map.convertGPS(32.296577, -64.854304);
|
||||||
displayBoat(boat1coord, Color.AQUAMARINE);
|
displayBoat(boat1coord, Color.AQUAMARINE);
|
||||||
|
//finish line
|
||||||
gc.setStroke(Color.DARKRED);
|
|
||||||
gc.setLineWidth(2);
|
gc.setLineWidth(2);
|
||||||
Coordinate finishLineCoord1 = this.map.convertGPS(32.317379, -64.839291);
|
Coordinate finishLineCoord1 = this.map.convertGPS(32.317379, -64.839291);
|
||||||
Coordinate finishLineCoord2 = this.map.convertGPS(32.317257, -64.836260);
|
Coordinate finishLineCoord2 = this.map.convertGPS(32.317257, -64.836260);
|
||||||
gc.strokeLine(finishLineCoord1.getX(), finishLineCoord1.getY(), finishLineCoord2.getX(), finishLineCoord2.getY());
|
displayLine(finishLineCoord1, finishLineCoord2, Color.DARKRED);
|
||||||
gc.strokeRect(finishLineCoord1.getX() - 1, finishLineCoord1.getY() - 1, 3, 3);
|
//marks
|
||||||
gc.strokeRect(finishLineCoord2.getX() - 1, finishLineCoord2.getY() - 1, 3, 3);
|
Coordinate markCoord = this.map.convertGPS(32.293039, -64.843983);
|
||||||
|
Coordinate southGate1 = this.map.convertGPS(32.284680, -64.850045);
|
||||||
|
Coordinate southGate2 = this.map.convertGPS(32.280164, -64.847591);
|
||||||
|
Coordinate northGate1 = this.map.convertGPS(32.309693, -64.835249);
|
||||||
|
Coordinate northGate2 = this.map.convertGPS(32.308046, -64.831785);
|
||||||
|
displayBoat(boat1coord, Color.AQUAMARINE);
|
||||||
|
displayBoat(markCoord, Color.GOLD);
|
||||||
|
displayLine(southGate1, southGate2, Color.DARKCYAN);
|
||||||
|
displayLine(northGate1, northGate2, Color.DARKVIOLET);
|
||||||
|
//start line
|
||||||
|
Coordinate startline1 = this.map.convertGPS(32.296577, -64.854304);
|
||||||
|
Coordinate startline2 = this.map.convertGPS(32.293771, -64.855242);
|
||||||
|
displayLine(startline1, startline2, Color.GREEN);
|
||||||
|
|
||||||
|
displayPoint(this.map.convertGPS(32.293771, -64.855242), Color.BLACK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,6 @@ public class RaceMap {
|
|||||||
* @see seng302.Coordinate
|
* @see seng302.Coordinate
|
||||||
*/
|
*/
|
||||||
public Coordinate convertGPS(double lat, double lon) {
|
public Coordinate convertGPS(double lat, double lon) {
|
||||||
return new Coordinate((int) (width * (lat - x1) / (x2 - x1)), (int) (height * (lon - y1) / (y2 - y1)));
|
return new Coordinate((int) (width * (lat - x1) / (x2 - x1)), (int) (height - (height * (lon - y1) / (y2 - y1))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,14 +5,13 @@
|
|||||||
<?import java.lang.*?>
|
<?import java.lang.*?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
|
|
||||||
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.Controllers.RaceController">
|
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.Controllers.RaceController">
|
||||||
<children>
|
<children>
|
||||||
<SplitPane fx:id="racePane" dividerPositions="0.75" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
<SplitPane fx:id="racePane" dividerPositions="0.75" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
<items>
|
<items>
|
||||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
|
<AnchorPane fx:id="canvasBase" minHeight="0.0" minWidth="0.0">
|
||||||
<children>
|
<children>
|
||||||
<Canvas fx:id="raceMap" height="400.0" width="446.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
<Canvas fx:id="raceMap" height="600.0" width="600.0" />
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
|
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
|
||||||
|
|||||||
Reference in New Issue
Block a user