/* * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package meshviewer; import javafx.animation.Interpolator; import javafx.animation.RotateTransition; import javafx.animation.Timeline; import javafx.application.Application; import javafx.event.EventHandler; import javafx.geometry.Point3D; import javafx.scene.*; import javafx.scene.input.KeyEvent; import javafx.scene.paint.Color; import javafx.scene.paint.PhongMaterial; import javafx.scene.shape.*; import javafx.stage.Stage; import javafx.util.Duration; public class NoSizeTest extends Application { private Shape3D shape3d; private Box box; private Cylinder cylinder; private Sphere sphere; private Group root, shapeGroup; private PhongMaterial material; private RotateTransition rotTrans; private PerspectiveCamera addCamera(Scene scene) { PerspectiveCamera perspectiveCamera = new PerspectiveCamera(); scene.setCamera(perspectiveCamera); return perspectiveCamera; } @Override public void start(Stage primaryStage) { material = new PhongMaterial(); material.setDiffuseColor(Color.GOLD); material.setSpecularColor(Color.rgb(30, 30, 30)); shape3d = new Box(0, 0, 0); shape3d.setMaterial(material); shape3d.setTranslateX(100); shape3d.setTranslateY(400); shape3d.setTranslateZ(50); box = new Box(0, 0, 0); box.setMaterial(material); box.setTranslateX(300); box.setTranslateY(400); box.setTranslateZ(50); cylinder = new Cylinder(0, 0); cylinder.setMaterial(material); cylinder.setTranslateX(500); cylinder.setTranslateY(400); cylinder.setTranslateZ(50); sphere = new Sphere(0); sphere.setMaterial(material); sphere.setTranslateX(700); sphere.setTranslateY(400); sphere.setTranslateZ(50); AmbientLight ambientLight = new AmbientLight(Color.ANTIQUEWHITE); shapeGroup = new Group(shape3d, box, cylinder, sphere); root = new Group(shapeGroup, ambientLight); rotTrans = new RotateTransition(Duration.seconds(35), shapeGroup); // rotTrans.setAutoReverse(true); rotTrans.setAxis(new Point3D(2, 1, 0).normalize()); rotTrans.setInterpolator(Interpolator.EASE_BOTH); rotTrans.setCycleCount(Timeline.INDEFINITE); rotTrans.setByAngle(360); rotTrans.setDuration(Duration.seconds(5)); rotTrans.play(); Scene scene = new Scene(root, 800, 800, true); scene.setFill(Color.rgb(10, 10, 40)); scene.setOnKeyTyped(new EventHandler() { @Override public void handle(KeyEvent e) { switch (e.getCharacter()) { // Comment out until getBoundsInLocal() gets updated every time dimension changes. case "w": box.setWidth(box.getWidth() + 50); System.err.println("add width " + box.getWidth()); break; case "h": box.setHeight(box.getHeight() + 50); cylinder.setHeight(cylinder.getHeight() + 50); System.err.println("add height " + box.getHeight()); break; case "d": box.setDepth(box.getDepth() + 50); System.err.println("add depth " + box.getDepth()); break; case "r": System.err.println("add radius "); cylinder.setRadius(cylinder.getRadius() + 50); sphere.setRadius(sphere.getRadius() + 50); break; case "+": box.setWidth(box.getWidth() + 50); box.setDepth(box.getDepth() + 50); box.setHeight(box.getHeight() + 50); cylinder.setHeight(cylinder.getHeight() + 50); cylinder.setRadius(cylinder.getRadius() + 50); sphere.setRadius(sphere.getRadius() + 50); System.err.println("rise each dimension to " + box.getWidth()); break; case "-": box.setWidth(box.getWidth() - 50); box.setDepth(box.getDepth() - 50); box.setHeight(box.getHeight() + 50); cylinder.setHeight(cylinder.getHeight() - 50); cylinder.setRadius(cylinder.getRadius() - 50); sphere.setRadius(sphere.getRadius() - 50); System.err.println("reduce each dimension to " + box.getWidth()); break; // case "w": // box = new Box(box.getWidth() + 50, box.getHeight(), box.getDepth()); // System.err.println("add width " + box.getWidth()); // shapeGroup.getChildren().set(1, box); // break; // case "h": // box = new Box(box.getWidth(), box.getHeight() + 50, box.getDepth()); // cylinder = new Cylinder(cylinder.getRadius(), cylinder.getHeight() + 50); // System.err.println("add height " + box.getHeight()); // shapeGroup.getChildren().set(1, box); // shapeGroup.getChildren().set(2, cylinder); // break; // case "d": // box = new Box(box.getWidth(), box.getHeight(), box.getDepth() + 50); // System.err.println("add depth " + box.getDepth()); // shapeGroup.getChildren().set(1, box); // break; // case "r": // System.err.println("add radius "); // cylinder = new Cylinder(cylinder.getRadius() + 50, cylinder.getHeight()); // sphere = new Sphere(sphere.getRadius() + 50); // shapeGroup.getChildren().set(2, cylinder); // shapeGroup.getChildren().set(3, sphere); // break; // case "+": // box = new Box(box.getWidth() + 50, box.getHeight() + 50, box.getDepth() + 50); // cylinder = new Cylinder(cylinder.getRadius() + 50, cylinder.getHeight() + 50); // sphere = new Sphere(sphere.getRadius() + 50); // shapeGroup.getChildren().set(1, box); // shapeGroup.getChildren().set(2, cylinder); // shapeGroup.getChildren().set(3, sphere); // System.err.println("rise each dimension to " + box.getWidth()); // break; // case "-": // box = new Box(box.getWidth() - 50, box.getHeight() - 50, box.getDepth() - 50); // cylinder = new Cylinder(cylinder.getRadius() - 50, cylinder.getHeight() - 50); // sphere = new Sphere(sphere.getRadius() - 50); // shapeGroup.getChildren().set(1, box); // shapeGroup.getChildren().set(2, cylinder); // shapeGroup.getChildren().set(3, sphere); // System.err.println("reduce each dimension to " + box.getWidth()); // break; case "b": System.err.print("b "); shape3d = new Box(100, 100, 100); break; case "B": System.err.print("B "); shape3d = new Box(100, 100, 100); break; case "s": System.err.print("s "); shape3d = new Sphere(100); break; case "S": System.err.print("S "); shape3d = new Sphere(0); break; case "c": System.err.print("c "); shape3d = new Cylinder(25, 100); break; case "C": System.err.print("C "); shape3d = new Cylinder(0, 0); break; case "R": if (rotTrans.getStatus() == Timeline.Status.RUNNING) { rotTrans.pause(); } else { rotTrans.play(); } break; default: System.err.println("shape3d\t\t" + shape3d.getBoundsInLocal()); System.err.println("box\t\t" + box.getBoundsInLocal()); System.err.println("cylinder\t" + cylinder.getBoundsInLocal()); System.err.println("sphere\t\t" + sphere.getBoundsInLocal()); } shape3d.setMaterial(material); shape3d.setTranslateX(100); shape3d.setTranslateY(400); shape3d.setTranslateZ(50); shapeGroup.getChildren().set(0, shape3d); // Remove settings when getBoundsInLocal() gets updated every time dimension changes. // box.setMaterial(material); // // box.setTranslateX(300); // box.setTranslateY(400); // box.setTranslateZ(50); // // cylinder.setMaterial(material); // // cylinder.setTranslateX(500); // cylinder.setTranslateY(400); // cylinder.setTranslateZ(50); // // sphere.setMaterial(material); // // sphere.setTranslateX(700); // sphere.setTranslateY(400); // sphere.setTranslateZ(50); System.err.println("box\t\t" + box.getBoundsInLocal()); System.err.println("cylinder\t" + cylinder.getBoundsInLocal()); System.err.println("sphere\t\t" + sphere.getBoundsInLocal()); } }); addCamera(scene); primaryStage.setTitle("NoSizeTest"); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { System.setProperty("prism.dirtyopts", "false"); launch(args); } }