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

  • new Camera(eye?: vec3, center?: vec3, up?: vec3): Camera
  • 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: GLfloat = 1
see

aspect

Protected _center

_center: vec3
see

center

Protected _eye

_eye: vec3
see

eye

Protected _far

_far: number = Camera.DEFAULT_FAR
see

far

Protected _fovy

_fovy: number = Camera.DEFAULT_FOVY
see

fovy

Protected _near

_near: number = Camera.DEFAULT_NEAR
see

near

Protected _projection

_projection: mat4 | undefined

Protected _projectionInverse

_projectionInverse: mat4 | undefined | null

Protected _up

_up: vec3
see

up

Protected _view

_view: mat4 | undefined
see

view

Protected _viewInverse

_viewInverse: mat4 | undefined | null

Protected _viewProjection

_viewProjection: mat4 | undefined

Protected _viewProjectionInverse

_viewProjectionInverse: mat4 | undefined | null

Protected _viewport

_viewport: GLsizei2 = [1, 1]
see

viewport

Static Private DEFAULT_CENTER

DEFAULT_CENTER: vec3 = vec3.fromValues(0.0, 0.0, 0.0)

Static Private DEFAULT_EYE

DEFAULT_EYE: vec3 = vec3.fromValues(0.0, 0.0, 1.0)

Static Private DEFAULT_FAR

DEFAULT_FAR: 8 = 8

Static Private DEFAULT_FOVY

DEFAULT_FOVY: 45 = 45

Static Private DEFAULT_NEAR

DEFAULT_NEAR: 2 = 2

Static Private DEFAULT_UP

DEFAULT_UP: vec3 = vec3.fromValues(0.0, 1.0, 0.0)

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(): GLfloat
  • set aspect(aspect: GLfloat): void
  • Computes the ratio of width over height (set explicitly for differentiation between viewport size and scale).

    Returns GLfloat

  • 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: GLfloat

    Returns void

center

  • get center(): vec3
  • set center(center: vec3): void
  • Look-at point into a virtual 3D scene.

    Returns vec3

  • Sets the center. Invalidates the view.

    Parameters

    • center: vec3

    Returns void

eye

  • get eye(): vec3
  • set eye(eye: vec3): void
  • Position of the virtual camera in a virtual 3D scene, the point of view.

    Returns vec3

  • Sets the eye. Invalidates the view.

    Parameters

    • eye: vec3

    Returns void

far

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

    Returns GLfloat

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

    Parameters

    • far: GLfloat

    Returns void

fovy

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

    Returns GLfloat

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

    Parameters

    • fovy: GLfloat

    Returns void

height

  • get height(): GLsizei
  • Access to the viewport height.

    Returns GLsizei

near

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

    Returns GLfloat

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

    Parameters

    • near: GLfloat

    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(): mat4 | null
  • Either returns the cached inverse projection matrix or derives the current one after invalidation and caches it.

    Returns mat4 | null

up

  • get up(): vec3
  • set up(up: vec3): void
  • Up-vector of the virtual camera.

    Returns vec3

  • Sets the up vector. Invalidates the view.

    Parameters

    • up: vec3

    Returns void

view

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

    Returns mat4

viewInverse

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

    Returns mat4 | null

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(): mat4 | null
  • Returns the inverse view projection matrix based on view and projection. This is also cached (since matrix multiplication is involved).

    Returns mat4 | null

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(): GLsizei
  • Access to the viewport width.

    Returns GLsizei

Methods

Protected invalidate

  • invalidate(invalidateView: boolean, invalidateProjection: 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

    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.