mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Experimented with parallel camera in 3d gameview. Works ok for rendering boats in isometric view.
#test
This commit is contained in:
@@ -13,9 +13,7 @@ import javafx.animation.Timeline;
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.geometry.Point2D;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.PerspectiveCamera;
|
||||
import javafx.scene.*;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
@@ -89,7 +87,7 @@ public class GameView extends Pane {
|
||||
private List<Node> mapTokens;
|
||||
|
||||
private ImageView mapImage = new ImageView();
|
||||
private PerspectiveCamera camera;
|
||||
private Camera camera;
|
||||
|
||||
//FRAME RATE
|
||||
|
||||
@@ -143,24 +141,25 @@ public class GameView extends Pane {
|
||||
public GameView () {
|
||||
gameObjects = this.getChildren();
|
||||
// AmbientLight ambientLight = new AmbientLight(new Color(1,1,1,0.4));
|
||||
//// ambientLight.setOpacity(0.5);
|
||||
// ambientLight.setOpacity(0.5);
|
||||
// gameObjects.add(ambientLight);
|
||||
// create image view for map, bind panel size to image
|
||||
// camera = new PerspectiveCamera(true);
|
||||
// camera.setTranslateZ(-500);
|
||||
// camera.setTranslateY(500);
|
||||
// camera.setTranslateX(800);
|
||||
// camera.setFieldOfView(100);
|
||||
// camera.setFarClip(50);
|
||||
// camera.setNearClip(-600);
|
||||
//// gameObjects.add(camera);
|
||||
// this.sceneProperty().addListener((obs, oldValue, scene) -> {
|
||||
// if (scene != null) {
|
||||
// scene.setCamera(camera);
|
||||
// }
|
||||
// });
|
||||
camera = new ParallelCamera();
|
||||
camera.setTranslateZ(-500);
|
||||
camera.setFarClip(Double.MAX_VALUE);
|
||||
camera.setNearClip(0.1);
|
||||
PointLight pl = new PointLight();
|
||||
pl.setLightOn(true);
|
||||
pl.layoutYProperty().bind(camera.layoutYProperty());
|
||||
pl.layoutXProperty().bind(camera.layoutXProperty());
|
||||
// gameObjects.add(camera);
|
||||
this.sceneProperty().addListener((obs, oldValue, scene) -> {
|
||||
if (scene != null) {
|
||||
scene.setCamera(camera);
|
||||
}
|
||||
});
|
||||
initializeTimer();
|
||||
gameObjects.addAll(mapImage, raceBorder, markers, tokens);
|
||||
gameObjects.addAll(mapImage, raceBorder, markers, tokens, pl);
|
||||
}
|
||||
|
||||
private void initializeTimer() {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package seng302.visualiser.fxObjects.assets_2D;
|
||||
|
||||
import com.interactivemesh.jfx.importer.stl.StlMeshImporter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javafx.application.Platform;
|
||||
@@ -13,13 +12,15 @@ import javafx.scene.PointLight;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.paint.PhongMaterial;
|
||||
import javafx.scene.shape.Line;
|
||||
import javafx.scene.shape.MeshView;
|
||||
import javafx.scene.shape.Polygon;
|
||||
import javafx.scene.shape.Polyline;
|
||||
import javafx.scene.shape.Shape3D;
|
||||
import javafx.scene.transform.Rotate;
|
||||
import javafx.scene.transform.Scale;
|
||||
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;
|
||||
|
||||
/**
|
||||
* BoatGroup is a javafx group that by default contains a graphical objects for representing a 2
|
||||
@@ -59,7 +60,7 @@ public class BoatObject extends Group {
|
||||
//Graphical objects
|
||||
private Polyline trail = new Polyline();
|
||||
// private Polygon boatPoly;
|
||||
private Shape3D boatPoly;
|
||||
private BoatModel boatPoly;
|
||||
private Polygon sail;
|
||||
private Wake wake;
|
||||
private Line leftLayLine;
|
||||
@@ -101,29 +102,29 @@ public class BoatObject extends Group {
|
||||
*/
|
||||
private void initChildren(double... points) {
|
||||
boatPoly = makeBoatPolygon();
|
||||
boatPoly.getTransforms().addAll(
|
||||
boatPoly.getAssets().getTransforms().addAll(
|
||||
new Rotate(-40, new Point3D(1,0,0)),
|
||||
rotation,
|
||||
new Rotate(180, new Point3D(0, 0, 1))
|
||||
new Rotate(-90, new Point3D(0,0,1))
|
||||
);
|
||||
boatPoly.getTransforms().add(new Scale(10, 10, 10));
|
||||
boatPoly.getAssets().getTransforms().add(new Scale(5, 5, 5));
|
||||
// boatPoly.setDrawMode(DrawMode.FILL);
|
||||
// boatPoly.setFill(colour);
|
||||
// boatPoly.setFill(this.colour);
|
||||
// boatPoly.setMaterial(new PhongMaterial(this.colour));
|
||||
boatPoly.setOnMouseEntered(event -> {
|
||||
boatPoly.getAssets().setOnMouseEntered(event -> {
|
||||
// boatPoly.setFill(Color.FLORALWHITE);
|
||||
// boatPoly.setStroke(Color.RED);
|
||||
// boatPoly.setMaterial(new PhongMaterial(Color.FLORALWHITE));
|
||||
});
|
||||
boatPoly.setOnMouseExited(event -> {
|
||||
boatPoly.getAssets().setOnMouseExited(event -> {
|
||||
// boatPoly.setMaterial(new PhongMaterial(this.colour));
|
||||
// boatPoly.setFill(colour);
|
||||
// boatPoly.setFill(this.colour);
|
||||
// boatPoly.setStroke(Color.BLACK);
|
||||
});
|
||||
boatPoly.setOnMouseClicked(event -> setIsSelected(!isSelected));
|
||||
boatPoly.setCache(true);
|
||||
boatPoly.getAssets().setOnMouseClicked(event -> setIsSelected(!isSelected));
|
||||
boatPoly.getAssets().setCache(true);
|
||||
// boatPoly.setCacheHint(CacheHint.SPEED);
|
||||
|
||||
// annotationBox = new AnnotationBox();
|
||||
@@ -162,20 +163,22 @@ 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);//, sail);
|
||||
super.getChildren().addAll(boatPoly.getAssets());//, sail);
|
||||
}
|
||||
|
||||
public void setFill (Color value) {
|
||||
this.colour = value;
|
||||
PhongMaterial pm = new PhongMaterial(this.colour);
|
||||
pm.setSpecularPower(0.5);
|
||||
boatPoly.setMaterial(pm);
|
||||
for (int i=0;i<2;i++) {
|
||||
Shape3D s = (Shape3D) boatPoly.getAssets().getChildren().get(i);
|
||||
s.setMaterial(pm);
|
||||
}
|
||||
trail.setStroke(colour);
|
||||
}
|
||||
|
||||
public Shape3D makeBoatPolygon () {
|
||||
StlMeshImporter importer = new StlMeshImporter();
|
||||
importer.read(getClass().getResource("/meshes/hollow_simple_boat.stl").toString());
|
||||
public BoatModel makeBoatPolygon () {
|
||||
// StlMeshImporter importer = new StlMeshImporter();
|
||||
// importer.read(getClass().getResource("/meshes/hollow_simple_boat.stl").toString());
|
||||
// importer.read(getClass().getResource("/cube.stl").toString());
|
||||
// importer.read(getClass().getResource("/meshes/simple_yacht.stl").toString());
|
||||
// ObjModelImporter importer = new ObjModelImporter();
|
||||
@@ -194,7 +197,7 @@ public class BoatObject extends Group {
|
||||
// FloatBuffer texCoords = ObjData.getTexCoords(obj);
|
||||
// MeshView
|
||||
// FloatBuffer normals = ObjData.getNormals(obj);
|
||||
return new MeshView(importer.getImport());
|
||||
return ModelFactory.boatGameView(BoatMeshType.DINGHY, colour);
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// return null;
|
||||
@@ -210,12 +213,12 @@ public class BoatObject extends Group {
|
||||
* @param sailIn Boolean to toggle sail state.
|
||||
*/
|
||||
public void moveTo(double x, double y, double rotation, double velocity, Boolean sailIn, double windDir) {
|
||||
Double dx = Math.abs(boatPoly.getLayoutX() - x);
|
||||
Double dy = Math.abs(boatPoly.getLayoutY() - y);
|
||||
Double dx = Math.abs(boatPoly.getAssets().getLayoutX() - x);
|
||||
Double dy = Math.abs(boatPoly.getAssets().getLayoutY() - y);
|
||||
Platform.runLater(() -> {
|
||||
rotateTo(rotation, sailIn, windDir);
|
||||
boatPoly.setLayoutX(x);
|
||||
boatPoly.setLayoutY(y);
|
||||
boatPoly.getAssets().setLayoutX(x);
|
||||
boatPoly.getAssets().setLayoutY(y);
|
||||
if (sailIn) {
|
||||
// sail.getPoints().clear();
|
||||
// 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);
|
||||
@@ -261,33 +264,30 @@ public class BoatObject extends Group {
|
||||
private void rotateTo(double heading, boolean sailsIn, double windDir) {
|
||||
rotation.setAngle(heading);
|
||||
if (sailsIn) {
|
||||
boatPoly.showSail();
|
||||
Double sailWindOffset = 30.0;
|
||||
Double upwindAngleLimit = 15.0;
|
||||
Double downwindAngleLimit = 10.0; //Upwind from normalised horizontal
|
||||
Double normalizedHeading = normalizeHeading(heading, windDir);
|
||||
if (normalizedHeading < 180) {
|
||||
sail.getTransforms().setAll(new Rotate(windDir + 90 + sailWindOffset));
|
||||
sail.getPoints().clear();
|
||||
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);
|
||||
if (normalizedHeading > 90 + sailWindOffset){
|
||||
sail.getTransforms().setAll(new Rotate(heading + downwindAngleLimit));
|
||||
}
|
||||
if (normalizedHeading < sailWindOffset + upwindAngleLimit){
|
||||
sail.getTransforms().setAll(new Rotate(heading + 90 - upwindAngleLimit));
|
||||
boatPoly.rotateSail(heading + 90 - upwindAngleLimit);
|
||||
} else if (normalizedHeading > 90 + sailWindOffset){
|
||||
boatPoly.rotateSail(heading + downwindAngleLimit);
|
||||
} else {
|
||||
boatPoly.rotateSail(windDir + 90 + sailWindOffset);
|
||||
}
|
||||
} else {
|
||||
sail.getTransforms().setAll(new Rotate(windDir + 90 - sailWindOffset));
|
||||
sail.getPoints().clear();
|
||||
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);
|
||||
if (normalizedHeading < 270 - sailWindOffset){
|
||||
sail.getTransforms().setAll(new Rotate(heading + 180 - downwindAngleLimit));
|
||||
}
|
||||
if (normalizedHeading > 360 - (sailWindOffset + upwindAngleLimit)){
|
||||
sail.getTransforms().setAll(new Rotate(heading + 90 + upwindAngleLimit));
|
||||
boatPoly.rotateSail(heading + 90 + upwindAngleLimit);
|
||||
} else if (normalizedHeading < 270 - sailWindOffset){
|
||||
boatPoly.rotateSail(heading + 180 - downwindAngleLimit);
|
||||
} else {
|
||||
boatPoly.rotateSail(windDir + 90 - sailWindOffset);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sail.getTransforms().setAll(new Rotate(windDir));
|
||||
boatPoly.hideSail();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -423,12 +423,12 @@ public class BoatObject extends Group {
|
||||
}
|
||||
|
||||
public Double getBoatLayoutX() {
|
||||
return boatPoly.getLayoutX();
|
||||
return boatPoly.getAssets().getLayoutX();
|
||||
}
|
||||
|
||||
|
||||
public Double getBoatLayoutY() {
|
||||
return boatPoly.getLayoutY();
|
||||
return boatPoly.getAssets().getLayoutY();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,13 +7,16 @@ import javafx.scene.Group;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.paint.Paint;
|
||||
import javafx.scene.shape.Circle;
|
||||
import javafx.scene.transform.Scale;
|
||||
import seng302.visualiser.fxObjects.assets_3D.ModelFactory;
|
||||
import seng302.visualiser.fxObjects.assets_3D.ModelType;
|
||||
|
||||
/**
|
||||
* Visual object for a mark. Contains a coloured circle and any specified arrows.
|
||||
*/
|
||||
public class Marker extends Group {
|
||||
|
||||
private Circle mark = new Circle();
|
||||
private Group mark = ModelFactory.importModel(ModelType.PLAIN_MARKER).getAssets();
|
||||
private Paint colour = Color.BLACK;
|
||||
private List<Group> enterArrows = new ArrayList<>();
|
||||
private List<Group> exitArrows = new ArrayList<>();
|
||||
@@ -24,10 +27,13 @@ public class Marker extends Group {
|
||||
* Creates a new Marker containing only a circle. The default colour is black.
|
||||
*/
|
||||
public Marker() {
|
||||
mark.setRadius(5);
|
||||
mark.setCenterX(0);
|
||||
mark.setCenterY(0);
|
||||
Platform.runLater(() -> this.getChildren().addAll(mark, new Group())); //Empty group placeholder or arrows.
|
||||
// mark.setRadius(5);
|
||||
// mark.setCenterX(0);
|
||||
// mark.setCenterY(0);
|
||||
Platform.runLater(() -> {
|
||||
mark.getTransforms().add(new Scale(5,5,5));
|
||||
this.getChildren().addAll(mark, new Group());
|
||||
}); //Empty group placeholder or arrows.
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,7 +43,7 @@ public class Marker extends Group {
|
||||
public Marker(Paint colour) {
|
||||
this();
|
||||
this.colour = colour;
|
||||
mark.setFill(colour);
|
||||
// mark.setFill(colour);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,7 +7,7 @@ package seng302.visualiser.fxObjects.assets_3D;
|
||||
*/
|
||||
public enum BoatMeshType {
|
||||
|
||||
DINGHY ("dinghy_hull.stl", "dinghy_mast.stl", 0, "dinghy_sail.stl", -1.36653);
|
||||
DINGHY ("dinghy_hull.stl", "dinghy_mast.stl", -1.36653, "dinghy_sail.stl", -1.36653);
|
||||
|
||||
final String hullFile, mastFile, sailFile;
|
||||
final double mastOffset, sailOffset;
|
||||
|
||||
@@ -33,14 +33,14 @@ public class BoatModel extends Model {
|
||||
* Rotates the sail of this model by the given amount.
|
||||
* @param degrees The rotation of the sail in degrees
|
||||
*/
|
||||
public void RotateSail(double degrees) {
|
||||
public void rotateSail(double degrees) {
|
||||
MeshView mast = getMeshViewChild(MAST_INDEX);
|
||||
MeshView sail = getMeshViewChild(SAIL_INDEX);
|
||||
mast.getTransforms().setAll(
|
||||
new Rotate(degrees, meshType.mastOffset, 0,0, new Point3D(0, 0, 1))
|
||||
new Rotate(degrees, -meshType.mastOffset, 0,0, new Point3D(0, 0, 1))
|
||||
);
|
||||
sail.getTransforms().setAll(
|
||||
new Rotate(degrees, meshType.sailOffset, 0,0, new Point3D(0, 0, 1))
|
||||
new Rotate(degrees, -meshType.sailOffset, 0,0, new Point3D(0, 0, 1))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user