JavaFX 3D Tutorial #2 – Camera Systems – Genuine Coder

JavaFX 3D Tutorial #2 – Camera Systems

By default, JavaFX provides a camera that allows to view the world from the negative z position. When we have to look at the world from our own angle, we need a custom camera.

JavaFX camera component extends javafx.scene.Node. It can be added to the scene graph just like any other JavaFX components. We have 2 different cameras available.

1: Parallel Camera

Parallel Camera always render the objects in same size. This camera defines a viewing volume for a parallel (orthographic) projection; a rectangular box. This camera is always located at center of the window and looks along the positive z-axis. It is not really useful when you want to look at the objects from a certain point.

ParallelCamera camera = new ParallelCamera();
//..Attach to scene
scene.setCamera(camera);

2: Perspective Camera

This camera allows to look at the object from a point. As per the documentation,
“This camera defines a viewing volume for a perspective projection; a truncated right pyramid. The fieldOfView value can be used to change viewing volume. This camera is always located at center of the scene and looks along the positive z-axis. The coordinate system defined by this camera has its origin in the upper left corner of the panel with the Y-axis pointing down and the Z axis pointing away from the viewer (into the screen).”

It has two constructors

  • PerspectiveCamera()
  • PerspectiveCamera(boolean fixedEyeAtCameraZero)

If fixedEyeAtCameraZero is true, the eye position is fixed at (0, 0, 0) in the local coordinates of the camera. A fixedEyeAtCameraZero as true guarantees that after the eye of the PerspectiveCamera moves along with it, and remains at the camera’s zero position.

PerspectiveCamera camera = new PerspectiveCamera(true);
//..Attach to scene
scene.setCamera(camera);

Field of View

Field of view defines how much we can see in the 3D scene. A larger field of view angles provides a wider view –> you can see more things. This can be set as

 
camera.setFieldOfView(double value);

Clipping Planes

Clipping planes allows to defines that part of the 3D world that we are interested to see. Anything closer to the eye than the near clipping distance isn’t displayed (it’s too close), and anything further away from the eye than the far clipping distance isn’t displayed either (it’s too far away).

 
 camera.setNearClip(double value);
 camera.setFarClip(double value);

Example Code


import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.input.KeyEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Sphere;
import javafx.stage.Stage;

/**
 * @author afsal villan
 * @version 1.0
 *
 * https://genuinecoder.com
 */
public class Camera3D extends Application {
    private static final int WIDTH = 1400;
    private static final int HEIGHT = 800;

    @Override
    public void start(Stage primaryStage) throws Exception {
        Sphere sphere = new Sphere(50);

        Group group = new Group();
        group.getChildren().add(sphere);

        //Create new Camera
        Camera camera = new PerspectiveCamera(true);
        Scene scene = new Scene(group, WIDTH, HEIGHT);
        scene.setFill(Color.SILVER);
        //Attach to scene
        scene.setCamera(camera);

        //Move back a little to get a good view of the sphere
        camera.translateZProperty().set(-500);

        //Set the clipping planes
        camera.setNearClip(1);
        camera.setFarClip(1000);

        primaryStage.addEventHandler(KeyEvent.KEY_PRESSED, event -> {
            switch (event.getCode()) {
                case W:
                    camera.translateZProperty().set(camera.getTranslateZ() + 100);
                    break;
                case S:
                    camera.translateZProperty().set(camera.getTranslateZ() - 100);
                    break;
            }
        });

        primaryStage.setTitle("Genuine Coder");
        primaryStage.setScene(scene);
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }
}

 

Visit JavaFX 3D Course Index Page

Comments

52 responses to “JavaFX 3D Tutorial #2 – Camera Systems”

  1. … [Trackback]

    […] Here you will find 30106 more Information to that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  2. … [Trackback]

    […] Find More here on that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  3. … [Trackback]

    […] Find More Information here to that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  4. … [Trackback]

    […] Find More on that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  5. … [Trackback]

    […] Read More Info here on that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  6. … [Trackback]

    […] Read More on that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  7. … [Trackback]

    […] Here you can find 52638 additional Info on that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  8. … [Trackback]

    […] Here you will find 53674 more Information on that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  9. … [Trackback]

    […] Read More here to that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  10. … [Trackback]

    […] Information to that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  11. … [Trackback]

    […] Read More on that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  12. … [Trackback]

    […] Here you will find 67685 more Info to that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  13. … [Trackback]

    […] Find More Info here to that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  14. … [Trackback]

    […] Here you can find 57765 more Information on that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  15. … [Trackback]

    […] Read More on to that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  16. … [Trackback]

    […] Here you will find 4719 additional Information on that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  17. … [Trackback]

    […] Find More on on that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  18. … [Trackback]

    […] Info on that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  19. … [Trackback]

    […] Read More Info here to that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  20. … [Trackback]

    […] Information on that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  21. … [Trackback]

    […] There you can find 59006 more Info on that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  22. … [Trackback]

    […] Read More on on that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  23. … [Trackback]

    […] Info on that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  24. … [Trackback]

    […] Here you can find 83275 additional Info to that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  25. … [Trackback]

    […] Info on that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  26. … [Trackback]

    […] Find More on that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  27. … [Trackback]

    […] Here you will find 82886 additional Information on that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  28. … [Trackback]

    […] Find More here to that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  29. … [Trackback]

    […] Information to that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  30. … [Trackback]

    […] Information on that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  31. … [Trackback]

    […] Here you can find 75738 additional Info on that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  32. … [Trackback]

    […] Read More here to that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  33. … [Trackback]

    […] There you will find 30210 more Info on that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  34. … [Trackback]

    […] Read More to that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  35. … [Trackback]

    […] Read More Information here on that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  36. … [Trackback]

    […] Here you will find 50957 additional Info to that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  37. … [Trackback]

    […] Information on that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  38. … [Trackback]

    […] There you can find 47600 more Information to that Topic: genuinecoder.com/javafx-3d-camera-systems/ […]

  39. how to buy enclomiphene cheap buy online no prescription

    cash on delivery online prescriptions enclomiphene

  40. achat kamagra pilule pharmacie renouveler

    medicament kamagra pharmacie acheter medicament

  41. Buying androxal without a perscription

    how buy androxal canada

  42. order flexeril cyclobenzaprine generic canada no prescription

    online order flexeril cyclobenzaprine price at walmart

  43. purchase dutasteride generic south africa

    canadian pharmacy dutasteride online

  44. gabapentin fedex delivery

    how to order gabapentin canada mail order

  45. online pharmacy cod fildena

    discount fildena cheap store

  46. online order itraconazole cheap to buy online

    cheap itraconazole uk no prescription

  47. online order staxyn uk suppliers

    online order staxyn generic release date

  48. buy avodart france where to buy

    buy cheap avodart uk online

  49. buy cheap xifaxan generic from canadian pharmacy

    online order xifaxan cheap discount

  50. ordering rifaximin generic effectiveness

    rifaximin online no perscription overnight

  51. kamagra stナ凖ュdテ。 nad pナ册pテ。ナセkou

    levné generické kamagra

Leave a Reply Cancel reply

Exit mobile version