Package 

Class Camera


  • 
    public class Camera
    
                        

    Camera represents the eye through which the scene is viewed.

    A Camera has a position and orientation and controls the projection and exposure parameters.

    In Filament, Camera is a component that must be associated with an entity. To do so, use createCamera. A Camera component is destroyed using destroyCameraComponent ()}.
     Camera myCamera = engine.createCamera(myCameraEntity);
     myCamera.setProjection(45, 16.0/9.0, 0.1, 1.0);
     myCamera.lookAt(0, 1.60, 1,
                     0, 0, 0,
                     0, 1, 0);
     engine.destroyCameraComponent(myCameraEntity);
    
    The camera coordinate system defines the view space. The camera points towards its -z axis and is oriented such that its top side is in the direction of +y, and its right side in the direction of +x.

    Since the near and far planes are defined by the distance from the camera, their respective coordinates are -distancenear and -distancefar.

    The camera defines six clipping planes which together create a clipping volume. The geometry outside this volume is clipped.

    The clipping volume can either be a box or a frustum depending on which projection is used, respectively ORTHO or PERSPECTIVE. The six planes are specified either directly or indirectly using setProjection or setLensProjection.

    The six planes are:

    • left
    • right
    • bottom
    • top
    • near
    • far

    To increase the depth-buffer precision, the far clipping plane is always assumed to be at infinity for rendering. That is, it is not used to clip geometry during rendering. However, it is used during the culling phase (objects entirely behind the farplane are culled).

    The near plane distance greatly affects the depth-buffer resolution.

    Example: Precision at 1m, 10m, 100m and 1Km for various near distances assuming a 32-bit float depth-buffer

    As can be seen in the table above, the depth-buffer precision drops rapidly with the distance to the camera.

    Make sure to pick the highest near plane distance possible.

    The Camera is also used to set the scene's exposure, just like with a real camera. The lights intensity and the Camera exposure interact to produce the final scene's brightness.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      public enum Camera.Projection

      Denotes the projection type used by this camera.

      public enum Camera.Fov

      Denotes a field-of-view direction.

    • Method Summary

      Modifier and Type Method Description
      void setProjection(@NonNull() Camera.Projection projection, double left, double right, double bottom, double top, double near, double far) Sets the projection matrix from a frustum defined by six planes.
      void setProjection(double fovInDegrees, double aspect, double near, double far, @NonNull() Camera.Fov direction) Sets the projection matrix from the field-of-view.
      void setLensProjection(double focalLength, double aspect, double near, double far) Sets the projection matrix from the focal length.
      void setCustomProjection(@NonNull() @Size(min = 16) Array<double> inProjection, double near, double far) Sets a custom projection matrix.
      void setCustomProjection(@NonNull() @Size(min = 16) Array<double> inProjection, @NonNull() @Size(min = 16) Array<double> inProjectionForCulling, double near, double far) Sets a custom projection matrix.
      void setScaling(double xscaling, double yscaling) Sets an additional matrix that scales the projection matrix.
      void setScaling(@NonNull() @Size(min = 4) Array<double> inScaling) Sets an additional matrix that scales the projection matrix.
      void setShift(double xshift, double yshift) Sets an additional matrix that shifts (translates) the projection matrix.
      void setModelMatrix(@NonNull() @Size(min = 16) Array<float> modelMatrix) Sets the camera's model matrix.
      void setModelMatrix(@NonNull() @Size(min = 16) Array<double> modelMatrix) Sets the camera's model matrix.
      void lookAt(double eyeX, double eyeY, double eyeZ, double centerX, double centerY, double centerZ, double upX, double upY, double upZ) Sets the camera's model matrix.
      float getNear() Gets the distance to the near plane
      float getCullingFar() Gets the distance to the far plane
      Array<double> getProjectionMatrix(@Nullable() @Size(min = 16) Array<double> out) Retrieves the camera's projection matrix.
      Array<double> getCullingProjectionMatrix(@Nullable() @Size(min = 16) Array<double> out) Retrieves the camera's culling matrix.
      Array<double> getScaling(@Nullable() @Size(min = 4) Array<double> out) Returns the scaling amount used to scale the projection matrix.
      Array<float> getModelMatrix(@Nullable() @Size(min = 16) Array<float> out) Retrieves the camera's model matrix.
      Array<double> getModelMatrix(@Nullable() @Size(min = 16) Array<double> out) Retrieves the camera's model matrix.
      Array<float> getViewMatrix(@Nullable() @Size(min = 16) Array<float> out) Retrieves the camera's view matrix.
      Array<double> getViewMatrix(@Nullable() @Size(min = 16) Array<double> out) Retrieves the camera's view matrix.
      Array<float> getPosition(@Nullable() @Size(min = 3) Array<float> out) Retrieves the camera position in world space.
      Array<float> getLeftVector(@Nullable() @Size(min = 3) Array<float> out) Retrieves the camera left unit vector in world space, that is a unit vector that points tothe left of the camera.
      Array<float> getUpVector(@Nullable() @Size(min = 3) Array<float> out) Retrieves the camera up unit vector in world space, that is a unit vector that points up withrespect to the camera.
      Array<float> getForwardVector(@Nullable() @Size(min = 3) Array<float> out) Retrieves the camera forward unit vector in world space, that is a unit vector that pointsin the direction the camera is looking at.
      void setExposure(float aperture, float shutterSpeed, float sensitivity) Sets this camera's exposure (default is f/16, 1/125s, 100 ISO)The exposure ultimately controls the scene's brightness, just like with a real camera.The default values provide adequate exposure for a camera placed outdoors on a sunny daywith the sun at the zenith.With the default parameters, the scene must contain at least one Light of intensitysimilar to the sun (e.g.: a 100,000 lux directional light) and/or an indirect lightof appropriate intensity (30,000).
      void setExposure(float exposure) Sets this camera's exposure directly.
      float getAperture() Gets the aperture in f-stops
      float getShutterSpeed() Gets the shutter speed in seconds
      double getFocalLength() Gets the focal length in meters
      void setFocusDistance(float distance) Set the camera focus distance in world units
      float getFocusDistance() Gets the distance from the camera to the focus plane in world units
      float getSensitivity() Gets the sensitivity in ISO
      int getEntity() Gets the entity representing this Camera
      long getNativeObject()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • setProjection

         void setProjection(@NonNull() Camera.Projection projection, double left, double right, double bottom, double top, double near, double far)

        Sets the projection matrix from a frustum defined by six planes.

        Parameters:
        projection - type of projection to use
        left - distance in world units from the camera to the left plane,at the near plane.
        right - distance in world units from the camera to the right plane,at the near plane.
        bottom - distance in world units from the camera to the bottom plane,at the near plane.
        top - distance in world units from the camera to the top plane,at the near plane.
        near - distance in world units from the camera to the near plane.
        far - distance in world units from the camera to the far plane.
      • setProjection

         void setProjection(double fovInDegrees, double aspect, double near, double far, @NonNull() Camera.Fov direction)

        Sets the projection matrix from the field-of-view.

        Parameters:
        fovInDegrees - full field-of-view in degrees.
        aspect - aspect ratio width/height.
        near - distance in world units from the camera to the near plane.
        far - distance in world units from the camera to the far plane.
        direction - direction of the field-of-view parameter.
      • setLensProjection

         void setLensProjection(double focalLength, double aspect, double near, double far)

        Sets the projection matrix from the focal length.

        Parameters:
        focalLength - lens's focal length in millimeters.
        aspect - aspect ratio width/height.
        near - distance in world units from the camera to the near plane.
        far - distance in world units from the camera to the far plane.
      • setCustomProjection

         void setCustomProjection(@NonNull() @Size(min = 16) Array<double> inProjection, double near, double far)

        Sets a custom projection matrix.

        The projection matrix must define an NDC system that must match the OpenGL convention,that is all 3 axis are mapped to [-1, 1].

        Parameters:
        inProjection - custom projection matrix for rendering and culling
        near - distance in world units from the camera to the near plane.
        far - distance in world units from the camera to the far plane.
      • setCustomProjection

         void setCustomProjection(@NonNull() @Size(min = 16) Array<double> inProjection, @NonNull() @Size(min = 16) Array<double> inProjectionForCulling, double near, double far)

        Sets a custom projection matrix.

        The projection matrices must define an NDC system that must match the OpenGL convention,that is all 3 axis are mapped to [-1, 1].

        Parameters:
        inProjection - custom projection matrix for rendering.
        inProjectionForCulling - custom projection matrix for culling.
        near - distance in world units from the camera to the near plane.
        far - distance in world units from the camera to the far plane.
      • setScaling

         void setScaling(double xscaling, double yscaling)

        Sets an additional matrix that scales the projection matrix.

        This is useful to adjust the aspect ratio of the camera independent from its projection.First, pass an aspect of 1.0 to setProjection. Then set the scaling with the desired aspectratio:double aspect = width / height;// with Fov.HORIZONTAL passed to setProjection:camera.setScaling(1.0, aspect);// with Fov.VERTICAL passed to setProjection:camera.setScaling(1.0 / aspect, 1.0);By default, this is an identity matrix.

        Parameters:
        xscaling - horizontal scaling to be applied after the projection matrix.
        yscaling - vertical scaling to be applied after the projection matrix.
      • setScaling

        @Deprecated() void setScaling(@NonNull() @Size(min = 4) Array<double> inScaling)

        Sets an additional matrix that scales the projection matrix.

        This is useful to adjust the aspect ratio of the camera independent from its projection.First, pass an aspect of 1.0 to setProjection. Then set the scaling with the desired aspectratio:double aspect = width / height;// with Fov.HORIZONTAL passed to setProjection:double[] s = {1.0, aspect, 1.0, 1.0};camera.setScaling(s);// with Fov.VERTICAL passed to setProjection:double[] s = {1.0 / aspect, 1.0, 1.0, 1.0};camera.setScaling(s);By default, this is an identity matrix.

        Parameters:
        inScaling - diagonal of the scaling matrix to be applied after the projection matrix.
      • setShift

         void setShift(double xshift, double yshift)

        Sets an additional matrix that shifts (translates) the projection matrix.

        The shift parameters are specified in NDC coordinates, that is, if the translation mustbe specified in pixels, the xshift and yshift parameters be scaled by 1.0 / viewport.widthand 1.0 / viewport.height respectively.

        Parameters:
        xshift - horizontal shift in NDC coordinates applied after the projection
        yshift - vertical shift in NDC coordinates applied after the projection
      • setModelMatrix

         void setModelMatrix(@NonNull() @Size(min = 16) Array<float> modelMatrix)

        Sets the camera's model matrix.

        Helper method to set the camera's entity transform component.Remember that the Camera "looks" towards its -z axis.

        This has the same effect as calling:

         engine.getTransformManager().setTransform(
                 engine.getTransformManager().getInstance(camera->getEntity()), modelMatrix);
        
        Parameters:
        modelMatrix - The camera position and orientation provided as a rigid transform matrix.
      • setModelMatrix

         void setModelMatrix(@NonNull() @Size(min = 16) Array<double> modelMatrix)

        Sets the camera's model matrix.

        Helper method to set the camera's entity transform component.Remember that the Camera "looks" towards its -z axis.

        Parameters:
        modelMatrix - The camera position and orientation provided as a rigid transform matrix.
      • lookAt

         void lookAt(double eyeX, double eyeY, double eyeZ, double centerX, double centerY, double centerZ, double upX, double upY, double upZ)

        Sets the camera's model matrix.

        Parameters:
        eyeX - x-axis position of the camera in world space
        eyeY - y-axis position of the camera in world space
        eyeZ - z-axis position of the camera in world space
        centerX - x-axis position of the point in world space the camera is looking at
        centerY - y-axis position of the point in world space the camera is looking at
        centerZ - z-axis position of the point in world space the camera is looking at
        upX - x-axis coordinate of a unit vector denoting the camera's "up" direction
        upY - y-axis coordinate of a unit vector denoting the camera's "up" direction
        upZ - z-axis coordinate of a unit vector denoting the camera's "up" direction
      • getNear

         float getNear()

        Gets the distance to the near plane

      • getCullingFar

         float getCullingFar()

        Gets the distance to the far plane

      • getProjectionMatrix

        @NonNull()@Size(min = 16) Array<double> getProjectionMatrix(@Nullable() @Size(min = 16) Array<double> out)

        Retrieves the camera's projection matrix. The projection matrix used for rendering always hasits far plane set to infinity. This is why it may differ from the matrix set throughsetProjection() or setLensProjection().

        Parameters:
        out - A 16-float array where the projection matrix will be stored, or null in whichcase a new array is allocated.
      • getCullingProjectionMatrix

        @NonNull()@Size(min = 16) Array<double> getCullingProjectionMatrix(@Nullable() @Size(min = 16) Array<double> out)

        Retrieves the camera's culling matrix. The culling matrix is the same as the projectionmatrix, except the far plane is finite.

        Parameters:
        out - A 16-float array where the projection matrix will be stored, or null in whichcase a new array is allocated.
      • getModelMatrix

        @NonNull()@Size(min = 16) Array<float> getModelMatrix(@Nullable() @Size(min = 16) Array<float> out)

        Retrieves the camera's model matrix. The model matrix encodes the camera position andorientation, or pose.

        Parameters:
        out - A 16-float array where the model matrix will be stored, or null in whichcase a new array is allocated.
      • getModelMatrix

        @NonNull()@Size(min = 16) Array<double> getModelMatrix(@Nullable() @Size(min = 16) Array<double> out)

        Retrieves the camera's model matrix. The model matrix encodes the camera position andorientation, or pose.

        Parameters:
        out - A 16-double array where the model matrix will be stored, or null in whichcase a new array is allocated.
      • getViewMatrix

        @NonNull()@Size(min = 16) Array<float> getViewMatrix(@Nullable() @Size(min = 16) Array<float> out)

        Retrieves the camera's view matrix. The view matrix is the inverse of the model matrix.

        Parameters:
        out - A 16-float array where the view matrix will be stored, or null in whichcase a new array is allocated.
      • getViewMatrix

        @NonNull()@Size(min = 16) Array<double> getViewMatrix(@Nullable() @Size(min = 16) Array<double> out)

        Retrieves the camera's view matrix. The view matrix is the inverse of the model matrix.

        Parameters:
        out - A 16-double array where the model view will be stored, or null in whichcase a new array is allocated.
      • getPosition

        @NonNull()@Size(min = 3) Array<float> getPosition(@Nullable() @Size(min = 3) Array<float> out)

        Retrieves the camera position in world space.

        Parameters:
        out - A 3-float array where the position will be stored, or null in which case a newarray is allocated.
      • getLeftVector

        @NonNull()@Size(min = 3) Array<float> getLeftVector(@Nullable() @Size(min = 3) Array<float> out)

        Retrieves the camera left unit vector in world space, that is a unit vector that points tothe left of the camera.

        Parameters:
        out - A 3-float array where the left vector will be stored, or null in which case a newarray is allocated.
      • getUpVector

        @NonNull()@Size(min = 3) Array<float> getUpVector(@Nullable() @Size(min = 3) Array<float> out)

        Retrieves the camera up unit vector in world space, that is a unit vector that points up withrespect to the camera.

        Parameters:
        out - A 3-float array where the up vector will be stored, or null in which case a newarray is allocated.
      • getForwardVector

        @NonNull()@Size(min = 3) Array<float> getForwardVector(@Nullable() @Size(min = 3) Array<float> out)

        Retrieves the camera forward unit vector in world space, that is a unit vector that pointsin the direction the camera is looking at.

        Parameters:
        out - A 3-float array where the forward vector will be stored, or null in which case anew array is allocated.
      • setExposure

         void setExposure(float aperture, float shutterSpeed, float sensitivity)

        Sets this camera's exposure (default is f/16, 1/125s, 100 ISO)The exposure ultimately controls the scene's brightness, just like with a real camera.The default values provide adequate exposure for a camera placed outdoors on a sunny daywith the sun at the zenith.With the default parameters, the scene must contain at least one Light of intensitysimilar to the sun (e.g.: a 100,000 lux directional light) and/or an indirect lightof appropriate intensity (30,000).

        Parameters:
        aperture - Aperture in f-stops, clamped between 0.5 and 64.A lower aperture value increases the exposure, leading toa brighter scene.
        shutterSpeed - Shutter speed in seconds, clamped between 1/25,000 and 60.A lower shutter speed increases the exposure.
        sensitivity - Sensitivity in ISO, clamped between 10 and 204,800.A higher sensitivity increases the exposure.
      • setExposure

         void setExposure(float exposure)

        Sets this camera's exposure directly. Calling this method will set the apertureto 1.0, the shutter speed to 1.2 and the sensitivity will be computed to matchthe requested exposure (for a desired exposure of 1.0, the sensitivity will beset to 100 ISO).This method is useful when trying to match the lighting of other engines or tools.Many engines/tools use unit-less light intensities, which can be matched by settingthe exposure manually. This can be typically achieved by setting the exposure to1.0.

      • getAperture

         float getAperture()

        Gets the aperture in f-stops

      • getShutterSpeed

         float getShutterSpeed()

        Gets the shutter speed in seconds

      • getFocalLength

         double getFocalLength()

        Gets the focal length in meters

      • setFocusDistance

         void setFocusDistance(float distance)

        Set the camera focus distance in world units

        Parameters:
        distance - Distance from the camera to the focus plane in world units.
      • getFocusDistance

         float getFocusDistance()

        Gets the distance from the camera to the focus plane in world units

      • getEntity

         int getEntity()

        Gets the entity representing this Camera