lots of trying seagull stuff but translate y doesn't want to work for some stupid reason.
This commit is contained in:
@@ -8,11 +8,14 @@ import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.AmbientLight;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.PointLight;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ButtonType;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.effect.Light;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
@@ -145,15 +148,23 @@ public class InGameLobbyController extends Controller {
|
||||
|
||||
for (VisualiserBoat boat : copy) {
|
||||
View3D playerBoatToSet = new View3D();
|
||||
|
||||
playerBoatToSet.setItems(subjects);
|
||||
|
||||
playerContainer.add(playerBoatToSet, (count % 3) , row);
|
||||
playerContainer.setMargin(playerBoatToSet, new Insets(10, 10, 10, 10));
|
||||
|
||||
SeaSurface sea = new SeaSurface(750, 200);
|
||||
sea.setX(250);
|
||||
sea.setZ(210);
|
||||
subjects.add(sea);
|
||||
// SeaSurface sea = new SeaSurface(750, 200);
|
||||
// sea.setX(250);
|
||||
// sea.setZ(210);
|
||||
// subjects.add(sea);
|
||||
//
|
||||
NewSeaSurface sea = new NewSeaSurface();
|
||||
Subject3D seaSubject = new Annotation3D(sea);
|
||||
seaSubject.setX(50);
|
||||
seaSubject.setZ(50);
|
||||
seaSubject.setXRot(0);
|
||||
subjects.add(seaSubject);
|
||||
|
||||
// MeshView mesh = new MeshView(importer.getImport());
|
||||
// Subject3D subject = new Subject3D(mesh,0);
|
||||
|
||||
@@ -31,6 +31,7 @@ import javafx.scene.shape.Cylinder;
|
||||
import javafx.scene.paint.Stop;
|
||||
import javafx.scene.shape.MeshView;
|
||||
import javafx.scene.shape.Shape3D;
|
||||
import javafx.scene.shape.Sphere;
|
||||
import javafx.scene.transform.Translate;
|
||||
import javafx.util.Callback;
|
||||
import network.Messages.Enums.BoatStatusEnum;
|
||||
@@ -504,6 +505,18 @@ public class RaceViewController extends Controller {
|
||||
viewSubjects.add(Assets3D.ccwNextArrow);
|
||||
viewSubjects.add(Assets3D.cwNextArrow);
|
||||
|
||||
|
||||
// SeagullFlock seagullFlock = new SeagullFlock(67, 43, 0);
|
||||
//// seagullFlock.addToFlock();
|
||||
//// seagullFlock.addToFlock();
|
||||
// seagullFlock.setxBound(450);
|
||||
// seagullFlock.setyBound(450);
|
||||
// viewSubjects.addAll(seagullFlock.getSeagulls());
|
||||
//
|
||||
// Subject3D textSubject = new Annotation3D(new SeagullMesh());
|
||||
// textSubject.setY(-10);
|
||||
// viewSubjects.add(textSubject);
|
||||
|
||||
AnimationTimer rotateArrows = new AnimationTimer() {
|
||||
@Override
|
||||
public void handle(long now) {
|
||||
@@ -720,38 +733,6 @@ public class RaceViewController extends Controller {
|
||||
nextMarkController.show2d();
|
||||
}
|
||||
|
||||
/**
|
||||
* Swap the colour of the next mark to pass with the last mark passed
|
||||
* @param leg boat has started on
|
||||
*/
|
||||
private void swapColours(Leg leg) {
|
||||
CompoundMark start = leg.getStartCompoundMark();
|
||||
CompoundMark end = leg.getEndCompoundMark();
|
||||
|
||||
//The last leg "finish" doesn't have compound marks.
|
||||
if (start == null || end == null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
Shape3D start1 = view3D.getShape(start.getMark1().getSourceID()).getMesh();
|
||||
Shape3D end1 = view3D.getShape(end.getMark1().getSourceID()).getMesh();
|
||||
|
||||
Material nextMark = start1.getMaterial();
|
||||
Material lastMark = end1.getMaterial();
|
||||
|
||||
start1.setMaterial(lastMark);
|
||||
if(start.getMark2() != null) {
|
||||
Shape3D start2 = view3D.getShape(start.getMark2().getSourceID()).getMesh();
|
||||
start2.setMaterial(lastMark);
|
||||
}
|
||||
|
||||
end1.setMaterial(nextMark);
|
||||
if(end.getMark2() != null) {
|
||||
Shape3D end2 = view3D.getShape(end.getMark2().getSourceID()).getMesh();
|
||||
end2.setMaterial(nextMark);
|
||||
}
|
||||
}
|
||||
|
||||
private void setNextMarkArrowDirection(Mark mark1, Mark mark2, RoundingType roundingType, int direction){
|
||||
boolean port = roundingType == RoundingType.Port;
|
||||
Mark chosenMark = null;
|
||||
|
||||
@@ -21,6 +21,7 @@ public class Assets3D {
|
||||
|
||||
public static MeshView[] sails;
|
||||
public static MeshView[] sea;
|
||||
public static MeshView[] seagull;
|
||||
public static Subject3D windArrow;
|
||||
public static Subject3D compass;
|
||||
public static Subject3D cwNextArrow;
|
||||
@@ -33,6 +34,7 @@ public class Assets3D {
|
||||
loadNextArrow();
|
||||
loadSeaSurface();
|
||||
loadSkybox();
|
||||
loadSeagull();
|
||||
}
|
||||
|
||||
private static void loadNextArrow(){
|
||||
@@ -94,6 +96,20 @@ public class Assets3D {
|
||||
}
|
||||
}
|
||||
|
||||
private static void loadSeagull(){
|
||||
seagull = new MeshView[30];
|
||||
ObjModelImporter objModelImporter = new ObjModelImporter();
|
||||
|
||||
for (int i = 0; i < seagull.length; i++){
|
||||
String path = String.format("assets/V1.1 Animated/Seagull V1.1_%06d.obj", i + 1);
|
||||
URL asset = Assets3D.class.getClassLoader().getResource(path);
|
||||
objModelImporter.read(asset);
|
||||
if (objModelImporter.getImport().length > 0) {
|
||||
seagull[i] = objModelImporter.getImport()[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Shape3D getBoat(){
|
||||
String path = "assets/V1.4 Boat.x3d";
|
||||
return loadX3d(path);
|
||||
|
||||
@@ -25,6 +25,7 @@ public class NewSeaSurface extends MeshView{
|
||||
Color seaBlue = new Color(0.284, 0.573, 1.00, 1);
|
||||
Material seaMat = new PhongMaterial(seaBlue);
|
||||
setMaterial(seaMat);
|
||||
setMouseTransparent(true);
|
||||
seaRipple.start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
package visualiser.layout;
|
||||
|
||||
import javafx.animation.AnimationTimer;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.transform.Translate;
|
||||
import visualiser.model.GraphCoordinate;
|
||||
import visualiser.utils.GPSConverter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Created by Gondr on 28/09/2017.
|
||||
*/
|
||||
public class SeagullFlock{
|
||||
private ObservableList<Subject3D> seagulls = FXCollections.observableArrayList();
|
||||
private double xPos = 0;
|
||||
private double yPos = 0;
|
||||
private double zPos = 20;
|
||||
private double heading = 0;
|
||||
private double[] xOffset = {0, -5, -5};
|
||||
private double[] yOffset = {0, -5, 5};
|
||||
private double xBound = Integer.MAX_VALUE;//-/+
|
||||
private double yBound = Integer.MAX_VALUE;
|
||||
private List<Double> goToX = new ArrayList<>();
|
||||
private List<Double> goToY = new ArrayList<>();
|
||||
|
||||
private double speed = 0.01;
|
||||
|
||||
private AnimationTimer goTo = new AnimationTimer() {
|
||||
@Override
|
||||
public void handle(long now) {
|
||||
if (goToX.size() > 0) {
|
||||
//System.out.println(xPosition + " " + yPosition);
|
||||
heading = GPSConverter.getAngle(new GraphCoordinate(xPos, yPos),
|
||||
new GraphCoordinate(goToX.get(0), goToY.get(0)));
|
||||
double delx = goToX.get(0) - xPos;
|
||||
double dely = goToY.get(0) - yPos;
|
||||
double scale = speed / Math.sqrt(delx * delx + dely * dely);
|
||||
if (scale < 1) {
|
||||
xPos += delx * scale;
|
||||
yPos += dely * scale;
|
||||
} else {
|
||||
goToX.remove(0);
|
||||
goToY.remove(0);
|
||||
}
|
||||
}else {
|
||||
stop();
|
||||
randNewAction();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private AnimationTimer update = new AnimationTimer() {
|
||||
@Override
|
||||
public void handle(long now) {
|
||||
for (int i = 0; i < seagulls.size(); i++){
|
||||
Subject3D seagull = seagulls.get(i);
|
||||
System.out.println(seagull.getY());
|
||||
seagull.getMesh().setTranslateY(zPos);
|
||||
|
||||
seagull.setHeading(heading);
|
||||
seagull.setX(xPos + xOffset[i]);
|
||||
seagull.setZ(yPos + yOffset[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public SeagullFlock() {
|
||||
this(0d, 0d, 0d);
|
||||
}
|
||||
|
||||
public SeagullFlock(double x, double y, double z){
|
||||
xPos = x;
|
||||
yPos = y;
|
||||
zPos = z;
|
||||
addToFlock();
|
||||
update.start();
|
||||
randNewAction();
|
||||
}
|
||||
|
||||
public void addToFlock(){
|
||||
if (seagulls.size() < 3) {
|
||||
Annotation3D newSeagull = new Annotation3D(new SeagullMesh());
|
||||
System.out.println("After Create " + newSeagull.getY());
|
||||
newSeagull.setXRot(0);
|
||||
seagulls.add(newSeagull);
|
||||
// seagulls.add(new Annotation3D(new Sphere(5)));
|
||||
}
|
||||
}
|
||||
|
||||
public void setxBound(double xBound) {
|
||||
this.xBound = xBound;
|
||||
}
|
||||
|
||||
public void setyBound(double yBound) {
|
||||
this.yBound = yBound;
|
||||
}
|
||||
|
||||
public void randNewAction(){
|
||||
Random rand = new Random();
|
||||
int nextAction = rand.nextInt(1);
|
||||
switch(nextAction){
|
||||
case 0:
|
||||
//do a straight line
|
||||
double nextX = rand.nextInt((int)this.xBound);
|
||||
/*if (nextX > this.xBound/2){
|
||||
nextX = - nextX/2;
|
||||
}*/
|
||||
double nextY = rand.nextInt((int)this.yBound);
|
||||
/*if (nextY > this.yBound/2){
|
||||
nextY = - nextY/2;
|
||||
}*/
|
||||
goToX.add(nextX);
|
||||
goToY.add(nextY);
|
||||
break;
|
||||
case 1:
|
||||
//do a octogan circle
|
||||
goToX.add(xPos - 3);
|
||||
goToX.add(xPos - 3);
|
||||
goToX.add(xPos);
|
||||
goToX.add(xPos + 3);
|
||||
goToX.add(xPos + 6);
|
||||
goToX.add(xPos + 6);
|
||||
goToX.add(xPos + 3);
|
||||
goToX.add(xPos);
|
||||
//y
|
||||
goToX.add(yPos - 3);
|
||||
goToX.add(yPos - 6);
|
||||
goToX.add(yPos - 9);
|
||||
goToX.add(yPos - 9);
|
||||
goToX.add(yPos - 6);
|
||||
goToX.add(yPos - 3);
|
||||
goToX.add(yPos);
|
||||
goToX.add(yPos);
|
||||
break;
|
||||
}
|
||||
goTo.start();
|
||||
}
|
||||
|
||||
public List<Subject3D> getSeagulls() {
|
||||
return seagulls;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package visualiser.layout;
|
||||
|
||||
import javafx.animation.AnimationTimer;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.paint.PhongMaterial;
|
||||
import javafx.scene.shape.MeshView;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Created by Gondr on 28/09/2017.
|
||||
*/
|
||||
public class SeagullMesh extends MeshView{
|
||||
private int index = 0;
|
||||
private int isFlapping = 0;
|
||||
private int flapPeriod;
|
||||
private int flapStrength;
|
||||
private int periodElapsed = 0;
|
||||
|
||||
public SeagullMesh() {
|
||||
setMesh(Assets3D.seagull[0].getMesh());
|
||||
setTranslateY(10);
|
||||
System.out.println("On create " + getTranslateY());
|
||||
// PhongMaterial white = new PhongMaterial(Color.WHITE);
|
||||
// setMaterial(white);
|
||||
// Random rand = new Random();
|
||||
// flapPeriod = rand.nextInt(9);
|
||||
// flapPeriod = 60 * (11 + flapPeriod);
|
||||
// flapStrength = rand.nextInt(3) + 2;
|
||||
//scheduledFlap.start();
|
||||
}
|
||||
|
||||
private AnimationTimer flap = new AnimationTimer() {
|
||||
@Override
|
||||
public void handle(long now) {
|
||||
index = (index + 1) % Assets3D.seagull.length;
|
||||
setMesh(Assets3D.seagull[index].getMesh());
|
||||
if (index == 0){
|
||||
isFlapping ++;
|
||||
if (isFlapping >= flapStrength){
|
||||
stop();
|
||||
setMesh(Assets3D.seagull[0].getMesh());
|
||||
isFlapping = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private AnimationTimer scheduledFlap = new AnimationTimer() {
|
||||
@Override
|
||||
public void handle(long now) {
|
||||
if (periodElapsed == 0 && isFlapping == 0){
|
||||
startFlapping();
|
||||
}
|
||||
periodElapsed = (periodElapsed + 1) % flapPeriod;
|
||||
}
|
||||
};
|
||||
|
||||
public void startFlapping(){
|
||||
flap.start();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user