Camera

Source: Camera.ts:124

//@param {Renderer} [renderer] - Renderer uses the camera instance.

Fires

  • event:viewchange
  • event:moveend

Constructor

new Camera(options?: Object): Camera

Parameters

  • options (Object, optional) — Camera options:
    • options.name (Object, optional) — Camera name.
    • options.viewAngle (number, optional, default: 47) — Camera angle of view. Default is 47.0
    • options.near (number, optional, default: 1) — Camera near plane distance. Default is 1.0
    • options.far (number, optional, default: "og.math.MAX") — Camera far plane distance. Default is og.math.MAX
    • options.eye (Vec3, optional, default: "[0,0,0]") — Camera eye position. Default (0,0,0)
    • options.look (Vec3, optional, default: "[0,0,0]") — Camera look position. Default (0,0,0)
    • options.up (Vec3, optional, default: "[0,1,0]") — Camera eye position. Default (0,1,0)

Instance Methods

setDepthZeroToOne(enabled: boolean)

Enables or disables ZERO_TO_ONE depth range mode.

Parameters

  • enabled (boolean) — Depth range mode flag.

_setOrthoFocus(distance?: number)

protected
Camera.ts:452

Keeps the orthographic scale on whatever the camera has just been aimed at.

Parameters

  • distance (number, optional) — Distance from the eye to the point in view.

flyCartesian(cartesian?: Vec3, params?: IFlyCartesianParams)

Flies to the cartesian coordinates.

Parameters

  • cartesian (Vec3, optional) — Finish cartesian coordinates.
  • params (IFlyCartesianParams, optional) — Flight parameters

stopFlying()

Breaks the flight.

checkFly()

Prepare camera to the frame. Used in render node frame function.

isFlying(): boolean

Returns camera is flying.

Returns

  • boolean

checkViewChanges()

Checks camera movement and projection changes.

checkMoveEnd(): boolean

Checks whether the camera stopped moving and dispatches moveend.

Returns

  • boolean — true when the camera is moving after the check.

_checkViewChange()

protected
Camera.ts:636

Checks whether the camera view or projection changed and dispatches viewchange.

bindFrustumsPickingColors(renderer: Renderer)

Binds picking colors for all frustums.

Parameters

  • renderer (Renderer) — Renderer instance.

_init(options?: Object)

Camera initialization.

Parameters

  • options (Object, optional) — Camera options:
    • options.viewAngle (number, optional) — Camera angle of view.
    • options.near (number, optional) — Camera near plane distance. Default is 1.0
    • options.far (number, optional) — Camera far plane distance. Default is math.MAX
    • options.eye (Vec3, optional) — Camera eye position. Default (0,0,0)
    • options.look (Vec3, optional) — Camera look position. Default (0,0,0)
    • options.up (Vec3, optional) — Camera eye position. Default (0,1,0)

getUp(): Vec3

Returns up direction vector.

Returns

  • Vec3 — Up direction.

getDown(): Vec3

Returns down direction vector.

Returns

  • Vec3 — Down direction.

getRight(): Vec3

Returns right direction vector.

Returns

  • Vec3 — Right direction.

getLeft(): Vec3

Returns left direction vector.

Returns

  • Vec3 — Left direction.

getForward(): Vec3

Returns forward direction vector.

Returns

  • Vec3 — Forward direction.

getBackward(): Vec3

Returns backward direction vector.

Returns

  • Vec3 — Backward direction.

updateCameraSlope()

Updates camera slope against the horizontal XZ plane.

update()

Updates camera view space

refresh()

Refresh camera matrices

setViewportSize(width: number, height: number)

Sets viewport size and updates projection.

Parameters

  • width (number) — Viewport width in pixels.
  • height (number) — Viewport height in pixels.

getAspectRatio(): number

Returns aspect ratio.

Returns

  • number — Aspect ratio.

_setProj(viewAngle: number, aspect: number)

Sets camera projection.

Parameters

  • viewAngle (number) — Camera view angle.
  • aspect (number) — Screen aspect ratio.

setNearFar(near: number, far?: number, frustumIndex?: number)

Updates near/far planes for one frustum.

Parameters

  • near (number) — Near clipping plane distance.
  • far (number, optional) — Far clipping plane distance.
  • frustumIndex (number, optional, default: 0) — Frustum index.

setFrustums(frustums: Array.<NumberArray2>)

Replaces camera frustum ranges.

Parameters

  • frustums (Array.<NumberArray2>) — Array of [near, far] ranges.

setViewAngle(angle: number)

Sets camera view angle in degrees

Parameters

  • angle (number) — View angle

setHorizontalViewAngle(angle: number)

Sets camera horizontal view angle in degrees.

Parameters

  • angle (number) — Horizontal view angle.

getViewAngle(): number

Returns camera vertical view angle in degrees.

Returns

  • number — View angle in degrees.

set(eye: Vec3, look: Vec3, up: Vec3): Camera

Sets camera to eye position

Parameters

  • eye (Vec3) — Camera position
  • look (Vec3) — Look point
  • up (Vec3) — Camera up vector

Returns

look(look: Vec3, up?: Vec3)

Sets camera look point

Parameters

  • look (Vec3) — Look point
  • up (Vec3, optional) — Camera up vector otherwise camera current up vector(this._u)

slide(du: number, dv: number, dn: number)

Slides camera to vector d - (du, dv, dn)

Parameters

  • du (number) — delta X
  • dv (number) — delta Y
  • dn (number) — delta Z

setRoll(angle: number)

Roll the camera to the angle in radians

Parameters

  • angle (number) — Delta roll angle in radians

setPitch(angle: number)

Pitch the camera to the angle in radians

Parameters

  • angle (number) — Delta pitch angle in radians

setYaw(angle: number)

Yaw the camera to the angle in radians

Parameters

  • angle (number) — Delta yaw angle in radians

setPitchYawRoll(pitch: number, yaw: number, roll: number)

Sets camera orientation from Euler angles.

Parameters

  • pitch (number) — Pitch angle in radians.
  • yaw (number) — Yaw angle in radians.
  • roll (number) — Roll angle in radians.

getPitch(): number

Returns pitch angle.

Returns

  • number — Pitch angle in radians.

getYaw(): number

Returns yaw angle.

Returns

  • number — Yaw angle in radians.

getRoll(): number

Returns roll angle.

Returns

  • number — Roll angle in radians.

getAbsolutePitch(): number

Returns absolute pitch angle.

Returns

  • number — Absolute pitch angle in radians.

getAbsoluteYaw(): number

Returns absolute yaw angle.

Returns

  • number — Absolute yaw angle in radians.

getAbsoluteRoll(): number

Returns absolute roll angle.

Returns

  • number — Absolute roll angle in radians.

getRotation(): Quat

Returns camera rotation quaternion.

Returns

  • Quat — Camera rotation quaternion.

setRotation(rot: Quat, up?: Vec3, right?: Vec3, back?: Vec3)

Sets camera orientation from a quaternion.

Parameters

  • rot (Quat) — Rotation quaternion.
  • up (Vec3, optional) — Base up vector.
  • right (Vec3, optional) — Base right vector.
  • back (Vec3, optional) — Base backward vector.

rotate(rot: Quat)

Rotates current camera basis by quaternion.

Parameters

  • rot (Quat) — Rotation quaternion.

unproject2v(pos: Vec2, dist?: number, outPos?: Vec3): Vec3

Returns normal vector direction to the unprojected screen point from camera eye

Parameters

  • pos (Vec2) — Screen coordinates in pixels.
  • dist (number, optional) — Optional projection distance for orthographic mode.
  • outPos (Vec3, optional) — Optional output world position for orthographic mode.

Returns

unproject( x: number, y: number, dist?: number, outPos?: Vec3, ): Vec3

Returns normal vector direction to the unprojected screen point from camera eye

Parameters

  • x (number) — Screen X coordinate in pixels.
  • y (number) — Screen Y coordinate in pixels.
  • dist (number, optional) — Optional projection distance for orthographic mode.
  • outPos (Vec3, optional) — Optional output world position for orthographic mode.

Returns

getRay(x: number, y: number): Ray

Returns a world-space ray corresponding to the given screen point. For perspective camera the ray shares camera eye as origin. For orthographic camera the origin is offset across the view plane, and the direction equals the camera forward vector.

Parameters

  • x (number) — Screen X coordinate in pixels.
  • y (number) — Screen Y coordinate in pixels.

Returns

getRay2v(pos: Vec2): Ray

Returns a world-space ray corresponding to the given screen point.

Parameters

  • pos (Vec2) — Screen coordinates in pixels.

Returns

project3v(v: Vec3): Vec2

Gets projected 3d point to the 2d screen coordinates

Parameters

  • v (Vec3) — Cartesian 3d coordinates

Returns

project(x: number, y: number, z: number): Vec2

Gets projected 3d point to the 2d screen coordinates

Parameters

  • x (number) — X coordinate
  • y (number) — Y coordinate
  • z (number) — Z coordinate

Returns

rotateAround( angle: number, isArc?: boolean, center?: Vec3, up?: Vec3, )

Rotates camera around center point

Parameters

  • angle (number) — Rotation angle in radians
  • isArc (boolean, optional, default: false) — If true camera up vector gets from current up vector every frame, otherwise up is always input parameter.
  • center (Vec3, optional) — Point that the camera rotates around
  • up (Vec3, optional) — Camera up vector

rotateHorizontal( angle: number, isArc?: boolean, center?: Vec3, up?: Vec3, )

Rotates camera around the center point by horizontal.

Parameters

  • angle (number) — Rotation angle in radians.
  • isArc (boolean, optional) — If true camera up vector gets from current up vector every frame, otherwise up is always input parameter.
  • center (Vec3, optional) — Point that the camera rotates around.
  • up (Vec3, optional) — Camera up vector.

rotateVertical(angle: number, center?: Vec3)

Rotates camera around the center point by vertical.

Parameters

  • angle (number) — Rotation angle in radians.
  • center (Vec3, optional) — Point that the camera rotates around.

projectedSize(p: Vec3, r: Vec3): number

Gets 3d size factor. Uses in LOD distance calculation. It is a very important function used in Node.ts

Parameters

  • p (Vec3) — Point in 3d.
  • r (Vec3) — size.

Returns

  • number

getViewMatrix(): NumberArray16

Returns model matrix.

Returns

  • NumberArray16

getNormalMatrix(): NumberArray9

Returns camera normal matrix.

Returns

  • NumberArray9

setCurrentFrustum(k: number)

Sets current active frustum index.

Parameters

  • k (number) — Frustum index.

getCurrentFrustum(): number

Returns current active frustum index.

Returns

  • number — Current frustum index.

containsSphere(sphere: Sphere): boolean

Checks whether the sphere intersects any camera frustum.

Parameters

  • sphere (Sphere) — Bounding sphere.

Returns

  • boolean — true when visible in at least one frustum.

containsPoint(point: Vec3): boolean

Checks whether a point is inside any camera frustum.

Parameters

  • point (Vec3) — Cartesian point.

Returns

  • boolean — true when visible in at least one frustum.

getProjectionMatrix(): NumberArray16

Returns projection matrix.

Returns

  • NumberArray16 — Projection matrix.

getProjectionViewMatrix(): NumberArray16

Returns projection-view matrix.

Returns

  • NumberArray16 — Projection-view matrix.

getProjectionViewRTEMatrix(): NumberArray16

Returns projection-view RTE matrix.

Returns

  • NumberArray16 — Projection-view RTE matrix.

getInverseProjectionViewMatrix(): NumberArray16

Returns inverse projection-view matrix.

Returns

  • NumberArray16 — Inverse projection-view matrix.

getInverseProjectionMatrix(): NumberArray16

Returns inverse projection matrix.

Returns

  • NumberArray16 — Inverse projection matrix.

viewDistance(cartesian: Vec3, distance?: number)

Places camera at a fixed distance from a point and looks at it.

Parameters

  • cartesian (Vec3) — Target cartesian point.
  • distance (number, optional, default: "10000.0") — Distance from the target.

copy(cam: Camera)

Copies camera pose and projection settings from another camera.

Parameters

  • cam (Camera) — Source camera.

getAltitude(): number

Returns camera altitude value for base camera.

Returns

  • number — Camera y coordinate.

Instance Fields

isOrthographic

Returns current projection mode.

Returns

  • boolean — true when orthographic projection is enabled.

reverseDepth

Returns reverse depth flag.

Returns

  • boolean — true when reverse depth mode is enabled.

reverseDepthActive

Returns active reverse depth state.

Returns

  • boolean — true for perspective reverse-Z mode.

depthZeroToOne

Returns active depth range mode.

Returns

  • boolean — true when ZERO_TO_ONE depth range is active.

isOrthographic

Enables or disables orthographic projection mode.

Parameters

  • isOrthographic (boolean) — Orthographic mode flag.

focusDistance

Returns focus distance used for orthographic projection size.

Returns

  • number — Focus distance.

focusDistance

Sets focus distance used for orthographic projection size.

Parameters

  • dist (number) — Focus distance.

id

Returns camera identifier.

Returns

  • number — Camera id.

width

Returns viewport width.

Returns

  • number — Viewport width in pixels.

height

Returns viewport height.

Returns

  • number — Viewport height in pixels.

viewAngle

Returns camera vertical view angle in degrees.

Returns

  • number — Vertical view angle.

verticalViewAngle

Returns camera vertical view angle in degrees.

Returns

  • number — Vertical view angle.

horizontalViewAngle

Returns camera horizontal view angle in degrees.

Returns

  • number — Horizontal view angle.

frustum

Returns current active frustum.

Returns

  • Frustum — Active frustum instance.