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;
|
||||
@FXML
|
||||
Label FPS;
|
||||
@FXML
|
||||
ComboBox<BoatInRace> visibleTrackSelect;
|
||||
|
||||
@FXML
|
||||
TableView<BoatInRace> boatInfoTable;
|
||||
@@ -168,8 +166,6 @@ public class RaceController extends Controller {
|
||||
startScreen.setVisible(false);
|
||||
ongoingRacePane.setVisible(true);
|
||||
|
||||
visibleTrackSelect.setItems(FXCollections.observableArrayList(startingBoats));
|
||||
|
||||
initializeFPS();
|
||||
initializeAnnotations();
|
||||
|
||||
@@ -195,13 +191,6 @@ public class RaceController extends Controller {
|
||||
FPS.setText((fps));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void toggleTrackVisibility() {
|
||||
visibleTrackSelect.getSelectionModel().getSelectedItem().setTrackVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up FPS display at bottom of screen
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package seng302.Model;
|
||||
|
||||
import javafx.beans.property.IntegerProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.scene.paint.Color;
|
||||
@@ -28,11 +27,12 @@ public class BoatInRace extends Boat {
|
||||
private StringProperty currentLegName;
|
||||
private boolean started = false;
|
||||
private StringProperty position;
|
||||
private Queue<GPSCoordinate> track = new ConcurrentLinkedQueue<GPSCoordinate>();
|
||||
|
||||
private Queue<TrackPoint> track = new ConcurrentLinkedQueue<TrackPoint>();
|
||||
private long nextValidTime = 0;
|
||||
private final int TRACK_POINT_TIME_INTERVAL = 1000; // every 1 seconds
|
||||
private final int TRACK_POINT_LIMIT = 10;
|
||||
private boolean trackVisible = false;
|
||||
private boolean trackVisible = true;
|
||||
|
||||
/**
|
||||
* Constructor method.
|
||||
@@ -262,7 +262,7 @@ public class BoatInRace extends Boat {
|
||||
Boolean added = System.currentTimeMillis() >= nextValidTime;
|
||||
if (added && this.started) {
|
||||
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) {
|
||||
track.remove();
|
||||
}
|
||||
@@ -270,7 +270,7 @@ public class BoatInRace extends Boat {
|
||||
return added;
|
||||
}
|
||||
|
||||
public Queue<GPSCoordinate> getTrack() {
|
||||
public Queue<TrackPoint> getTrack() {
|
||||
return track;
|
||||
}
|
||||
|
||||
@@ -281,11 +281,4 @@ public class BoatInRace extends Boat {
|
||||
public void setTrackVisible(boolean 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 {
|
||||
displayBoat(boat, 0);
|
||||
}
|
||||
drawTrackPoint(boat);
|
||||
|
||||
if (raceAnno)
|
||||
displayText(boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()));
|
||||
|
||||
if(boat.isTrackVisible()) drawTrackPoint(boat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void drawTrackPoint(BoatInRace boat) {
|
||||
int queuePos = 0;
|
||||
for (GPSCoordinate coordinate : boat.getTrack()) {
|
||||
GraphCoordinate scaledCoordinate = this.map.convertGPS(coordinate);
|
||||
Color colour = boat.getTrackPointColour(queuePos);
|
||||
gc.setFill(colour);
|
||||
for (TrackPoint point : boat.getTrack()) {
|
||||
GraphCoordinate scaledCoordinate = this.map.convertGPS(point.getCoordinate());
|
||||
Color boatColour = boat.getColour();
|
||||
gc.setFill(new Color(boatColour.getRed(), boatColour.getGreen(), boatColour.getBlue(), point.getAlpha()));
|
||||
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>
|
||||
<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" />
|
||||
<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>
|
||||
</AnchorPane>
|
||||
</content>
|
||||
|
||||
Reference in New Issue
Block a user