/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package picking; import javafx.application.Application; import javafx.event.EventHandler; import javafx.scene.Camera; import javafx.scene.Group; import javafx.scene.PerspectiveCamera; import javafx.scene.Scene; import javafx.scene.input.KeyEvent; import javafx.scene.input.MouseEvent; import javafx.scene.shape.Sphere; import javafx.stage.Stage; /** * * @author Andrew Glushchenko */ public class ScenePickingTestApp extends Application { Group root; Camera camera; private static int DISTANCE = 500; @Override public void start(Stage stage) throws Exception { Sphere s = new Sphere(50); root = new Group(s); Scene scene = new Scene(root, 500, 500); camera = new PerspectiveCamera(); scene.setCamera(camera); scene.setOnKeyPressed(new EventHandler() { @Override public void handle(KeyEvent t) { System.out.println(t.getText()); switch (t.getText()) { case "g": camera.setTranslateZ(0); root.setTranslateZ(DISTANCE); break; case "c": camera.setTranslateZ(-DISTANCE); root.setTranslateZ(0); break; } } }); scene.setOnMouseClicked(new EventHandler() { @Override public void handle(MouseEvent t) { System.out.println(t.getPickResult().getIntersectedPoint()); } }); stage.setScene(scene); stage.show(); } public static void main(String[] args) { launch(args); } }