Search in sources :

Example 1 with Capsule

use of org.fxyz.shapes.Capsule in project FXyzLib by Birdasaur.

the class CapsuleTest method start.

@Override
public void start(Stage stage) {
    Group capsuleGroup = new Group();
    for (int i = 0; i < 50; i++) {
        Random r = new Random();
        //A lot of magic numbers in here that just artificially constrain the math
        float randomRadius = (float) ((r.nextFloat() * 100) + 25);
        float randomHeight = (float) ((r.nextFloat() * 300) + 75);
        Color randomColor = new Color(r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble());
        Capsule cap = new Capsule(randomRadius, randomHeight, randomColor);
        cap.setEmissiveLightingColor(randomColor);
        cap.setEmissiveLightingOn(r.nextBoolean());
        cap.setDrawMode(r.nextBoolean() ? DrawMode.FILL : DrawMode.LINE);
        double translationX = Math.random() * 1024 * 1.95;
        if (Math.random() >= 0.5) {
            translationX *= -1;
        }
        double translationY = Math.random() * 1024 * 1.95;
        if (Math.random() >= 0.5) {
            translationY *= -1;
        }
        double translationZ = Math.random() * 1024 * 1.95;
        if (Math.random() >= 0.5) {
            translationZ *= -1;
        }
        Translate translate = new Translate(translationX, translationY, translationZ);
        Rotate rotateX = new Rotate(Math.random() * 360, Rotate.X_AXIS);
        Rotate rotateY = new Rotate(Math.random() * 360, Rotate.Y_AXIS);
        Rotate rotateZ = new Rotate(Math.random() * 360, Rotate.Z_AXIS);
        cap.getTransforms().addAll(translate, rotateX, rotateY, rotateZ);
        capsuleGroup.getChildren().add(cap);
    }
    root.getChildren().add(capsuleGroup);
    camera = new AdvancedCamera();
    controller = new FPSController();
    camera.setNearClip(0.1);
    camera.setFarClip(10000.0);
    camera.setFieldOfView(42);
    camera.setController(controller);
    Scene scene = new Scene(new StackPane(root), 1024, 668, true, SceneAntialiasing.BALANCED);
    scene.setCamera(camera);
    scene.setFill(Color.BLACK);
    controller.setScene(scene);
    stage.setTitle("Hello World!");
    stage.setScene(scene);
    stage.show();
    stage.setFullScreen(true);
    stage.setFullScreenExitHint("");
}
Also used : Group(javafx.scene.Group) Rotate(javafx.scene.transform.Rotate) Color(javafx.scene.paint.Color) FPSController(org.fxyz.cameras.controllers.FPSController) Capsule(org.fxyz.shapes.Capsule) Scene(javafx.scene.Scene) Random(java.util.Random) AdvancedCamera(org.fxyz.cameras.AdvancedCamera) Translate(javafx.scene.transform.Translate) StackPane(javafx.scene.layout.StackPane)

Aggregations

Random (java.util.Random)1 Group (javafx.scene.Group)1 Scene (javafx.scene.Scene)1 StackPane (javafx.scene.layout.StackPane)1 Color (javafx.scene.paint.Color)1 Rotate (javafx.scene.transform.Rotate)1 Translate (javafx.scene.transform.Translate)1 AdvancedCamera (org.fxyz.cameras.AdvancedCamera)1 FPSController (org.fxyz.cameras.controllers.FPSController)1 Capsule (org.fxyz.shapes.Capsule)1