Example usage for javafx.scene.transform Rotate Rotate

List of usage examples for javafx.scene.transform Rotate Rotate

Introduction

In this page you can find the example usage for javafx.scene.transform Rotate Rotate.

Prototype

public Rotate(double angle, Point3D axis) 

Source Link

Document

Creates a three-dimensional Rotate transform.

Usage

From source file:eu.mihosoft.fx.tutorials.gravity.SolarSystem.java

/**
 * Runs the simulation./*from  www . j a  va  2s .  c  om*/
 */
public void runSimulation() {

    // stop previous running simulation
    // does nothing if no simulation is running
    stopSimulation();

    // state vector
    int numBodies = particles.size();
    double[] y = new double[numBodies * ODEParticle.getStructSize()];
    double[] m = new double[numBodies];
    boolean[] ignoreFlags = new boolean[numBodies];

    // ui nodes
    nodes = new Node[numBodies];
    rotations = new Rotate[numBodies];

    // gravitational constant
    // see https://en.wikipedia.org/wiki/Gravitational_constant
    double G = 6.672e-11 * 0.000000001; // scaled G

    // initialize particles
    for (int i = 0; i < numBodies; i++) {
        Particle p = particles.get(i);
        p.apply(i, y, m);
        nodes[i] = p.toJFXNode();
        rotations[i] = new Rotate(0, new Point3D(0, 1, 0));
        nodes[i].getTransforms().add(rotations[i]);
    }

    // setup ODE system
    FirstOrderDifferentialEquations odeEqSys = createODE(numBodies, y, m, ignoreFlags, G);

    // start frame listener
    initFrameListener(odeEqSys, y, m, ignoreFlags, 0.001);

}

From source file:be.makercafe.apps.makerbench.editors.GCodeEditor.java

/**
 * Draws a line in 3D between 2 3D points on the given group.
 * //w w  w .j  a  v a 2  s  .  c om
 * @param origin
 *            Origin point
 * @param target
 *            Target point
 * @return 3D line (cylinder) between to points
 */
private Cylinder drawLine3D(Group group, Point3D origin, Point3D target, Material color) {
    if (color == null) {
        color = MATERIAL_BLACK; // default to orange
    }
    Point3D yAxis = new Point3D(0, 1, 0);
    Point3D diff = target.subtract(origin);
    double height = diff.magnitude();

    Point3D mid = target.midpoint(origin);
    Translate moveToMidpoint = new Translate(mid.getX(), mid.getY(), mid.getZ());

    Point3D axisOfRotation = diff.crossProduct(yAxis);
    double angle = Math.acos(diff.normalize().dotProduct(yAxis));
    Rotate rotateAroundCenter = new Rotate(-Math.toDegrees(angle), axisOfRotation);

    Cylinder line = new Cylinder(1, height);
    line.setMaterial(color);

    line.getTransforms().addAll(moveToMidpoint, rotateAroundCenter);

    if (group != null) {
        group.getChildren().add(line);
    }

    return line;
}