Boat now shows a fading collision effect
#story[1195]
This commit is contained in:
@@ -21,10 +21,7 @@ import javafx.scene.layout.StackPane;
|
|||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.paint.Material;
|
import javafx.scene.paint.Material;
|
||||||
import javafx.scene.paint.PhongMaterial;
|
import javafx.scene.paint.PhongMaterial;
|
||||||
import javafx.scene.shape.Box;
|
import javafx.scene.shape.*;
|
||||||
import javafx.scene.shape.MeshView;
|
|
||||||
import javafx.scene.shape.Shape3D;
|
|
||||||
import javafx.scene.shape.Sphere;
|
|
||||||
import javafx.scene.transform.Translate;
|
import javafx.scene.transform.Translate;
|
||||||
import javafx.util.Callback;
|
import javafx.util.Callback;
|
||||||
import network.Messages.Enums.RaceStatusEnum;
|
import network.Messages.Enums.RaceStatusEnum;
|
||||||
@@ -309,9 +306,12 @@ public class RaceController extends Controller {
|
|||||||
if(nextMark.getMark2() != null) {
|
if(nextMark.getMark2() != null) {
|
||||||
view3D.getShape(nextMark.getMark2().getSourceID()).setMaterial(markColor);
|
view3D.getShape(nextMark.getMark2().getSourceID()).setMaterial(markColor);
|
||||||
}
|
}
|
||||||
|
Subject3D shockwave = new Shockwave();
|
||||||
|
|
||||||
|
viewSubjects.add(shockwave);
|
||||||
|
|
||||||
boat.legProperty().addListener((o, prev, curr) -> swapColours(curr));
|
boat.legProperty().addListener((o, prev, curr) -> swapColours(curr));
|
||||||
boat.hasCollidedProperty().addListener((o, prev, curr) -> showCollision(boat));
|
boat.hasCollidedProperty().addListener((o, prev, curr) -> showCollision(boatModel, shockwave));
|
||||||
}
|
}
|
||||||
// Fix initial bird's-eye position
|
// Fix initial bird's-eye position
|
||||||
view3D.updatePivot(new Translate(250, 0, 210));
|
view3D.updatePivot(new Translate(250, 0, 210));
|
||||||
@@ -369,8 +369,24 @@ public class RaceController extends Controller {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showCollision(VisualiserBoat boat) {
|
private void showCollision(Subject3D boat, Subject3D shockwave) {
|
||||||
System.out.println(boat.getSourceID() + " has collided");
|
AnimationTimer shockFront = new AnimationTimer() {
|
||||||
|
double opacity = 1;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(long now) {
|
||||||
|
shockwave.setX(boat.getPosition().getX());
|
||||||
|
shockwave.setY(boat.getPosition().getY());
|
||||||
|
shockwave.setZ(boat.getPosition().getZ());
|
||||||
|
|
||||||
|
if(opacity <= 0) this.stop();
|
||||||
|
else {
|
||||||
|
shockwave.getMesh().setMaterial(new PhongMaterial(new Color(1,0,0,opacity)));
|
||||||
|
opacity -= 0.1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
shockFront.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addThirdPersonAnnotations(Subject3D subject3D) {
|
private void addThirdPersonAnnotations(Subject3D subject3D) {
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package visualiser.layout;
|
||||||
|
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
import javafx.scene.paint.PhongMaterial;
|
||||||
|
import javafx.scene.shape.Cylinder;
|
||||||
|
import javafx.scene.transform.Rotate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by cbt24 on 14/09/17.
|
||||||
|
*/
|
||||||
|
public class Shockwave extends Subject3D {
|
||||||
|
public Shockwave() {
|
||||||
|
super(new Cylinder(5,0),0);
|
||||||
|
getMesh().getTransforms().add(new Rotate(-90, Rotate.X_AXIS));
|
||||||
|
getMesh().setMaterial(new PhongMaterial(new Color(0,0,0,0)));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user