Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Camera

Virtual 3D camera specified by eye, center, up, fovy, near, far, and a viewport size. It provides access to cached view, projection, and view projection matrices. Cached by means of whenever one of the attributes change, all matrices are invalidated and recalculated only once and only when requested. Please note that eye denotes the position in a virtual 3D scene and center denotes the position which is being looked at.

Hierarchy

  • Camera

Index

Constructors

constructor

  • Constructor setting up the camera's eye, center and up vectors.

    Parameters

    • Optional eye: vec3

      The viewpoint of the virtual camera

    • Optional center: vec3

      The look-at point in the scene

    • Optional up: vec3

      The up-vector of the virtual camera

    Returns Camera

Properties

Protected _altered

_altered: boolean = false
see

altered

Protected _aspect

_aspect: number = 1.0
see

aspect

Protected _center

_center: vec3
see

center

Protected _eye

_eye: vec3
see

eye

Protected _far

_far: number = ...
see

far

Protected _fovy

_fovy: number = ...
see

fovy

Protected _near

_near: number = ...
see

near

Protected _postViewProjection

_postViewProjection: undefined | mat4

Protected _projection

_projection: undefined | mat4

Protected _projectionInverse

_projectionInverse: undefined | mat4

Protected _up

_up: vec3
see

up

Protected _view

_view: undefined | mat4
see

view

Protected _viewInverse

_viewInverse: undefined | mat4

Protected _viewProjection

_viewProjection: undefined | mat4

Protected _viewProjectionInverse

_viewProjectionInverse: undefined | mat4

Protected _viewport

_viewport: GLsizei2 = ...
see

viewport

Static Private Readonly DEFAULT_CENTER

DEFAULT_CENTER: vec3 = ...

Static Private Readonly DEFAULT_EYE

DEFAULT_EYE: vec3 = ...

Static Private Readonly DEFAULT_FAR

DEFAULT_FAR: 8 = 8.0

Static Private Readonly DEFAULT_FOVY

DEFAULT_FOVY: 45 = 45.0

Static Private Readonly DEFAULT_NEAR

DEFAULT_NEAR: 2 = 2.0

Static Private Readonly DEFAULT_UP

DEFAULT_UP: vec3 = ...

Accessors

altered

  • get altered(): boolean
  • set altered(status: boolean): void
  • Whether or not any other public property has changed. Please note that the alteration status is detached from caching state of lazily computed properties.

    Returns boolean

  • Intended for resetting alteration status.

    Parameters

    • status: boolean

    Returns void

aspect

  • get aspect(): number
  • set aspect(aspect: number): void
  • Computes the ratio of width over height (set explicitly for differentiation between viewport size and scale).

    Returns number

  • Sets the aspect ratio (width over height). However, this is not derived from viewport to allow for differentiation between viewport size and scale.

    Parameters

    • aspect: number

    Returns void

center

  • get center(): vec3
  • set center(center: vec3): void

eye

  • get eye(): vec3
  • set eye(eye: vec3): void

far

  • get far(): number
  • set far(far: number): void
  • Distance of far-plane in view coordinates.

    Returns number

  • Sets the distance to the far clipping plane. Invalidates the projection.

    Parameters

    • far: number

    Returns void

fovx

  • set fovx(fovx: number): void
  • Sets the horizontal field-of-view in degrees. Invalidates the projection. Note that internally, this will be translated to the corresponding the vertical field.

    Parameters

    • fovx: number

    Returns void

fovy

  • get fovy(): number
  • set fovy(fovy: number): void
  • Vertical field of view in degree.

    Returns number

  • Sets the vertical field-of-view in degrees. Invalidates the projection.

    Parameters

    • fovy: number

    Returns void

height

  • get height(): number

near

  • get near(): number
  • set near(near: number): void
  • Distance of near-plane in view coordinates.

    Returns number

  • Sets the distance to the near clipping plane. Invalidates the projection.

    Parameters

    • near: number

    Returns void

postViewProjection

  • get postViewProjection(): mat4
  • set postViewProjection(matrix: mat4): void
  • Returns the matrix which contains the operations that are applied to the viewProjection matrix. For now this is only used by the TiledRenderer to adjust the NDC-coordinates to the tile.

    Returns mat4

  • Sets the matrix which contains the operations that are applied to the viewProjection matrix. For now this is only used by the TiledRenderer to adjust the NDC-coordinates to the tile.

    Parameters

    Returns void

projection

  • get projection(): mat4
  • Either returns the cached projection matrix or derives the current one after invalidation and caches it.

    Returns mat4

projectionInverse

  • get projectionInverse(): undefined | mat4
  • Either returns the cached inverse projection matrix or derives the current one after invalidation and caches it.

    Returns undefined | mat4

up

view

  • Either returns the cached view matrix or derives the current one after invalidation and caches it.

    Returns mat4

viewInverse

  • get viewInverse(): undefined | mat4
  • Either returns the inverse cached view matrix or derives the current one after invalidation and caches it.

    Returns undefined | mat4

viewProjection

  • get viewProjection(): mat4
  • Returns the view projection matrix based on view and projection. This is also cached (since matrix multiplication is involved).

    Returns mat4

viewProjectionInverse

  • get viewProjectionInverse(): undefined | mat4
  • Returns the inverse view projection matrix based on view and projection. This is also cached (since matrix multiplication is involved).

    Returns undefined | mat4

viewport

  • The size of the target viewport used to determine the aspect ratio for subsequent perspective matrix projection computation.

    Returns GLsizei2

  • Sets the viewport size. Invalidates the projection.

    Parameters

    Returns void

width

  • get width(): number

Methods

fovFromLens

  • fovFromLens(sensorWidth: number, focalLength: number): void
  • With this function the view of a physical camera can be emulated. The width and focal length of a lens are used to generate the correct field of view. Blender camera presets can be imported by using the camera setting 'HorizontalFit' and using the width and focal length values in this function. See: https://www.scantips.com/lights/fieldofviewmath.html

    Parameters

    • sensorWidth: number

      Width of the sensor in mm

    • focalLength: number

      Focal length of the lens in mm

    Returns void

Protected invalidate

  • invalidate(invalidateView: boolean, invalidateProjection: boolean, invalidateOnlyViewProjection?: boolean): void
  • Invalidates derived matrices, i.e., view, projection, and view-projection. The view should be invalidated on eye, center, and up changes. The projection should be invalidated on fovy, viewport, near, and far changes. The view projection invalidates whenever either one or both view and projection are to be invalidated.

    Parameters

    • invalidateView: boolean
    • invalidateProjection: boolean
    • invalidateOnlyViewProjection: boolean = false

    Returns void

Static calculateFovY

  • calculateFovY(elementDisplayHeight: number, eyeToDisplayDistance: number): number
  • Computes a vertical field of view angle based on the display height and distance to eye. Since both parameters are highly dependent of the device, this function can only be used to derive a rough estimate for a reasonable field of view. Note that both parameters should be passed using the same unit, e.g., inch or centimeters.

    Parameters

    • elementDisplayHeight: number

      Height of an element on the display.

    • eyeToDisplayDistance: number

      Distance from the users eye to that element.

    Returns number

    • Vertical field of view angle in radian.