Class Camera

  • All Implemented Interfaces:
    TransformProvider, CameraProvider

    public class Camera
    extends Node
    implements CameraProvider
    Represents a virtual camera, which determines the perspective through which the scene is viewed.

    If the camera is part of an ArSceneView, then the camera automatically tracks the camera pose from ARCore. Additionally, the following methods will throw UnsupportedOperationException when called:

    All other functionality in Node is supported. You can access the position and rotation of the camera, assign a collision shape to the camera, or add children to the camera. Disabling the camera turns off rendering.
    • Method Detail

      • setNearClipPlane

        public void setNearClipPlane​(float nearPlane)
      • setFarClipPlane

        public void setFarClipPlane​(float farPlane)
      • setVerticalFovDegrees

        public void setVerticalFovDegrees​(float verticalFov)
        Sets the vertical field of view for the non-ar camera in degrees. If this is an AR camera, then the fov comes from ARCore and cannot be set so an exception is thrown. The default is 90 degrees.
        Throws:
        java.lang.UnsupportedOperationException - if this is an AR camera
      • getVerticalFovDegrees

        public float getVerticalFovDegrees()
        Gets the vertical field of view for the camera.

        If this is an AR camera, then it is calculated based on the camera information from ARCore and can vary between device. It can't be calculated until the first frame after the ARCore session is resumed, in which case an IllegalStateException is thrown.

        Otherwise, this will return the value set by setVerticalFovDegrees(float), with a default of 90 degrees.

        Throws:
        java.lang.IllegalStateException - if called before the first frame after ARCore is resumed
      • updateTrackedPose

        public void updateTrackedPose​(com.google.ar.core.Camera camera)
        Updates the pose and projection of the camera to match the tracked pose from ARCore.
        Specified by:
        updateTrackedPose in interface CameraProvider
      • screenPointToRay

        public Ray screenPointToRay​(float x,
                                    float y)
        Calculates a ray in world space going from the near-plane of the camera and going through a point in screen space. Screen space is in Android device screen coordinates: TopLeft = (0, 0) BottomRight = (Screen Width, Screen Height) The device coordinate space is unaffected by the orientation of the device.
        Parameters:
        x - X position in device screen coordinates.
        y - Y position in device screen coordinates.
      • worldToScreenPoint

        public Vector3 worldToScreenPoint​(Vector3 point)
        Convert a point from world space into screen space.

        The X value is negative when the point is left of the viewport, between 0 and the width of the SceneView when the point is within the viewport, and greater than the width when the point is to the right of the viewport.

        The Y value is negative when the point is below the viewport, between 0 and the height of the SceneView when the point is within the viewport, and greater than the height when the point is above the viewport.

        The Z value is always 0 since the return value is a 2D coordinate.

        Parameters:
        point - the point in world space to convert
        Returns:
        a new vector that represents the point in screen-space.
      • setParent

        public void setParent​(@Nullable
                              NodeParent parent)
        Unsupported operation. Camera's parent cannot be changed, it is always the scene.
        Overrides:
        setParent in class Node
        Parameters:
        parent - The new parent that this node will be a child of. If null, this node will be detached from its parent.
        See Also:
        Node.getParent(), Node.getScene()
      • setProjectionMatrix

        public void setProjectionMatrix​(Matrix matrix)