Merge remote-tracking branch 'origin/NewUI_merge' into NewUI_merge

This commit is contained in:
Alistair McIntyre
2017-09-12 17:08:22 +12:00
4 changed files with 37 additions and 29 deletions
+5 -9
View File
@@ -1,20 +1,16 @@
package seng302; package seng302;
import ch.qos.logback.classic.Level; import ch.qos.logback.classic.Level;
import com.jfoenix.controls.JFXDecorator;
import javafx.application.Application; import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage; import javafx.stage.Stage;
import org.apache.commons.cli.*; import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import seng302.visualiser.controllers.ViewManager; import seng302.visualiser.controllers.ViewManager;
import seng302.gameServer.ServerAdvertiser;
import java.io.IOException;
public class App extends Application { public class App extends Application {
@@ -13,6 +13,7 @@ import javafx.scene.Cursor;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.SceneAntialiasing;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane; import javafx.scene.layout.StackPane;
@@ -78,7 +79,7 @@ public class ViewManager {
gameClient = new GameClient(decorator); gameClient = new GameClient(decorator);
stage.getIcons().add(new Image(getClass().getResourceAsStream("/PP.png"))); stage.getIcons().add(new Image(getClass().getResourceAsStream("/PP.png")));
Scene scene = new Scene(decorator, 1200, 800); Scene scene = new Scene(decorator, 1200, 800, false, SceneAntialiasing.BALANCED);
stage.setMinHeight(800); stage.setMinHeight(800);
stage.setMinWidth(1200); stage.setMinWidth(1200);
stage.setScene(scene); stage.setScene(scene);
@@ -4,7 +4,7 @@ import javafx.animation.AnimationTimer;
import javafx.scene.Group; import javafx.scene.Group;
/** /**
* Created by CJIRWIN on 7/09/2017. * Class for generic imported 3D model. Animation terminates on if removed from scene.
*/ */
public class Model { public class Model {
@@ -16,6 +16,12 @@ public class Model {
this.animationTimer = animation; this.animationTimer = animation;
if (animation != null) { if (animation != null) {
animation.start(); animation.start();
assets.sceneProperty().addListener((obs, oldVal, newVal) -> {
if (newVal == null) {
animationTimer.stop();
animationTimer = null;
}
});
} }
} }
@@ -2,7 +2,6 @@ package seng302.visualiser.fxObjects.assets_3D;
import com.interactivemesh.jfx.importer.col.ColModelImporter; import com.interactivemesh.jfx.importer.col.ColModelImporter;
import com.interactivemesh.jfx.importer.stl.StlMeshImporter; import com.interactivemesh.jfx.importer.stl.StlMeshImporter;
import java.util.Random;
import javafx.animation.AnimationTimer; import javafx.animation.AnimationTimer;
import javafx.geometry.Point3D; import javafx.geometry.Point3D;
import javafx.scene.AmbientLight; import javafx.scene.AmbientLight;
@@ -15,6 +14,8 @@ import javafx.scene.transform.Rotate;
import javafx.scene.transform.Scale; import javafx.scene.transform.Scale;
import javafx.scene.transform.Translate; import javafx.scene.transform.Translate;
/** /**
* Factory class for creating 3D models of boats. * Factory class for creating 3D models of boats.
*/ */
@@ -22,28 +23,30 @@ public class ModelFactory {
public static BoatModel boatIconView(BoatMeshType boatType, Color primaryColour) { public static BoatModel boatIconView(BoatMeshType boatType, Color primaryColour) {
Group boatAssets = getUnmodifiedBoatModel(boatType, primaryColour); Group boatAssets = getUnmodifiedBoatModel(boatType, primaryColour);
final Rotate animationRotate = new Rotate(0, new Point3D(0,0,1));
boatAssets.getTransforms().addAll( boatAssets.getTransforms().addAll(
new Scale(10, 10, 10), new Scale(3.3, 3.3, 3.3),
new Rotate(45, new Point3D(0,0,1)), new Rotate(-70, new Point3D(1,0,0)),
new Rotate(90, new Point3D(0, 1, 0)), new Translate(13,50, 0),
new Rotate(270, new Point3D(1, 0, 0)), animationRotate
new Translate(12, 14, 0)
); );
boatAssets.getTransforms().add(animationRotate);
BoatModel bo = new BoatModel(boatAssets, null, boatType); BoatModel bo = new BoatModel(boatAssets, null, boatType);
bo.showSail();
bo.rotateSail(45); bo.rotateSail(45);
bo.setAnimation(new AnimationTimer() {
Group group = bo.getAssets();
double boatAngle = 0;
int id = new Random().nextInt();
bo.setAnimation(new AnimationTimer() {
double boatAngle = 0;
Rotate rotate = animationRotate;
@Override @Override
public void handle(long now) { public void handle(long now) {
((Rotate) group.getTransforms().get(3)).setAngle(boatAngle++); boatAngle += 0.5;
rotate.setAngle(boatAngle);
} }
}); });
boatAssets.getChildren().add(new AmbientLight(new Color(1, 1, 1, 0.01))); boatAssets.getChildren().addAll(
new AmbientLight()
);
return bo; return bo;
} }
@@ -52,19 +55,21 @@ public class ModelFactory {
boatAssets.getTransforms().addAll( boatAssets.getTransforms().addAll(
new Scale(40, 40, 40), new Scale(40, 40, 40),
new Rotate(90, new Point3D(0,0,1)), new Rotate(90, new Point3D(0,0,1)),
new Rotate(90, new Point3D(0, 1, 0)), new Rotate(90, new Point3D(0, 1, 0))
new Rotate(0, new Point3D(1,1,1))
); );
// TODO: 7/09/17 This seems like it will never be garbage claimed. Might have to call BoatModel.stopAnimation();
final Rotate animationRotate = new Rotate(0, new Point3D(1,1,1));
boatAssets.getTransforms().add(animationRotate);
return new BoatModel(boatAssets, new AnimationTimer() { return new BoatModel(boatAssets, new AnimationTimer() {
private double rotation = 0; private double rotation = 0;
private final Group group = boatAssets; private Rotate rotate = animationRotate;
@Override @Override
public void handle(long now) { public void handle(long now) {
rotation += 0.5; rotation += 0.5;
((Rotate) group.getTransforms().get(3)).setAngle(rotation); rotate.setAngle(rotation);
} }
}, boatType); }, boatType);
} }