javafx.scene.PerspectiveCamera Java Examples
The following examples show how to use
javafx.scene.PerspectiveCamera.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MarsViewer.java From mars-sim with GNU General Public License v3.0 | 7 votes |
@Override public void start(Stage stage) { Group group = buildScene(); Scene scene = new Scene( new StackPane(group), VIEWPORT_SIZE, VIEWPORT_SIZE, true, SceneAntialiasing.BALANCED ); scene.setFill(Color.rgb(10, 10, 40)); scene.setCamera(new PerspectiveCamera()); stage.setScene(scene); stage.show(); stage.setFullScreen(true); rotateAroundYAxis(group).play(); }
Example #2
Source File: Skybox.java From FXyzLib with GNU General Public License v3.0 | 6 votes |
public Skybox(Image topImg, Image bottomImg, Image leftImg, Image rightImg, Image frontImg, Image backImg, double size, PerspectiveCamera camera) { super(); this.imageType = SkyboxImageType.MULTIPLE; this.topImg = topImg; this.bottomImg = bottomImg; this.leftImg = leftImg; this.rightImg = rightImg; this.frontImg = frontImg; this.backImg = backImg; this.size.set(size); this.camera = camera; loadImageViews(); getTransforms().add(affine); getChildren().addAll(views); startTimer(); }
Example #3
Source File: Drag3DObject.java From FXyzLib with GNU General Public License v3.0 | 6 votes |
private void loadCamera(Scene scene) { //initialize camera camera = new PerspectiveCamera(true); camera.setVerticalFieldOfView(RUN_JASON); //setup camera transform for rotational support cameraTransform.setTranslate(0, 0, 0); cameraTransform.getChildren().add(camera); camera.setNearClip(0.1); camera.setFarClip(100000.0); camera.setTranslateZ(-5000); cameraTransform.ry.setAngle(0.0); cameraTransform.rx.setAngle(-45.0); //add a Point Light for better viewing of the grid coordinate system PointLight light = new PointLight(Color.GAINSBORO); cameraTransform.getChildren().add(light); cameraTransform.getChildren().add(new AmbientLight(Color.WHITE)); light.setTranslateX(camera.getTranslateX()); light.setTranslateY(camera.getTranslateY()); light.setTranslateZ(camera.getTranslateZ()); //attach camera to scene scene.setCamera(camera); }
Example #4
Source File: FlipOutY.java From AnimateFX with Apache License 2.0 | 6 votes |
@Override void initTimeline() { getNode().getScene().setCamera(new PerspectiveCamera()); getNode().setRotationAxis(Y_AXIS); setTimeline(new Timeline( new KeyFrame(Duration.millis(0), new KeyValue(getNode().opacityProperty(), 1, AnimateFXInterpolator.EASE) ), new KeyFrame(Duration.millis(225), new KeyValue(getNode().rotateProperty(), 15, AnimateFXInterpolator.EASE) ), new KeyFrame(Duration.millis(750), new KeyValue(getNode().opacityProperty(), 0, AnimateFXInterpolator.EASE), new KeyValue(getNode().rotateProperty(), -90, AnimateFXInterpolator.EASE) ) )); getTimeline().setOnFinished(event -> getNode().getScene().setCamera(new ParallelCamera())); }
Example #5
Source File: FlipOutX.java From AnimateFX with Apache License 2.0 | 6 votes |
@Override void initTimeline() { getNode().getScene().setCamera(new PerspectiveCamera()); getNode().setRotationAxis(X_AXIS); setTimeline(new Timeline( new KeyFrame(Duration.millis(0), new KeyValue(getNode().opacityProperty(), 1, AnimateFXInterpolator.EASE) ), new KeyFrame(Duration.millis(225), new KeyValue(getNode().rotateProperty(), 20, AnimateFXInterpolator.EASE) ), new KeyFrame(Duration.millis(750), new KeyValue(getNode().opacityProperty(), 0, AnimateFXInterpolator.EASE), new KeyValue(getNode().rotateProperty(), -90, AnimateFXInterpolator.EASE) ) )); getTimeline().setOnFinished(event -> getNode().getScene().setCamera(new ParallelCamera())); }
Example #6
Source File: TilesDemo.java From mars-sim with GNU General Public License v3.0 | 5 votes |
@Override public void start(Stage stage) { FlowGridPane pane = new FlowGridPane(7, 5, percentageTile, clockTile, gaugeTile, sparkLineTile, areaChartTile, lineChartTile, timerControlTile, numberTile, textTile, highLowTile, plusMinusTile, sliderTile, switchTile, timeTile, barChartTile, customTile, leaderBoardTile, worldTile, mapTile, radialChartTile, donutChartTile, circularProgressTile, stockTile, gaugeSparkLineTile, radarChartTile1, radarChartTile2, smoothAreaChartTile, countryTile, ephemerisTile, characterTile, flipTile, switchSliderTile, dateTile, calendarTile);//, weatherTile); pane.setHgap(5); pane.setVgap(5); pane.setAlignment(Pos.CENTER); pane.setCenterShape(true); pane.setPadding(new Insets(5)); //pane.setPrefSize(800, 600); pane.setBackground(new Background(new BackgroundFill(Color.web("#101214"), CornerRadii.EMPTY, Insets.EMPTY))); PerspectiveCamera camera = new PerspectiveCamera(); camera.setFieldOfView(10); Scene scene = new Scene(pane); scene.setCamera(camera); stage.setTitle("TilesFX"); stage.setScene(scene); stage.show(); timer.start(); mapTile.addPoiLocation(new Location(51.85, 7.75, "Test")); mapTile.removePoiLocation(new Location(51.85, 7.75, "Test")); }
Example #7
Source File: Demo.java From Enzo with Apache License 2.0 | 5 votes |
@Override public void start(Stage stage) { StackPane pane = new StackPane(); pane.getChildren().addAll(control); Scene scene = new Scene(pane); scene.setCamera(new PerspectiveCamera(false)); stage.setScene(scene); stage.show(); timer.start(); }
Example #8
Source File: Skybox.java From FXyzLib with GNU General Public License v3.0 | 5 votes |
public Skybox(Image singleImg, double size, PerspectiveCamera camera) { super(); this.imageType = SkyboxImageType.SINGLE; this.singleImg = singleImg; this.size.set(size); this.camera = camera; getTransforms().add(affine); loadImageViews(); getChildren().addAll(views); }
Example #9
Source File: PeerInfoWithTagEditor.java From bisq with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void animateHide(Runnable onFinishedHandler) { if (GlobalSettings.getUseAnimations()) { double duration = getDuration(300); Interpolator interpolator = Interpolator.SPLINE(0.25, 0.1, 0.25, 1); gridPane.setRotationAxis(Rotate.X_AXIS); Camera camera = gridPane.getScene().getCamera(); gridPane.getScene().setCamera(new PerspectiveCamera()); Timeline timeline = new Timeline(); ObservableList<KeyFrame> keyFrames = timeline.getKeyFrames(); keyFrames.add(new KeyFrame(Duration.millis(0), new KeyValue(gridPane.rotateProperty(), 0, interpolator), new KeyValue(gridPane.opacityProperty(), 1, interpolator) )); keyFrames.add(new KeyFrame(Duration.millis(duration), new KeyValue(gridPane.rotateProperty(), -90, interpolator), new KeyValue(gridPane.opacityProperty(), 0, interpolator) )); timeline.setOnFinished(event -> { gridPane.setRotate(0); gridPane.setRotationAxis(Rotate.Z_AXIS); gridPane.getScene().setCamera(camera); onFinishedHandler.run(); }); timeline.play(); } else { onFinishedHandler.run(); } }
Example #10
Source File: Notification.java From bisq with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void animateHide(Runnable onFinishedHandler) { if (autoCloseTimer != null) { autoCloseTimer.stop(); autoCloseTimer = null; } if (NotificationCenter.useAnimations) { double duration = getDuration(400); Interpolator interpolator = Interpolator.SPLINE(0.25, 0.1, 0.25, 1); gridPane.setRotationAxis(Rotate.X_AXIS); Camera camera = gridPane.getScene().getCamera(); gridPane.getScene().setCamera(new PerspectiveCamera()); Timeline timeline = new Timeline(); ObservableList<KeyFrame> keyFrames = timeline.getKeyFrames(); keyFrames.add(new KeyFrame(Duration.millis(0), new KeyValue(gridPane.rotateProperty(), 0, interpolator), new KeyValue(gridPane.opacityProperty(), 1, interpolator) )); keyFrames.add(new KeyFrame(Duration.millis(duration), new KeyValue(gridPane.rotateProperty(), -90, interpolator), new KeyValue(gridPane.opacityProperty(), 0, interpolator) )); timeline.setOnFinished(event -> { gridPane.setRotate(0); gridPane.setRotationAxis(Rotate.Z_AXIS); gridPane.getScene().setCamera(camera); onFinishedHandler.run(); }); timeline.play(); } else { onFinishedHandler.run(); } }
Example #11
Source File: Snake3dApp.java From FXTutorials with MIT License | 5 votes |
private Scene createScene() { Cube cube = new Cube(Color.BLUE); snake.getChildren().add(cube); moveFood(); root.getChildren().addAll(snake, food); Scene scene = new Scene(root, 1280, 720, true); PerspectiveCamera camera = new PerspectiveCamera(true); camera.getTransforms().addAll(new Translate(0, -20, -20), new Rotate(-45, Rotate.X_AXIS)); scene.setCamera(camera); timer = new AnimationTimer() { @Override public void handle(long now) { t += 0.016; if (t > 0.1) { onUpdate(); t = 0; } } }; timer.start(); return scene; }
Example #12
Source File: ViewFrustum.java From paintera with GNU General Public License v2.0 | 5 votes |
public ViewFrustum(final PerspectiveCamera camera, final double[] screenSize) { this.screenSize = screenSize.clone(); this.tanHalfFov = new double[2]; final double widthToHeightRatio = screenSize[0] / screenSize[1]; final double halfFovMainDimension = Math.toRadians(camera.getFieldOfView() / 2); if (camera.isVerticalFieldOfView()) { tanHalfFov[1] = Math.tan(halfFovMainDimension); tanHalfFov[0] = tanHalfFov[1] * widthToHeightRatio; } else { tanHalfFov[0] = Math.tan(halfFovMainDimension); tanHalfFov[1] = tanHalfFov[0] / widthToHeightRatio; } final ViewFrustumPlane[] newNearFarPlanes = new ViewFrustumPlane[2]; final double[] clipValues = {camera.getNearClip(), camera.getFarClip()}; for (int i = 0; i < 2; ++i) { final double clipVal = clipValues[i]; final RealInterval viewPlane2D = viewPlaneAtGivenDistance(clipVal); newNearFarPlanes[i] = new ViewFrustumPlane(); newNearFarPlanes[i].minMin.setPosition(new double[] {viewPlane2D.realMin(0), viewPlane2D.realMin(1), clipVal}); newNearFarPlanes[i].minMax.setPosition(new double[] {viewPlane2D.realMin(0), viewPlane2D.realMax(1), clipVal}); newNearFarPlanes[i].maxMin.setPosition(new double[] {viewPlane2D.realMax(0), viewPlane2D.realMin(1), clipVal}); newNearFarPlanes[i].maxMax.setPosition(new double[] {viewPlane2D.realMax(0), viewPlane2D.realMax(1), clipVal}); } nearFarPlanes = new ViewFrustumPlanes( newNearFarPlanes[0], newNearFarPlanes[1] ); }
Example #13
Source File: TilesFxDemo.java From mars-sim with GNU General Public License v3.0 | 5 votes |
@Override public void start(Stage stage) { FlowGridPane pane = new FlowGridPane(7, 4, percentageTile, clockTile, gaugeTile, sparkLineTile, areaChartTile, lineChartTile, timerControlTile, numberTile, textTile, highLowTile, plusMinusTile, sliderTile, switchTile, timeTile, barChartTile, customTile, leaderBoardTile, worldTile, mapTile, radialChartTile, donutChartTile, circularProgressTile, stockTile, gaugeSparkLineTile, radarChartTile1, radarChartTile2, smoothAreaChartTile, countryTile, flipTile);// , weatherTile); pane.setHgap(5); pane.setVgap(5); pane.setAlignment(Pos.CENTER); pane.setCenterShape(true); pane.setPadding(new Insets(5)); // pane.setPrefSize(800, 600); pane.setBackground(new Background(new BackgroundFill(Color.web("#101214"), CornerRadii.EMPTY, Insets.EMPTY))); PerspectiveCamera camera = new PerspectiveCamera(); camera.setFieldOfView(7); Scene scene = new Scene(pane); scene.setCamera(camera); stage.setTitle("TilesFX"); stage.setScene(scene); stage.show(); timer.start(); mapTile.addPoiLocation(new Location(51.85, 7.75, "Test")); mapTile.removePoiLocation(new Location(51.85, 7.75, "Test")); }
Example #14
Source File: VirtualCameraDevice.java From BowlerStudio with GNU General Public License v3.0 | 5 votes |
public VirtualCameraDevice(PerspectiveCamera camera, Group hand){ this.hand = hand; this.setCamera(camera); setScriptingName("virtualCameraDevice"); //System.out.println("Setting camera frame transform"); manipulationFrame = new Group(); camera.getTransforms().add(zoomAffine); cameraFrame.getTransforms().add(getOffset()); manipulationFrame.getChildren().addAll(camera, hand); cameraFrame.getChildren().add(manipulationFrame); //new RuntimeException().printStackTrace(); setZoomDepth(DEFAULT_ZOOM_DEPTH); }
Example #15
Source File: Curbstone3D.java From SmartCity-ParkingManagement with Apache License 2.0 | 5 votes |
@Override public void start(final Stage s) throws Exception { s.setTitle("Curbstone 3D"); final Curbstone c = new Curbstone(50, Color.web("#DC143C"), 1); c.setTranslateX(0); c.rx.setAngle(25); c.ry.setAngle(45); final Timeline animation = new Timeline(); animation.getKeyFrames().addAll(new KeyFrame(Duration.ZERO, new KeyValue(c.ry.angleProperty(), 0d)), new KeyFrame(Duration.valueOf("20000ms"), new KeyValue(c.ry.angleProperty(), 360d))); animation.setCycleCount(Animation.INDEFINITE); // create root group final Parent root = c; // translate and rotate group so that origin is center and +Y is up root.setTranslateX(200); root.setTranslateY(75); final Line line = new Line(200, 200, 200, 200); final Rotate rotation = new Rotate(1, Rotate.Y_AXIS); rotation.pivotXProperty().bind(line.startXProperty()); rotation.pivotYProperty().bind(line.startYProperty()); root.getTransforms().add(rotation); // create scene final Scene scene = new Scene(root, 400, 150); scene.setCamera(new PerspectiveCamera()); s.setScene(scene); s.show(); // start spining animation animation.play(); }
Example #16
Source File: ViewFrustumTest.java From paintera with GNU General Public License v2.0 | 5 votes |
@Before public void setUp() { camera = new PerspectiveCamera(true); camera.setNearClip(0.1); camera.setFarClip(10.0); camera.setFieldOfView(45); camera.setVerticalFieldOfView(true); frustumCamera = new ViewFrustum(camera, new double[] {800, 600}); cameraTransform = new AffineTransform3D(); cameraTransform.setTranslation(0, 0, -1); sceneTransform = new AffineTransform3D(); sceneTransform.set( -1.9735242914056459E-4, -1.0436920839427981E-4, -2.061953312972022E-4, 3.0306137875177632, -1.2649862727035413E-4, -1.7813723813362014E-4, 2.11240737752298E-4, 0.956379113095983, -1.9341029860978865E-4, 2.2300587509429097E-4, 7.223755022420857E-5, -1.1240682338705246 ); sourceToWorldTransform = new AffineTransform3D(); sourceToWorldTransform.set( 64.0, 0.0, 0.0, 3674.0, 0.0, 64.0, 0.0, 3674.0, 0.0, 0.0, 80.0, 1540.0 ); }
Example #17
Source File: FlipInY.java From AnimateFX with Apache License 2.0 | 5 votes |
@Override void initTimeline() { getNode().getScene().setCamera(new PerspectiveCamera()); getNode().setRotationAxis(Y_AXIS); setTimeline(new Timeline( new KeyFrame(Duration.millis(0), new KeyValue(getNode().opacityProperty(), 0, Interpolator.EASE_IN), new KeyValue(getNode().rotateProperty(), -90, Interpolator.EASE_IN) ), new KeyFrame(Duration.millis(400), new KeyValue(getNode().rotateProperty(), 20, Interpolator.EASE_IN) ), new KeyFrame(Duration.millis(600), new KeyValue(getNode().rotateProperty(), -10, Interpolator.EASE_IN) ), new KeyFrame(Duration.millis(800), new KeyValue(getNode().rotateProperty(), 5, Interpolator.EASE_IN) ), new KeyFrame(Duration.millis(1000), new KeyValue(getNode().opacityProperty(), 1, Interpolator.EASE_IN), new KeyValue(getNode().rotateProperty(), 0, Interpolator.EASE_IN) ) )); getTimeline().setOnFinished(event -> getNode().getScene().setCamera(new ParallelCamera())); }
Example #18
Source File: AudioVisualizer3D.java From netbeans with Apache License 2.0 | 5 votes |
private void init(Stage primaryStage) { Group root = new Group(); root.setDepthTest(DepthTest.ENABLE); primaryStage.setResizable(false); primaryStage.setScene(new Scene(root, 400, 500, true)); primaryStage.getScene().setCamera(new PerspectiveCamera()); root.getTransforms().addAll( new Translate(400 / 2, 500 / 2 + 100), new Rotate(180, Rotate.X_AXIS) ); root.getChildren().add(create3dContent()); }
Example #19
Source File: CubeSystem3D.java From netbeans with Apache License 2.0 | 5 votes |
private void init(Stage primaryStage) { Group root = new Group(); root.setDepthTest(DepthTest.ENABLE); primaryStage.setResizable(false); primaryStage.setScene(new Scene(root, 500, 500, true)); primaryStage.getScene().setCamera(new PerspectiveCamera()); root.getTransforms().addAll( new Translate(500 / 2, 500 / 2), new Rotate(180, Rotate.X_AXIS) ); root.getChildren().add(create3dContent()); }
Example #20
Source File: FlipInX.java From AnimateFX with Apache License 2.0 | 5 votes |
@Override void initTimeline() { getNode().getScene().setCamera(new PerspectiveCamera()); getNode().setRotationAxis(X_AXIS); setTimeline(new Timeline( new KeyFrame(Duration.millis(0), new KeyValue(getNode().opacityProperty(), 0, Interpolator.EASE_IN), new KeyValue(getNode().rotateProperty(), -90, Interpolator.EASE_IN) ), new KeyFrame(Duration.millis(400), new KeyValue(getNode().rotateProperty(), 20, Interpolator.EASE_IN) ), new KeyFrame(Duration.millis(600), new KeyValue(getNode().rotateProperty(), -10, Interpolator.EASE_IN) ), new KeyFrame(Duration.millis(800), new KeyValue(getNode().rotateProperty(), 5, Interpolator.EASE_IN) ), new KeyFrame(Duration.millis(1000), new KeyValue(getNode().opacityProperty(), 1, Interpolator.EASE_IN), new KeyValue(getNode().rotateProperty(), 0, Interpolator.EASE_IN) ) )); getTimeline().setOnFinished(event -> getNode().getScene().setCamera(new ParallelCamera())); }
Example #21
Source File: Flip.java From AnimateFX with Apache License 2.0 | 5 votes |
@Override void initTimeline() { getNode().getScene().setCamera(new PerspectiveCamera()); getNode().setRotationAxis(Y_AXIS); setTimeline(new Timeline( new KeyFrame(Duration.millis(0), new KeyValue(getNode().rotateProperty(), 360, Interpolator.EASE_OUT) ), new KeyFrame(Duration.millis(400), new KeyValue(getNode().rotateProperty(), 190, Interpolator.EASE_OUT), new KeyValue(getNode().translateZProperty(), -150, Interpolator.EASE_OUT) ), new KeyFrame(Duration.millis(500), new KeyValue(getNode().rotateProperty(), 170, Interpolator.EASE_IN), new KeyValue(getNode().translateZProperty(), -150, Interpolator.EASE_IN) ), new KeyFrame(Duration.millis(800), new KeyValue(getNode().scaleXProperty(), 0.95, Interpolator.EASE_IN), new KeyValue(getNode().scaleYProperty(), 0.95, Interpolator.EASE_IN), new KeyValue(getNode().scaleZProperty(), 0.95, Interpolator.EASE_IN) ), new KeyFrame(Duration.millis(1000), new KeyValue(getNode().rotateProperty(), 0, Interpolator.EASE_IN), new KeyValue(getNode().scaleXProperty(), 1, Interpolator.EASE_IN), new KeyValue(getNode().scaleYProperty(), 1, Interpolator.EASE_IN), new KeyValue(getNode().scaleZProperty(), 1, Interpolator.EASE_IN), new KeyValue(getNode().translateZProperty(), 0, Interpolator.EASE_IN) ) )); //TODO getTimeline().setOnFinished(event -> getNode().getScene().setCamera(new ParallelCamera())); }
Example #22
Source File: Cube3D.java From netbeans with Apache License 2.0 | 5 votes |
private void init(Stage primaryStage) { Group root = new Group(); root.setDepthTest(DepthTest.ENABLE); primaryStage.setResizable(false); primaryStage.setScene(new Scene(root, 400, 150, true)); primaryStage.getScene().setCamera(new PerspectiveCamera()); root.getTransforms().addAll( new Translate(400 / 2, 150 / 2), new Rotate(180, Rotate.X_AXIS) ); root.getChildren().add(create3dContent()); }
Example #23
Source File: PolyLine3DTest.java From FXyzLib with GNU General Public License v3.0 | 4 votes |
@Override public void start(Stage primaryStage) throws Exception { Group sceneRoot = new Group(); Scene scene = new Scene(sceneRoot, sceneWidth, sceneHeight, true, SceneAntialiasing.BALANCED); scene.setFill(Color.BLACK); camera = new PerspectiveCamera(true); camera.setNearClip(0.1); camera.setFarClip(10000.0); camera.setTranslateZ(-1000); scene.setCamera(camera); ArrayList<Point3D> points = new ArrayList<>(); for(int i=-250;i<250;i++) { points.add(new Point3D( (float) i, (float) Math.sin(i)*50+i, (float) Math.cos(i)*50+i)); } polyLine3D = new PolyLine3D(points,3,Color.STEELBLUE); sceneRoot.getChildren().addAll(polyLine3D); scene.setOnKeyPressed(event -> { double change = 10.0; //Add shift modifier to simulate "Running Speed" if(event.isShiftDown()) { change = 50.0; } //What key did the user press? KeyCode keycode = event.getCode(); //Step 2c: Add Zoom controls if(keycode == KeyCode.W) { camera.setTranslateZ(camera.getTranslateZ() + change); } if(keycode == KeyCode.S) { camera.setTranslateZ(camera.getTranslateZ() - change); } //Step 2d: Add Strafe controls if(keycode == KeyCode.A) { camera.setTranslateX(camera.getTranslateX() - change); } if(keycode == KeyCode.D) { camera.setTranslateX(camera.getTranslateX() + change); } }); //Add a Mouse Handler for Rotations Rotate xRotate = new Rotate(0, Rotate.X_AXIS); Rotate yRotate = new Rotate(0, Rotate.Y_AXIS); Rotate zRotate = new Rotate(0, Rotate.Z_AXIS); polyLine3D.getTransforms().addAll(xRotate, yRotate); //Use Binding so your rotation doesn't have to be recreated xRotate.angleProperty().bind(angleX); yRotate.angleProperty().bind(angleY); zRotate.angleProperty().bind(angleZ); //Start Tracking mouse movements only when a button is pressed scene.setOnMousePressed(event -> { scenex = event.getSceneX(); sceney = event.getSceneY(); fixedXAngle = angleX.get(); fixedYAngle = angleY.get(); if(event.isMiddleButtonDown()) { scenez = event.getSceneX(); fixedZAngle = angleZ.get(); } }); //Angle calculation will only change when the button has been pressed scene.setOnMouseDragged(event -> { if(event.isMiddleButtonDown()) angleZ.set(fixedZAngle - (scenez - event.getSceneY())); else angleX.set(fixedXAngle - (scenex - event.getSceneY())); angleY.set(fixedYAngle + sceney - event.getSceneX()); }); primaryStage.setTitle("F(X)yz ScatterPlotTest"); primaryStage.setScene(scene); primaryStage.show(); }
Example #24
Source File: Viewer3DFX.java From paintera with GNU General Public License v2.0 | 4 votes |
public Viewer3DFX(final double width, final double height) { super(); this.root = new Group(); this.sceneGroup = new Group(); this.meshesGroup = new Group(); sceneGroup.getChildren().add(meshesGroup); this.setWidth(width); this.setHeight(height); this.scene = new SubScene(root, width, height, true, SceneAntialiasing.BALANCED); this.scene.fillProperty().bind(backgroundFill); this.camera = new PerspectiveCamera(true); this.camera.setNearClip(0.01); this.camera.setFarClip(10.0); this.camera.setTranslateY(0); this.camera.setTranslateX(0); this.camera.setTranslateZ(0); this.camera.setFieldOfView(90); this.scene.setCamera(this.camera); this.cameraGroup = new Group(); this.getChildren().add(this.scene); this.root.getChildren().addAll(cameraGroup, sceneGroup); this.scene.widthProperty().bind(widthProperty()); this.scene.heightProperty().bind(heightProperty()); lightSpot.setTranslateX(-10); lightSpot.setTranslateY(-10); lightSpot.setTranslateZ(-10); lightFill.setTranslateX(10); this.cameraGroup.getChildren().addAll(camera, lightAmbient, lightSpot, lightFill); this.cameraGroup.getTransforms().add(cameraTransform); this.handler = new Scene3DHandler(this); this.root.visibleProperty().bind(this.meshesEnabled); final AffineTransform3D cameraAffineTransform = Transforms.fromTransformFX(cameraTransform); this.handler.addAffineListener(sceneTransform -> { final AffineTransform3D sceneToWorldTransform = Transforms.fromTransformFX(sceneTransform).inverse(); eyeToWorldTransformProperty.set(sceneToWorldTransform.concatenate(cameraAffineTransform)); }); final InvalidationListener sizeChangedListener = obs -> viewFrustumProperty.set( new ViewFrustum(camera, new double[] {getWidth(), getHeight()}) ); widthProperty().addListener(sizeChangedListener); heightProperty().addListener(sizeChangedListener); // set initial value sizeChangedListener.invalidated(null); }
Example #25
Source File: BillBoardBehaviorTest.java From FXyzLib with GNU General Public License v3.0 | 4 votes |
private void createSubscene(){ subScene = new SubScene(root, 800, 600, true, SceneAntialiasing.BALANCED); camera = new PerspectiveCamera(true); cameraTransform.setTranslate(0, 0, 0); cameraTransform.getChildren().addAll(camera); camera.setNearClip(0.1); camera.setFarClip(100000.0); camera.setFieldOfView(35); camera.setTranslateZ(-cameraDistance); cameraTransform.ry.setAngle(-45.0); cameraTransform.rx.setAngle(-10.0); //add a Point Light for better viewing of the grid coordinate system PointLight light = new PointLight(Color.WHITE); cameraTransform.getChildren().add(light); light.setTranslateX(camera.getTranslateX()); light.setTranslateY(camera.getTranslateY()); light.setTranslateZ(camera.getTranslateZ()); root.getChildren().add(cameraTransform); subScene.setCamera(camera); initFirstPersonControls(subScene); skyBox = new Skybox(new Image("http://www.zfight.com/misc/images/textures/envmaps/violentdays_large.jpg"), 100000, camera); //Make a bunch of semi random Torusesessses(toroids?) and stuff : from torustest Group torusGroup = new Group(); for (int i = 0; i < 10; i++) { Random r = new Random(); //A lot of magic numbers in here that just artificially constrain the math float randomRadius = (float) ((r.nextFloat() * 300) + 50); float randomTubeRadius = (float) ((r.nextFloat() * 100) + 1); int randomTubeDivisions = (int) ((r.nextFloat() * 64) + 1); int randomRadiusDivisions = (int) ((r.nextFloat() * 64) + 1); Color randomColor = new Color(r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble()); boolean ambientRandom = r.nextBoolean(); boolean fillRandom = r.nextBoolean(); if(i == 0){ torusGroup.getChildren().add(bill); } TorusMesh torus = new TorusMesh(randomTubeDivisions, randomRadiusDivisions, randomRadius, randomTubeRadius); double translationX = Math.random() * 1024 * 1.95; if (Math.random() >= 0.5) { translationX *= -1; } double translationY = Math.random() * 1024 * 1.95; if (Math.random() >= 0.5) { translationY *= -1; } double translationZ = Math.random() * 1024 * 1.95; if (Math.random() >= 0.5) { translationZ *= -1; } Translate translate = new Translate(translationX, translationY, translationZ); Rotate rotateX = new Rotate(Math.random() * 360, Rotate.X_AXIS); Rotate rotateY = new Rotate(Math.random() * 360, Rotate.Y_AXIS); Rotate rotateZ = new Rotate(Math.random() * 360, Rotate.Z_AXIS); torus.getTransforms().addAll(translate, rotateX, rotateY, rotateZ); //torus.getTransforms().add(translate); torusGroup.getChildren().add(torus); } root.getChildren().addAll(skyBox, torusGroup); rootPane.getChildren().add(subScene); //Enable subScene resizing subScene.widthProperty().bind(rootPane.widthProperty()); subScene.heightProperty().bind(rootPane.heightProperty()); subScene.setFocusTraversable(true); }
Example #26
Source File: SpheroidTest.java From FXyzLib with GNU General Public License v3.0 | 4 votes |
@Override public void start(Stage stage) { Group spheroidGroup = new Group(); for (int i = 0; i < 50; i++) { Random r = new Random(); //A lot of magic numbers in here that just artificially constrain the math float randomMajorRadius = (float) ((r.nextFloat() * 300) + 50); float randomMinorRadius = (float) ((r.nextFloat() * 300) + 50); int randomDivisions = (int) ((r.nextFloat() * 64) + 1); Color randomColor = new Color(r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble()); Spheroid sm = new Spheroid(randomDivisions, randomMajorRadius, randomMinorRadius, randomColor); sm.setDrawMode(DrawMode.LINE); double translationX = Math.random() * 1024 * 1.95; if (Math.random() >= 0.5) { translationX *= -1; } double translationY = Math.random() * 1024 * 1.95; if (Math.random() >= 0.5) { translationY *= -1; } double translationZ = Math.random() * 1024 * 1.95; if (Math.random() >= 0.5) { translationZ *= -1; } Translate translate = new Translate(translationX, translationY, translationZ); Rotate rotateX = new Rotate(Math.random() * 360, Rotate.X_AXIS); Rotate rotateY = new Rotate(Math.random() * 360, Rotate.Y_AXIS); Rotate rotateZ = new Rotate(Math.random() * 360, Rotate.Z_AXIS); sm.getTransforms().addAll(translate, rotateX, rotateY, rotateZ); spheroidGroup.getChildren().add(sm); } root.getChildren().add(spheroidGroup); System.out.println(spheroidGroup.getChildren().size()); camera = new PerspectiveCamera(true); cameraTransform.setTranslate(0, 0, 0); cameraTransform.getChildren().addAll(camera); camera.setNearClip(0.1); camera.setFarClip(10000.0); camera.setFieldOfView(42); camera.setTranslateZ(cameraDistance); cameraTransform.ry.setAngle(-45.0); cameraTransform.rx.setAngle(-10.0); //add a Point Light for better viewing of the grid coordinate system PointLight light = new PointLight(Color.WHITE); cameraTransform.getChildren().add(light); light.setTranslateX(camera.getTranslateX()); light.setTranslateY(camera.getTranslateY()); light.setTranslateZ(camera.getTranslateZ()); root.getChildren().add(cameraTransform); Scene scene = new Scene(new StackPane(root), 1024, 668, true, SceneAntialiasing.BALANCED); scene.setCamera(camera); scene.setFill(Color.BLACK); initFirstPersonControls(scene); stage.setTitle("Hello World!"); stage.setScene(scene); stage.show(); }
Example #27
Source File: SurfacePlotTest.java From FXyzLib with GNU General Public License v3.0 | 4 votes |
@Override public void start(Stage primaryStage) throws Exception { Group sceneRoot = new Group(); Scene scene = new Scene(sceneRoot, sceneWidth, sceneHeight, true, SceneAntialiasing.BALANCED); scene.setFill(Color.BLACK); camera = new PerspectiveCamera(true); camera.setNearClip(0.1); camera.setFarClip(10000.0); camera.setTranslateZ(-1000); scene.setCamera(camera); int size = 10; float [][] arrayY = new float[2*size][2*size]; //The Sombrero for(int i=-size;i<size;i++) { for(int j=-size;j<size;j++) { double R = Math.sqrt((i * i) + (j * j)) + 0.00000000000000001; arrayY[i+size][j+size] = ((float) -(Math.sin(R)/R)) * 100; } } surfacePlot = new SurfacePlot(arrayY, 10, Color.AQUA, false, false); sceneRoot.getChildren().addAll(surfacePlot); PointLight light = new PointLight(Color.WHITE); sceneRoot.getChildren().add(light); light.setTranslateZ(sceneWidth / 2); light.setTranslateY(-sceneHeight + 10); PointLight light2 = new PointLight(Color.WHITE); sceneRoot.getChildren().add(light2); light2.setTranslateZ(-sceneWidth + 10); light2.setTranslateY(-sceneHeight + 10); scene.setOnKeyPressed(event -> { double change = 10.0; //Add shift modifier to simulate "Running Speed" if(event.isShiftDown()) { change = 50.0; } //What key did the user press? KeyCode keycode = event.getCode(); //Step 2c: Add Zoom controls if(keycode == KeyCode.W) { camera.setTranslateZ(camera.getTranslateZ() + change); } if(keycode == KeyCode.S) { camera.setTranslateZ(camera.getTranslateZ() - change); } //Step 2d: Add Strafe controls if(keycode == KeyCode.A) { camera.setTranslateX(camera.getTranslateX() - change); } if(keycode == KeyCode.D) { camera.setTranslateX(camera.getTranslateX() + change); } }); //Add a Mouse Handler for Rotations Rotate xRotate = new Rotate(0, Rotate.X_AXIS); Rotate yRotate = new Rotate(0, Rotate.Y_AXIS); Rotate zRotate = new Rotate(0, Rotate.Z_AXIS); surfacePlot.getTransforms().addAll(xRotate, yRotate, zRotate); //Use Binding so your rotation doesn't have to be recreated xRotate.angleProperty().bind(angleX); yRotate.angleProperty().bind(angleY); zRotate.angleProperty().bind(angleZ); //Start Tracking mouse movements only when a button is pressed scene.setOnMousePressed(event -> { scenex = event.getSceneX(); sceney = event.getSceneY(); fixedXAngle = angleX.get(); fixedYAngle = angleY.get(); if(event.isMiddleButtonDown()) { scenez = event.getSceneX(); fixedZAngle = angleZ.get(); } }); //Angle calculation will only change when the button has been pressed scene.setOnMouseDragged(event -> { if(event.isMiddleButtonDown()) angleZ.set(fixedZAngle - (scenez - event.getSceneY())); else angleX.set(fixedXAngle - (scenex - event.getSceneY())); angleY.set(fixedYAngle + sceney - event.getSceneX()); }); primaryStage.setTitle("F(X)yz SurfacePlotTest"); primaryStage.setScene(scene); primaryStage.show(); }
Example #28
Source File: ScatterPlotMeshTest.java From FXyzLib with GNU General Public License v3.0 | 4 votes |
@Override public void start(Stage primaryStage) throws Exception { Group sceneRoot = new Group(); Scene scene = new Scene(sceneRoot, sceneWidth, sceneHeight, true, SceneAntialiasing.BALANCED); scene.setFill(Color.BLACK); camera = new PerspectiveCamera(true); camera.setNearClip(0.1); camera.setFarClip(10000.0); camera.setTranslateZ(-1000); scene.setCamera(camera); scatterPlotMesh = new ScatterPlotMesh(1000, 1, true); sceneRoot.getChildren().addAll(scatterPlotMesh); ArrayList<Double> dataX = new ArrayList<>(); ArrayList<Double> dataY = new ArrayList<>(); ArrayList<Double> dataZ = new ArrayList<>(); for(int i=-250;i<250;i++) { dataX.add(new Double(i)); dataY.add(new Double(Math.sin(i)*50)+i); dataZ.add(new Double(Math.cos(i)*50)+i); } scatterPlotMesh.setXYZData(dataX, dataY, dataZ); scene.setOnKeyPressed(event -> { double change = 10.0; //Add shift modifier to simulate "Running Speed" if(event.isShiftDown()) { change = 50.0; } //What key did the user press? KeyCode keycode = event.getCode(); //Step 2c: Add Zoom controls if(keycode == KeyCode.W) { camera.setTranslateZ(camera.getTranslateZ() + change); } if(keycode == KeyCode.S) { camera.setTranslateZ(camera.getTranslateZ() - change); } //Step 2d: Add Strafe controls if(keycode == KeyCode.A) { camera.setTranslateX(camera.getTranslateX() - change); } if(keycode == KeyCode.D) { camera.setTranslateX(camera.getTranslateX() + change); } }); //Add a Mouse Handler for Rotations Rotate xRotate = new Rotate(0, Rotate.X_AXIS); Rotate yRotate = new Rotate(0, Rotate.Y_AXIS); Rotate zRotate = new Rotate(0, Rotate.Z_AXIS); scatterPlotMesh.getTransforms().addAll(xRotate, yRotate); //Use Binding so your rotation doesn't have to be recreated xRotate.angleProperty().bind(angleX); yRotate.angleProperty().bind(angleY); zRotate.angleProperty().bind(angleZ); //Start Tracking mouse movements only when a button is pressed scene.setOnMousePressed(event -> { scenex = event.getSceneX(); sceney = event.getSceneY(); fixedXAngle = angleX.get(); fixedYAngle = angleY.get(); if(event.isMiddleButtonDown()) { scenez = event.getSceneX(); fixedZAngle = angleZ.get(); } }); //Angle calculation will only change when the button has been pressed scene.setOnMouseDragged(event -> { if(event.isMiddleButtonDown()) angleZ.set(fixedZAngle - (scenez - event.getSceneY())); else angleX.set(fixedXAngle - (scenex - event.getSceneY())); angleY.set(fixedYAngle + sceney - event.getSceneX()); }); primaryStage.setTitle("F(X)yz ScatterPlotTest"); primaryStage.setScene(scene); primaryStage.show(); }
Example #29
Source File: ScatterPlotColorTest.java From FXyzLib with GNU General Public License v3.0 | 4 votes |
@Override public void start(Stage primaryStage) throws Exception { Group sceneRoot = new Group(); Scene scene = new Scene(sceneRoot, sceneWidth, sceneHeight, true, SceneAntialiasing.BALANCED); scene.setFill(Color.BLACK); camera = new PerspectiveCamera(true); camera.setNearClip(0.1); camera.setFarClip(10000.0); camera.setTranslateZ(-1000); scene.setCamera(camera); scatterPlot = new ScatterPlot(1000, 1, true); sceneRoot.getChildren().addAll(scatterPlot); List<Double> dataX = new ArrayList<>(); List<Double> dataY = new ArrayList<>(); List<Double> dataZ = new ArrayList<>(); List<Color> colors = new ArrayList<>(); int k = 0; for(int i=-250;i<250;i++) { dataX.add(new Double(i)); dataY.add(Math.sin(i)*50+i); dataZ.add(Math.cos(i)*50+i); colors.add(new Color(Math.abs(i) / 250D, Math.abs(dataY.get(k)) / 300D, Math.abs(dataZ.get(k) / 300D), 0.25)); k++; } scatterPlot.setXYZData(dataX, dataY, dataZ, colors); scene.setOnKeyPressed(event -> { double change = 10.0; //Add shift modifier to simulate "Running Speed" if(event.isShiftDown()) { change = 50.0; } //What key did the user press? KeyCode keycode = event.getCode(); //Step 2c: Add Zoom controls if(keycode == KeyCode.W) { camera.setTranslateZ(camera.getTranslateZ() + change); } if(keycode == KeyCode.S) { camera.setTranslateZ(camera.getTranslateZ() - change); } //Step 2d: Add Strafe controls if(keycode == KeyCode.A) { camera.setTranslateX(camera.getTranslateX() - change); } if(keycode == KeyCode.D) { camera.setTranslateX(camera.getTranslateX() + change); } }); //Add a Mouse Handler for Rotations Rotate xRotate = new Rotate(0, Rotate.X_AXIS); Rotate yRotate = new Rotate(0, Rotate.Y_AXIS); Rotate zRotate = new Rotate(0, Rotate.Z_AXIS); scatterPlot.getTransforms().addAll(xRotate, yRotate); //Use Binding so your rotation doesn't have to be recreated xRotate.angleProperty().bind(angleX); yRotate.angleProperty().bind(angleY); zRotate.angleProperty().bind(angleZ); //Start Tracking mouse movements only when a button is pressed scene.setOnMousePressed(event -> { scenex = event.getSceneX(); sceney = event.getSceneY(); fixedXAngle = angleX.get(); fixedYAngle = angleY.get(); if(event.isMiddleButtonDown()) { scenez = event.getSceneX(); fixedZAngle = angleZ.get(); } }); //Angle calculation will only change when the button has been pressed scene.setOnMouseDragged(event -> { if(event.isMiddleButtonDown()) angleZ.set(fixedZAngle - (scenez - event.getSceneY())); else angleX.set(fixedXAngle - (scenex - event.getSceneY())); angleY.set(fixedYAngle + sceney - event.getSceneX()); }); primaryStage.setTitle("F(X)yz ScatterPlotColorTest"); primaryStage.setScene(scene); primaryStage.show(); }
Example #30
Source File: CameraView.java From FXyzLib with GNU General Public License v3.0 | 4 votes |
public PerspectiveCamera getCamera() { return camera; }