Example usage for javafx.scene.shape Cylinder getTransforms

List of usage examples for javafx.scene.shape Cylinder getTransforms

Introduction

In this page you can find the example usage for javafx.scene.shape Cylinder getTransforms.

Prototype

public final ObservableList<Transform> getTransforms() 

Source Link

Document

Defines the ObservableList of javafx.scene.transform.Transform objects to be applied to this Node .

Usage

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

/**
 * Draws a line in 3D between 2 3D points on the given group.
 * //from  w w w.  j  av a  2  s .  c  o  m
 * @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;
}