Fades boat opacity every frame during and after race.
- Added TrackPoint with time added and expiry to calculate opacity each frame - Modified drawTrackPoint to compute colour from TrackPoint alpha - Removed getTrackPoint from BoatInRace #pait[jjg64, cbt24]
This commit is contained in:
@@ -41,8 +41,6 @@ public class RaceController extends Controller {
|
|||||||
Label timer;
|
Label timer;
|
||||||
@FXML
|
@FXML
|
||||||
Label FPS;
|
Label FPS;
|
||||||
@FXML
|
|
||||||
ComboBox<BoatInRace> visibleTrackSelect;
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
TableView<BoatInRace> boatInfoTable;
|
TableView<BoatInRace> boatInfoTable;
|
||||||
@@ -168,8 +166,6 @@ public class RaceController extends Controller {
|
|||||||
startScreen.setVisible(false);
|
startScreen.setVisible(false);
|
||||||
ongoingRacePane.setVisible(true);
|
ongoingRacePane.setVisible(true);
|
||||||
|
|
||||||
visibleTrackSelect.setItems(FXCollections.observableArrayList(startingBoats));
|
|
||||||
|
|
||||||
initializeFPS();
|
initializeFPS();
|
||||||
initializeAnnotations();
|
initializeAnnotations();
|
||||||
|
|
||||||
@@ -195,13 +191,6 @@ public class RaceController extends Controller {
|
|||||||
FPS.setText((fps));
|
FPS.setText((fps));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void toggleTrackVisibility() {
|
|
||||||
visibleTrackSelect.getSelectionModel().getSelectedItem().setTrackVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up FPS display at bottom of screen
|
* Set up FPS display at bottom of screen
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package seng302.Model;
|
package seng302.Model;
|
||||||
|
|
||||||
import javafx.beans.property.IntegerProperty;
|
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
import javafx.beans.property.StringProperty;
|
import javafx.beans.property.StringProperty;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
@@ -28,11 +27,12 @@ public class BoatInRace extends Boat {
|
|||||||
private StringProperty currentLegName;
|
private StringProperty currentLegName;
|
||||||
private boolean started = false;
|
private boolean started = false;
|
||||||
private StringProperty position;
|
private StringProperty position;
|
||||||
private Queue<GPSCoordinate> track = new ConcurrentLinkedQueue<GPSCoordinate>();
|
|
||||||
|
private Queue<TrackPoint> track = new ConcurrentLinkedQueue<TrackPoint>();
|
||||||
private long nextValidTime = 0;
|
private long nextValidTime = 0;
|
||||||
private final int TRACK_POINT_TIME_INTERVAL = 1000; // every 1 seconds
|
private final int TRACK_POINT_TIME_INTERVAL = 1000; // every 1 seconds
|
||||||
private final int TRACK_POINT_LIMIT = 10;
|
private final int TRACK_POINT_LIMIT = 10;
|
||||||
private boolean trackVisible = false;
|
private boolean trackVisible = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor method.
|
* Constructor method.
|
||||||
@@ -262,7 +262,7 @@ public class BoatInRace extends Boat {
|
|||||||
Boolean added = System.currentTimeMillis() >= nextValidTime;
|
Boolean added = System.currentTimeMillis() >= nextValidTime;
|
||||||
if (added && this.started) {
|
if (added && this.started) {
|
||||||
nextValidTime = System.currentTimeMillis() + TRACK_POINT_TIME_INTERVAL;
|
nextValidTime = System.currentTimeMillis() + TRACK_POINT_TIME_INTERVAL;
|
||||||
track.add(coordinate);
|
track.add(new TrackPoint(coordinate, System.currentTimeMillis(), TRACK_POINT_LIMIT*TRACK_POINT_TIME_INTERVAL));
|
||||||
if (track.size() > TRACK_POINT_LIMIT) {
|
if (track.size() > TRACK_POINT_LIMIT) {
|
||||||
track.remove();
|
track.remove();
|
||||||
}
|
}
|
||||||
@@ -270,7 +270,7 @@ public class BoatInRace extends Boat {
|
|||||||
return added;
|
return added;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Queue<GPSCoordinate> getTrack() {
|
public Queue<TrackPoint> getTrack() {
|
||||||
return track;
|
return track;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,11 +281,4 @@ public class BoatInRace extends Boat {
|
|||||||
public void setTrackVisible(boolean trackVisible) {
|
public void setTrackVisible(boolean trackVisible) {
|
||||||
this.trackVisible = trackVisible;
|
this.trackVisible = trackVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Color getTrackPointColour(int queuePos) {
|
|
||||||
float alphaScale = 1f / (float) (TRACK_POINT_LIMIT);
|
|
||||||
float alpha = 1f - (float) (this.track.size() - queuePos) * alphaScale;
|
|
||||||
Color boatColour = this.colour;
|
|
||||||
return new Color(boatColour.getRed(), boatColour.getBlue(), boatColour.getGreen(), alpha);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -281,22 +281,21 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
} else {
|
} else {
|
||||||
displayBoat(boat, 0);
|
displayBoat(boat, 0);
|
||||||
}
|
}
|
||||||
drawTrackPoint(boat);
|
|
||||||
|
|
||||||
if (raceAnno)
|
if (raceAnno)
|
||||||
displayText(boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()));
|
displayText(boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()));
|
||||||
|
|
||||||
|
if(boat.isTrackVisible()) drawTrackPoint(boat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawTrackPoint(BoatInRace boat) {
|
private void drawTrackPoint(BoatInRace boat) {
|
||||||
int queuePos = 0;
|
for (TrackPoint point : boat.getTrack()) {
|
||||||
for (GPSCoordinate coordinate : boat.getTrack()) {
|
GraphCoordinate scaledCoordinate = this.map.convertGPS(point.getCoordinate());
|
||||||
GraphCoordinate scaledCoordinate = this.map.convertGPS(coordinate);
|
Color boatColour = boat.getColour();
|
||||||
Color colour = boat.getTrackPointColour(queuePos);
|
gc.setFill(new Color(boatColour.getRed(), boatColour.getGreen(), boatColour.getBlue(), point.getAlpha()));
|
||||||
gc.setFill(colour);
|
|
||||||
gc.fillOval(scaledCoordinate.getX(), scaledCoordinate.getY(), 5, 5);
|
gc.fillOval(scaledCoordinate.getX(), scaledCoordinate.getY(), 5, 5);
|
||||||
queuePos++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package seng302.Model;
|
||||||
|
|
||||||
|
import seng302.GPSCoordinate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by cbt24 on 7/04/17.
|
||||||
|
*/
|
||||||
|
public class TrackPoint {
|
||||||
|
private GPSCoordinate coordinate;
|
||||||
|
private long timeAdded;
|
||||||
|
private long expiry;
|
||||||
|
|
||||||
|
public TrackPoint(GPSCoordinate coordinate, long timeAdded, long expiry) {
|
||||||
|
this.coordinate = coordinate;
|
||||||
|
this.timeAdded = timeAdded;
|
||||||
|
this.expiry = expiry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GPSCoordinate getCoordinate() {
|
||||||
|
return coordinate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getAlpha() {
|
||||||
|
return Double.max(0,1.0 - (double)(System.currentTimeMillis() - timeAdded)/expiry);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -77,7 +77,6 @@
|
|||||||
<children>
|
<children>
|
||||||
<CheckBox fx:id="showFPS" mnemonicParsing="false" selected="true" text="Show FPS" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
<CheckBox fx:id="showFPS" mnemonicParsing="false" selected="true" text="Show FPS" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||||
<CheckBox fx:id="showAnnotations" mnemonicParsing="false" selected="true" text="Show Annotation" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="30.0" />
|
<CheckBox fx:id="showAnnotations" mnemonicParsing="false" selected="true" text="Show Annotation" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="30.0" />
|
||||||
<ComboBox fx:id="visibleTrackSelect" layoutX="3.0" layoutY="65.0" onAction="#toggleTrackVisibility" prefWidth="150.0" promptText="Visible tracks" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="55.0" />
|
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
</content>
|
</content>
|
||||||
|
|||||||
Reference in New Issue
Block a user