private Node createSnakeCube() {
final int SCALE=100;
final Point3D Y_AXIS=new Point3D(0, 1, 0);
final int[][] CUBE=new int[][] {
{-1, 1, -1}, {0, 1, -1}, {1, 1, -1}, {1, 1, 0},
{1, 1, 1}, {0, 1, 1}, {-1, 1, 1}, {-1, 0, 1},
{-1, -1, 1}, {0, -1, 1}, {0, 0, 1}, {1, 0, 1},
{1, 0, 0}, {1, 0, -1}, {0, 0, -1}, {-1, 0, -1},
{-1, -1, -1}, {-1, -1, 0}, {-1, 0, 0}, {-1, 1, 0},
{0, 1, 0}, {0, 0, 0}, {0, -1, 0}, {0, -1, -1},
{1, -1, -1}, {1, -1, 0}, {1, -1, 1}
};
Point3D[] cube=new Point3D[CUBE.length];
for(int i=0; i<cube.length; i++)
cube[i]=new Point3D(
CUBE[i][0]*SCALE, CUBE[i][1]*SCALE, CUBE[i][2]*SCALE);
Group group=new Group();
for(int i=0; i<cube.length-1; i++) {
Point3D p1=cube[i];
Point3D p2=cube[i+1];
Point3D diff=p2.subtract(p1);
double height=diff.magnitude();
Point3D mid=p2.midpoint(p1);
Translate moveToMidpoint=new Translate(
ORIGO.getX()+mid.getX(), ORIGO.getY()+mid.getY(), mid.getZ());
Point3D axisOfRotation=diff.crossProduct(Y_AXIS);
double angle=Math.acos(diff.normalize().dotProduct(Y_AXIS));
Rotate rotateAroundCenter=
new Rotate(-Math.toDegrees(angle), axisOfRotation);
Cylinder c=new Cylinder(5, height);
c.getTransforms().addAll(moveToMidpoint, rotateAroundCenter);
group.getChildren().add(c);
}
return group;
}