Fixed arrow Direction, and Canvas
- Canvas will not longer not fill the entire screen - Canvas will redraw when resized larger - Arrow Rotation no longer rotates the entire map. #fix
This commit is contained in:
@@ -1,20 +1,32 @@
|
||||
package seng302.Controllers;
|
||||
|
||||
|
||||
import javafx.beans.property.ReadOnlyObjectWrapper;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.canvas.Canvas;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.control.cell.PropertyValueFactory;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.paint.Paint;
|
||||
import javafx.util.Callback;
|
||||
import seng302.GPSCoordinate;
|
||||
import javafx.scene.transform.Rotate;
|
||||
import seng302.GraphCoordinate;
|
||||
import seng302.Model.ResizableRaceCanvas;
|
||||
import seng302.Model.*;
|
||||
import seng302.RaceMap;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Observable;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
@@ -27,10 +39,29 @@ public class RaceController extends Controller{
|
||||
AnchorPane canvasBase;
|
||||
@FXML
|
||||
ResizableRaceCanvas raceMap;
|
||||
@FXML
|
||||
TableColumn<BoatInRace, String> boatPlacingColumn;
|
||||
@FXML
|
||||
TableColumn<BoatInRace, String> boatTeamColumn;
|
||||
@FXML
|
||||
TableColumn<BoatInRace, String> boatMarkColumn;
|
||||
|
||||
private GraphicsContext gc;
|
||||
private RaceMap map;
|
||||
|
||||
public void updateInfoTable(Race race) {
|
||||
boatInfoTable.setItems(FXCollections.observableArrayList(race.getFinishingBoats()));
|
||||
|
||||
boatTeamColumn.setCellValueFactory(new PropertyValueFactory<BoatInRace,String>("Name"));
|
||||
boatMarkColumn.setCellValueFactory(new PropertyValueFactory<BoatInRace, String>("CurrentLeg"));
|
||||
boatPlacingColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<BoatInRace, String>, ObservableValue<String>>() {
|
||||
@Override
|
||||
public ObservableValue<String> call(TableColumn.CellDataFeatures<BoatInRace, String> table) {
|
||||
return new ReadOnlyObjectWrapper(boatInfoTable.getItems().indexOf(table.getValue()) + 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
raceMap = new ResizableRaceCanvas();
|
||||
@@ -38,5 +69,16 @@ public class RaceController extends Controller{
|
||||
raceMap.heightProperty().bind(canvasBase.heightProperty());
|
||||
raceMap.draw();
|
||||
canvasBase.getChildren().add(raceMap);
|
||||
|
||||
BoatInRace boat = new BoatInRace("NZ", 10000);
|
||||
BoatInRace[] boats = new BoatInRace[] {boat};
|
||||
Leg leg1 = new Leg("first leg", 1, new GPSCoordinate(0, 0), new GPSCoordinate(1, 1), 0);
|
||||
Leg[] legs = new Leg[] {leg1};
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, this);
|
||||
|
||||
(new Thread(race)).start();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -27,6 +27,10 @@ public class Boat {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return returns the speed of the boat.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package seng302.Model;
|
||||
|
||||
import seng302.Controllers.RaceController;
|
||||
import seng302.GPSCoordinate;
|
||||
import seng302.GraphCoordinate;
|
||||
|
||||
@@ -17,6 +18,10 @@ public class ConstantVelocityRace extends Race {
|
||||
* @see Leg
|
||||
*/
|
||||
|
||||
public ConstantVelocityRace(BoatInRace[] startingBoats, Leg[] marks, RaceController controller) {
|
||||
super(startingBoats, marks, controller);
|
||||
}
|
||||
|
||||
public ConstantVelocityRace(BoatInRace[] startingBoats, Leg[] marks) {
|
||||
super(startingBoats, marks);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,14 @@ public class Leg {
|
||||
this.legNumber = number;
|
||||
}
|
||||
|
||||
public Leg(String name) {
|
||||
this.name = name;
|
||||
this.distance = 0;
|
||||
this.startGPSCoordinate = new GPSCoordinate(0,0);
|
||||
this.endGPSCoordinate = new GPSCoordinate(0,0);
|
||||
this.legNumber = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the name of the Leg
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
package seng302.Model;
|
||||
|
||||
|
||||
import seng302.Controllers.RaceController;
|
||||
import seng302.GPSCoordinate;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Parent class for races
|
||||
* Created by fwy13 on 3/03/17.
|
||||
*/
|
||||
public abstract class Race {
|
||||
public abstract class Race implements Runnable {
|
||||
protected BoatInRace[] startingBoats;
|
||||
protected ArrayList<BoatInRace> finishingBoats = new ArrayList<>();
|
||||
protected Leg[] legs;
|
||||
protected RaceController controller;
|
||||
|
||||
private int SLEEP_TIME = 1000; //time in milliseconds to pause in a paced loop
|
||||
|
||||
@@ -19,16 +23,22 @@ public abstract class Race {
|
||||
* @param boats Takes in an array of boats that are participating in the race.
|
||||
* @param marks Number of marks in order that the boats pass in order to complete the race.
|
||||
*/
|
||||
public Race(BoatInRace[] boats, Leg[] marks, RaceController controller) {
|
||||
this.startingBoats = boats;
|
||||
this.legs = marks;
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
public Race(BoatInRace[] boats, Leg[] marks) {
|
||||
this.startingBoats = boats;
|
||||
this.legs = marks;
|
||||
|
||||
}
|
||||
|
||||
public void run() {
|
||||
long time = System.currentTimeMillis();
|
||||
preRace();
|
||||
simulateRace();
|
||||
|
||||
if(controller != null) controller.updateInfoTable(this);
|
||||
}
|
||||
|
||||
private void preRace() {
|
||||
@@ -79,6 +89,7 @@ public abstract class Race {
|
||||
if (boat.getCurrentLeg().getLegNumber() == legs.length - 1) {
|
||||
//boat has finished
|
||||
boat.setTimeFinished(timeElapsed);
|
||||
boat.setCurrentLeg(new Leg("Finish"));
|
||||
finishingBoats.add(boat);
|
||||
} else {
|
||||
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance());
|
||||
@@ -90,6 +101,11 @@ public abstract class Race {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<BoatInRace> getFinishingBoats() {
|
||||
return finishingBoats;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is a function that generates the Race and populates the events list.
|
||||
* Is automatically called by the initialiser function, so that simulateRace() does not return an empty race.
|
||||
|
||||
@@ -50,14 +50,16 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
gc.fillOval(graphCoordinate.getX(), graphCoordinate.getY(), 10, 10);
|
||||
}
|
||||
|
||||
public void displayArrow(GraphCoordinate coordinate, Paint paint){
|
||||
rotate(10, 30,30);
|
||||
gc.fillPolygon(new double[]{0, 6, 12, 8, 8, 4, 4},
|
||||
new double[]{15, 0, 15, 15, 40, 40, 15},
|
||||
public void displayArrow(GraphCoordinate coordinate, int angle){
|
||||
gc.save();
|
||||
rotate(angle, coordinate.getX(),coordinate.getY());
|
||||
gc.fillPolygon(new double[]{coordinate.getX()-12, coordinate.getX()-6, coordinate.getX(), coordinate.getX()-4, coordinate.getX()-4, coordinate.getX()-8, coordinate.getX()-8},
|
||||
new double[]{coordinate.getY()-5, coordinate.getY()-20, coordinate.getY()-5, coordinate.getY()-5, coordinate.getY()+20, coordinate.getY()+20, coordinate.getY()-5},
|
||||
7);
|
||||
gc.restore();
|
||||
}
|
||||
|
||||
|
||||
private void rotate(double angle, double px, double py) {
|
||||
Rotate r = new Rotate(angle, px, py);
|
||||
gc.setTransform(r.getMxx(), r.getMyx(), r.getMxy(), r.getMyy(), r.getTx(), r.getTy());
|
||||
@@ -75,29 +77,31 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
System.out.println("Drawing");
|
||||
gc.clearRect(0, 0, width, height);
|
||||
//boat
|
||||
GraphCoordinate boat1coord = map.convertGPS(32.296577, -64.854304);
|
||||
GraphCoordinate boat1coord = this.map.convertGPS(32.296577, -64.854304);
|
||||
displayBoat(boat1coord, Color.AQUAMARINE);
|
||||
//finish line
|
||||
gc.setLineWidth(2);
|
||||
GraphCoordinate finishLineCoord1 = map.convertGPS(32.317379, -64.839291);
|
||||
GraphCoordinate finishLineCoord2 = map.convertGPS(32.317257, -64.836260);
|
||||
GraphCoordinate finishLineCoord1 = this.map.convertGPS(32.317379, -64.839291);
|
||||
GraphCoordinate finishLineCoord2 = this.map.convertGPS(32.317257, -64.836260);
|
||||
displayLine(finishLineCoord1, finishLineCoord2, Color.DARKRED);
|
||||
//marks
|
||||
GraphCoordinate markCoord = map.convertGPS(32.293039, -64.843983);
|
||||
GraphCoordinate southGate1 = map.convertGPS(32.284680, -64.850045);
|
||||
GraphCoordinate southGate2 = map.convertGPS(32.280164, -64.847591);
|
||||
GraphCoordinate northGate1 = map.convertGPS(32.309693, -64.835249);
|
||||
GraphCoordinate northGate2 = map.convertGPS(32.308046, -64.831785);
|
||||
GraphCoordinate markCoord = this.map.convertGPS(32.293039, -64.843983);
|
||||
GraphCoordinate southGate1 = this.map.convertGPS(32.284680, -64.850045);
|
||||
GraphCoordinate southGate2 = this.map.convertGPS(32.280164, -64.847591);
|
||||
GraphCoordinate northGate1 = this.map.convertGPS(32.309693, -64.835249);
|
||||
GraphCoordinate 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
|
||||
GraphCoordinate startline1 = map.convertGPS(32.296577, -64.854304);
|
||||
GraphCoordinate startline2 = map.convertGPS(32.293771, -64.855242);
|
||||
GraphCoordinate startline1 = this.map.convertGPS(32.296577, -64.854304);
|
||||
GraphCoordinate startline2 = this.map.convertGPS(32.293771, -64.855242);
|
||||
displayLine(startline1, startline2, Color.GREEN);
|
||||
|
||||
displayArrow(new GraphCoordinate(100, 100), Color.BLUEVIOLET);
|
||||
//display wind direction arrow - specify origin point and angle
|
||||
displayPoint(this.map.convertGPS(32.293771, -64.855242), Color.BLACK);
|
||||
displayArrow(new GraphCoordinate(500, 20), 100);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user