Removed rounding in GameView that caused objects to be rendered at incorrect positions.

#bug
This commit is contained in:
Calum
2017-09-11 11:37:50 +12:00
parent f136a970db
commit 1210f9342b
9 changed files with 229 additions and 92 deletions
@@ -6,6 +6,7 @@ import seng302.model.GeoPoint;
public class GeoUtility {
private static double EARTH_RADIUS = 6378.137;
// private static double EARTH_RADIUS = 6378.13712121212121212121212121212121212121;
private static Double MS_TO_KNOTS = 1.943844492;
/**
@@ -13,6 +13,8 @@ import javafx.scene.*;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyEvent;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Sphere;
import javafx.scene.text.Text;
import javafx.scene.transform.Rotate;
import javafx.scene.transform.Scale;
@@ -126,9 +128,35 @@ public class GameView3D {
camera.getTransforms().add(new Rotate(30, new Point3D(1,0,0)));
// gameObjects.getChildren().addAll(raceBorder, markers, tokens);
Sphere red = new Sphere(1);
red.setMaterial(new PhongMaterial(Color.RED));
red.setLayoutX(0);
red.setLayoutY(0);
Sphere blue = new Sphere(1);
blue.setMaterial(new PhongMaterial(Color.BLUE));
blue.setLayoutX(1);
blue.setLayoutY(0);
Sphere green = new Sphere(1);
green.setMaterial(new PhongMaterial(Color.GREEN));
green.setLayoutX(-.5);
green.setLayoutY(0);
Sphere white = new Sphere(1);
white.setMaterial(new PhongMaterial(Color.WHITE));
white.setLayoutX(-.25);
white.setLayoutY(0);
Sphere black = new Sphere(1);
black.setMaterial(new PhongMaterial(Color.BLACK));
black.setLayoutX(-.125);
black.setLayoutY(0);
gameObjects.getChildren().addAll(
ModelFactory.importModel(ModelType.OCEAN).getAssets(),
raceBorder, markers, tokens
raceBorder, markers, tokens,
white, blue, green, black, red
);
// Sphere s = new Sphere(1);
@@ -281,9 +309,9 @@ public class GameView3D {
Math.toDegrees(
Math.atan2(m2Location.getY() - m1Location.getY(), m2Location.getX() - m1Location.getX())
) + 90,
new Point3D(0,1,0)
new Point3D(0,0,1)
),
new Scale(1, 1, m1Location.distance(m2Location) / 10)
new Scale(1, m1Location.distance(m2Location) / 10, 1)
);
Point2D midPoint = m2Location.midpoint(m1Location);
@@ -411,28 +439,20 @@ public class GameView3D {
minLatPoint, new GeoPoint(unscaledLat, unscaledLon)
);
if (angleFromReference >= 0 && angleFromReference <= Math.PI / 2) {
xAxisLocation += Math
.round(distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference);
yAxisLocation -= Math
.round(distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference);
xAxisLocation += distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference;
yAxisLocation -= distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference;
} else if (angleFromReference >= 0) {
angleFromReference = angleFromReference - Math.PI / 2;
xAxisLocation += Math
.round(distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference);
yAxisLocation += Math
.round(distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference);
xAxisLocation += distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference;
yAxisLocation += distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference;
} else if (angleFromReference < 0 && angleFromReference >= -Math.PI / 2) {
angleFromReference = Math.abs(angleFromReference);
xAxisLocation -= Math
.round(distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference);
yAxisLocation -= Math
.round(distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference);
xAxisLocation -= distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference;
yAxisLocation -= distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference;
} else {
angleFromReference = Math.abs(angleFromReference) - Math.PI / 2;
xAxisLocation -= Math
.round(distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference);
yAxisLocation += Math
.round(distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference);
xAxisLocation -= distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference;
yAxisLocation += distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference;
}
if (horizontalInversion) {
xAxisLocation = canvasWidth - bufferSize - (xAxisLocation - bufferSize);
@@ -502,8 +522,8 @@ public class GameView3D {
newBoat.setFill(colour);
boatObjects.put(clientYacht, newBoat);
// createAndBindAnnotationBox(clientYacht, colour);
// wakesGroup.getChildren().add(newBoat.getWake());
// wakes.add(newBoat.getWake());
wakesGroup.getChildren().add(newBoat.getWake());
wakes.add(newBoat.getWake());
boatObjectGroup.getChildren().add(newBoat);
// trails.getChildren().add(newBoat.getTrail());
@@ -521,9 +541,10 @@ public class GameView3D {
}
// annotationsGroup.getChildren().addAll(annotations.values());
Platform.runLater(() -> {
gameObjects.getChildren().addAll(boatObjectGroup);
// gameObjects.addAll(trails);
// gameObjects.addAll(wakes);
gameObjects.getChildren().addAll(wakes);
gameObjects.getChildren().addAll(boatObjectGroup);
// gameObjects.addAll(annotationsGroup);
// gameObjects.addAll(boatObjectGroup);
});
@@ -564,7 +585,7 @@ public class GameView3D {
Math.toDegrees(
Math.atan2(location.getY() - lastLocation.getY(), location.getX() - lastLocation.getX())
),
new Point3D(0,1,0)
new Point3D(0,0,1)
),
new Scale((lastLocation.distance(location) / 15)-0.2, 1, 1)
);
@@ -586,7 +607,7 @@ public class GameView3D {
Math.toDegrees(
Math.atan2(lastLocation.getY() - firstLocation.getY(), lastLocation.getX() - firstLocation.getX())
),
new Point3D(0,1,0)
new Point3D(0,0,1)
),
new Scale((firstLocation.distance(lastLocation) / 15)-0.2, 1, 1)
);
@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import javafx.application.Platform;
import javafx.geometry.Point2D;
import javafx.geometry.Point3D;
import javafx.scene.AmbientLight;
import javafx.scene.Group;
import javafx.scene.Node;
@@ -20,6 +21,7 @@ import javafx.scene.transform.Translate;
import seng302.visualiser.fxObjects.assets_3D.BoatMeshType;
import seng302.visualiser.fxObjects.assets_3D.BoatModel;
import seng302.visualiser.fxObjects.assets_3D.ModelFactory;
import seng302.visualiser.fxObjects.assets_3D.ModelType;
/**
* BoatGroup is a javafx group that by default contains a graphical objects for representing a 2
@@ -61,7 +63,7 @@ public class BoatObject extends Group {
// private Polygon boatPoly;
private BoatModel boatPoly;
private Polygon sail;
private Wake wake;
private Group wake;
private Line leftLayLine;
private Line rightLayline;
private double distanceTravelled, lastRotation;
@@ -133,8 +135,8 @@ public class BoatObject extends Group {
rightLayline = new Line();
trail.getStrokeDashArray().setAll(5d, 10d);
trail.setCache(true);
wake = new Wake(0, -BOAT_HEIGHT);
wake.setVisible(true);
wake = ModelFactory.importModel(ModelType.WAKE).getAssets();
sail = new Polygon(0.0,BOAT_HEIGHT / 4,
0.0, BOAT_HEIGHT);
@@ -162,7 +164,7 @@ public class BoatObject extends Group {
// super.getChildren().add(pointLight);
AmbientLight light = new AmbientLight(new Color(0.5,0.5,0.5,1));
super.getChildren().add(light);
super.getChildren().addAll(boatPoly.getAssets());//, sail);
super.getChildren().addAll(boatPoly.getAssets());
}
public void setFill (Color value) {
@@ -229,8 +231,8 @@ public class BoatObject extends Group {
// sail.setLayoutX(x);
// sail.setLayoutY(y);
// }
// wake.setLayoutX(x);
// wake.setLayoutY(y);
wake.setLayoutX(x);
wake.setLayoutY(y);
});
// wake.setRotation(rotation, velocity);
// rotateTo(rotation);
@@ -262,6 +264,7 @@ public class BoatObject extends Group {
private void rotateTo(double heading, boolean sailsIn, double windDir) {
rotation.setAngle(heading);
wake.getTransforms().setAll(new Rotate(heading, new Point3D(0,0,1)));
if (!sailsIn) {
boatPoly.showSail();
Double sailWindOffset = 30.0;
@@ -270,19 +273,19 @@ public class BoatObject extends Group {
Double normalizedHeading = normalizeHeading(heading, windDir);
if (normalizedHeading < 180) {
if (normalizedHeading < sailWindOffset + upwindAngleLimit){
boatPoly.rotateSail(heading + 90 - upwindAngleLimit);
boatPoly.rotateSail(90 - upwindAngleLimit);
} else if (normalizedHeading > 90 + sailWindOffset){
boatPoly.rotateSail(heading + downwindAngleLimit);
boatPoly.rotateSail(downwindAngleLimit);
} else {
boatPoly.rotateSail(windDir + 90 + sailWindOffset);
boatPoly.rotateSail(90 + sailWindOffset);
}
} else {
if (normalizedHeading > 360 - (sailWindOffset + upwindAngleLimit)){
boatPoly.rotateSail(heading + 90 + upwindAngleLimit);
boatPoly.rotateSail(90 + upwindAngleLimit);
} else if (normalizedHeading < 270 - sailWindOffset){
boatPoly.rotateSail(heading + 180 - downwindAngleLimit);
boatPoly.rotateSail(180 - downwindAngleLimit);
} else {
boatPoly.rotateSail(windDir + 90 - sailWindOffset);
boatPoly.rotateSail(90 - sailWindOffset);
}
}
} else {
@@ -447,7 +450,7 @@ public class BoatObject extends Group {
}
public void setTrajectory(double heading, double velocity, double windDir) {
wake.setRotation(lastHeading - heading, velocity);
// wake.r(lastHeading - heading, velocity);
// rotateTo(heading, false, windDir);
xVelocity = Math.cos(Math.toRadians(heading)) * velocity;
yVelocity = Math.sin(Math.toRadians(heading)) * velocity;
@@ -104,8 +104,10 @@ public class ModelFactory {
case START_LINE:
case GATE_LINE:
return makeGate(assets);
case WAKE:
return makeWake(assets);
default:
return new Model(assets, null);
return new Model(new Group(assets), null);
}
}
@@ -118,7 +120,7 @@ public class ModelFactory {
new Translate(0,-1,0),
new Rotate(0 ,new Point3D(1,1,1))
);
return new Model(assets, new AnimationTimer() {
return new Model(new Group(assets), new AnimationTimer() {
private double rotation = 0;
private Group group = assets;
@@ -137,14 +139,14 @@ public class ModelFactory {
Group area = new Group(importer.getImport());
area.getChildren().add(marker);
area.getTransforms().add(new Rotate(90, new Point3D(1, 0, 0)));
return new Model(area, null);
return new Model(new Group(area), null);
}
private static Model makeOcean(Group group) {
// group.setScaleY(Double.MAX_VALUE);
// group.setScaleX(Double.MAX_VALUE);
// group.getTransforms().add(new Rotate(90, new Point3D(1, 0, 0)));
Circle ocean = new Circle(0,0,1000, Color.DEEPSKYBLUE);
Circle ocean = new Circle(0,0,1000, Color.DARKSEAGREEN);
ocean.setStroke(Color.TRANSPARENT);
group.getChildren().add(ocean);
return new Model(group, null);
@@ -155,13 +157,22 @@ public class ModelFactory {
new Rotate(90, new Point3D(1,0,0)),
new Scale(1.5,1.5,1.5)
);
return new Model(assets, null);
return new Model(new Group(assets), null);
}
private static Model makeGate(Group assets) {
assets.getTransforms().addAll(
new Rotate(90, new Point3D(1,0,0))
);
return new Model(assets, null);
return new Model(new Group(assets), null);
}
private static Model makeWake(Group assets) {
assets.getTransforms().setAll(
new Rotate(-90, new Point3D(0,0,1)),
new Rotate(90, new Point3D(1,0,0)),
new Scale(0.5, 0.5, 0.5)
);
return new Model(new Group(assets), null);
}
}
@@ -16,7 +16,8 @@ public enum ModelType {
BORDER_BARRIER ("barrier_segment.dae"),
FINISH_LINE ("finish_line.dae"),
START_LINE ("start_line.dae"),
GATE_LINE ("gate_line.dae");
GATE_LINE ("gate_line.dae"),
WAKE ("wake.dae");
final String filename;