Luffing sails animation working correctly, working on sailsin animation now.

#story[1111] #pair[kre39,ptg19]
This commit is contained in:
Kusal Ekanayake
2017-08-07 15:24:01 +12:00
parent ecf2c52cfa
commit c7857872ce
4 changed files with 29 additions and 10 deletions
@@ -250,6 +250,9 @@ public class GameClient {
private void processRaceStatusUpdate(RaceStatusData data) {
if (allXMLReceived()) {
raceState.updateState(data);
if (raceView != null) {
raceView.getGameView().setWindDir(raceState.getWindDirection());
}
for (long[] boatData : data.getBoatData()) {
Yacht yacht = allBoatsMap.get((int) boatData[0]);
yacht.setEstimateTimeTillNextMark(raceState.getRaceTime() - boatData[1]);
@@ -81,6 +81,7 @@ public class GameView extends Pane {
private int frameTimeIndex = 0;
private boolean arrayFilled = false;
private Yacht playerYacht;
private double windDir = 0.0;
private enum ScaleDirection {
HORIZONTAL,
@@ -328,7 +329,7 @@ public class GameView extends Pane {
yacht.addLocationListener((boat, lat, lon, heading, velocity, sailIn) ->{
BoatObject bo = boatObjects.get(boat);
Point2D p2d = findScaledXY(lat, lon);
bo.moveTo(p2d.getX(), p2d.getY(), heading, velocity, sailIn, 95.0);
bo.moveTo(p2d.getX(), p2d.getY(), heading, velocity, sailIn, windDir);
// annotations.get(boat).setLayoutX(p2d.getX());
// annotations.get(boat).setLayoutY(p2d.getY());
// annotations.get(boat).setLocation(100d, 100d);
@@ -566,6 +567,12 @@ public class GameView extends Pane {
timer.stop();
}
public void setWindDir(double windDir) {
this.windDir = windDir;
}
public void startRace () {
timer.start();
}
@@ -131,8 +131,8 @@ public class BoatObject extends Group {
boatPoly.setLayoutY(y);
if (sailIn) {
sail.getPoints().clear();
sail.getPoints().addAll(0.0,BOAT_HEIGHT / 4,
0.0, BOAT_HEIGHT);
// sail.getPoints().addAll(0.0, 0.0, 4.0, 1.5, 8.0, 3.0, 12.0, 3.5, 16.0, 3.0, 20.0, 1.5, 24.0, 0.0);
sail.getPoints().addAll(0.0, 0.0, 24.0, 0.0);
sail.setLayoutX(x);
sail.setLayoutY(y);
} else {
@@ -167,21 +167,30 @@ public class BoatObject extends Group {
private void rotateTo(double rotation, boolean sailsIn, double windDir) {
boatPoly.getTransforms().setAll(new Rotate(rotation));
if (sailsIn) {
sail.getTransforms().setAll(new Rotate(95.0));
sail.getTransforms().setAll(new Rotate(windDir + 90));
} else {
sail.getTransforms().setAll(new Rotate(90.0));
sail.getTransforms().setAll(new Rotate(windDir));
}
}
private void animateSail(){
Double[] points = new Double[100];
Double[] points = new Double[200];
double amplitude = 2.0;
double period = 10;
for (int i = 0; i < 50; i++) {
points[i * 2] = 5 * Math.sin(((Math.PI * i) / 25 + sailState));
points[i * 2 + 1] = (BOAT_HEIGHT * i) / 25 + BOAT_HEIGHT / 4;
points[i * 2] = amplitude * Math.sin(((Math.PI * i) / period + sailState));
points[i * 2 + 1] = (BOAT_HEIGHT * i) / BOAT_HEIGHT / 2;
points[199 - (i * 2)] = (BOAT_HEIGHT * i) / BOAT_HEIGHT / 2;
points[199 - (i * 2 + 1)] = amplitude * Math.sin(((Math.PI * i) / period + sailState));
}
if (sailState == - 2 * Math.PI) {
sailState = 0;
} else {
sailState = sailState - Math.PI / 10;
sailState = sailState - Math.PI / 5;
}
sail.getPoints().clear();
sail.getPoints().addAll(points);