Camera

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

Constructor

new Camera(optionsopt)

Parameters:
NameTypeAttributesDescription
optionsObject<optional>

Camera options:

Properties
NameTypeAttributesDefaultDescription
nameObject<optional>

Camera name.

viewAnglenumber<optional>
47

Camera angle of view. Default is 47.0

nearnumber<optional>
1

Camera near plane distance. Default is 1.0

farnumber<optional>
og.math.MAX

Camera far plane distance. Default is og.math.MAX

eyeVec3<optional>
[0,0,0]

Camera eye position. Default (0,0,0)

lookVec3<optional>
[0,0,0]

Camera look position. Default (0,0,0)

upVec3<optional>
[0,1,0]

Camera eye position. Default (0,1,0)

Fires:
  • event:viewchange
  • event:moveend

Members

depthZeroToOne

Returns active depth range mode.

focusDistance

Returns focus distance used for orthographic projection size.

focusDistance

Sets focus distance used for orthographic projection size.

frustum

Returns current active frustum.

height

Returns viewport height.

horizontalViewAngle

Returns camera horizontal view angle in degrees.

id

Returns camera identifier.

isOrthographic

Returns current projection mode.

isOrthographic

Enables or disables orthographic projection mode.

reverseDepth

Returns reverse depth flag.

reverseDepthActive

Returns active reverse depth state.

verticalViewAngle

Returns camera vertical view angle in degrees.

viewAngle

Returns camera vertical view angle in degrees.

width

Returns viewport width.

Methods

_init(optionsopt)

Camera initialization.

Parameters:
NameTypeAttributesDescription
optionsObject<optional>

Camera options:

Properties
NameTypeAttributesDescription
viewAnglenumber<optional>

Camera angle of view.

nearnumber<optional>

Camera near plane distance. Default is 1.0

farnumber<optional>

Camera far plane distance. Default is math.MAX

eyeVec3<optional>

Camera eye position. Default (0,0,0)

lookVec3<optional>

Camera look position. Default (0,0,0)

upVec3<optional>

Camera eye position. Default (0,1,0)

_setProj(viewAngle, aspect)

Sets camera projection.

Parameters:
NameTypeDescription
viewAnglenumber

Camera view angle.

aspectnumber

Screen aspect ratio.

bindFrustumsPickingColors(renderer)

Binds picking colors for all frustums.

Parameters:
NameTypeDescription
rendererRenderer

Renderer instance.

checkFly()

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

checkMoveEnd()

Checks whether the camera stopped moving and dispatches moveend.

containsSphere(sphere) → {boolean}

Checks whether sphere intersects any camera frustum.

Parameters:
NameTypeDescription
sphereSphere

Bounding sphere.

Returns:

true when visible in at least one frustum.

Type: 
boolean

copy(cam)

Copies camera pose and projection settings from another camera.

Parameters:
NameTypeDescription
camCamera

Source camera.

flyCartesian(cartesianopt, paramsopt)

Flies to the cartesian coordinates.

Parameters:
NameTypeAttributesDescription
cartesianVec3<optional>

Finish cartesian coordinates.

paramsIFlyCartesianParams<optional>

Flight parameters

getAbsolutePitch() → {number}

Returns absolute pitch angle.

Returns:

Absolute pitch angle in radians.

Type: 
number

getAbsoluteRoll() → {number}

Returns absolute roll angle.

Returns:

Absolute roll angle in radians.

Type: 
number

getAbsoluteYaw() → {number}

Returns absolute yaw angle.

Returns:

Absolute yaw angle in radians.

Type: 
number

getAltitude() → {number}

Returns camera altitude value for base camera.

Returns:

Camera y coordinate.

Type: 
number

getAspectRatio() → {number}

Returns aspect ratio.

Returns:

Aspect ratio.

Type: 
number

getBackward() → {Vec3}

Returns backward direction vector.

Returns:

Backward direction.

Type: 
Vec3

getCurrentFrustum() → {number}

Returns current active frustum index.

Returns:

Current frustum index.

Type: 
number

getDown() → {Vec3}

Returns down direction vector.

Returns:

Down direction.

Type: 
Vec3

getForward() → {Vec3}

Returns forward direction vector.

Returns:

Forward direction.

Type: 
Vec3

getInverseProjectionMatrix() → {NumberArray16}

Returns inverse projection matrix.

Returns:

Inverse projection matrix.

Type: 
NumberArray16

getInverseProjectionViewMatrix() → {NumberArray16}

Returns inverse projection-view matrix.

Returns:

Inverse projection-view matrix.

Type: 
NumberArray16

getLeft() → {Vec3}

Returns left direction vector.

Returns:

Left direction.

Type: 
Vec3

getNormalMatrix() → {NumberArray9}

Returns normal matrix.

Returns:
  • Normal matrix.
Type: 
NumberArray9

getPitch() → {number}

Returns pitch angle.

Returns:

Pitch angle in radians.

Type: 
number

getProjectionMatrix() → {NumberArray16}

Returns projection matrix.

Returns:

Projection matrix.

Type: 
NumberArray16

getProjectionViewMatrix() → {NumberArray16}

Returns projection-view matrix.

Returns:

Projection-view matrix.

Type: 
NumberArray16

getProjectionViewRTEMatrix() → {NumberArray16}

Returns projection-view RTE matrix.

Returns:

Projection-view RTE matrix.

Type: 
NumberArray16

getRight() → {Vec3}

Returns right direction vector.

Returns:

Right direction.

Type: 
Vec3

getRoll() → {number}

Returns roll angle.

Returns:

Roll angle in radians.

Type: 
number

getRotation() → {Quat}

Returns camera rotation quaternion.

Returns:

Camera rotation quaternion.

Type: 
Quat

getUp() → {Vec3}

Returns up direction vector.

Returns:

Up direction.

Type: 
Vec3

getViewAngle() → {number}

Returns camera vertical view angle in degrees.

Returns:

View angle in degrees.

Type: 
number

getViewMatrix() → {NumberArray16}

Returns model matrix.

Returns:
  • View matrix.
Type: 
NumberArray16

getYaw() → {number}

Returns yaw angle.

Returns:

Yaw angle in radians.

Type: 
number

isFlying() → {boolean}

Returns camera is flying.

Returns:
Type: 
boolean

look(look, upopt)

Sets camera look point

Parameters:
NameTypeAttributesDescription
lookVec3

Look point

upVec3<optional>

Camera up vector otherwise camera current up vector(this._u)

project(x, y, z) → {Vec2}

Gets projected 3d point to the 2d screen coordinates

Parameters:
NameTypeDescription
xnumber

X coordinate

ynumber

Y coordinate

znumber

Z coordinate

Returns:
  • Screen point coordinates
Type: 
Vec2

project3v(v) → {Vec2}

Gets projected 3d point to the 2d screen coordinates

Parameters:
NameTypeDescription
vVec3

Cartesian 3d coordinates

Returns:
  • Screen point coordinates
Type: 
Vec2

projectedSize(p, r) → {number}

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

Parameters:
NameTypeDescription
pVec3

Point in 3d.

rVec3

size.

Returns:
  • Size factor.
Type: 
number

refresh()

Refresh camera matrices

rotate(rot)

Rotates current camera basis by quaternion.

Parameters:
NameTypeDescription
rotQuat

Rotation quaternion.

rotateAround(angle, isArcopt, centeropt, upopt)

Rotates camera around center point

Parameters:
NameTypeAttributesDefaultDescription
anglenumber

Rotation angle in radians

isArcboolean<optional>
false

If true camera up vector gets from current up vector every frame, otherwise up is always input parameter.

centerVec3<optional>

Point that the camera rotates around

upVec3<optional>

Camera up vector

rotateHorizontal(angle, isArcopt, centeropt, upopt)

Rotates camera around center point by horizontal.

Parameters:
NameTypeAttributesDescription
anglenumber

Rotation angle in radians.

isArcboolean<optional>

If true camera up vector gets from current up vector every frame, otherwise up is always input parameter.

centerVec3<optional>

Point that the camera rotates around.

upVec3<optional>

Camera up vector.

rotateVertical(angle, centeropt)

Rotates camera around center point by vertical.

Parameters:
NameTypeAttributesDescription
anglenumber

Rotation angle in radians.

centerVec3<optional>

Point that the camera rotates around.

set(eye, look, up) → {Camera}

Sets camera to eye position

Parameters:
NameTypeDescription
eyeVec3

Camera position

lookVec3

Look point

upVec3

Camera up vector

Returns:
  • This camera
Type: 
Camera

setCurrentFrustum(k)

Sets current active frustum index.

Parameters:
NameTypeDescription
knumber

Frustum index.

setDepthZeroToOne(enabled)

Enables or disables ZERO_TO_ONE depth range mode.

Parameters:
NameTypeDescription
enabledboolean

Depth range mode flag.

setFrustums(frustums)

Replaces camera frustum ranges.

Parameters:
NameTypeDescription
frustumsArray.<NumberArray2>

Array of [near, far] ranges.

setNearFar(near, faropt, frustumIndexopt)

Updates near/far planes for one frustum.

Parameters:
NameTypeAttributesDefaultDescription
nearnumber

Near clipping plane distance.

farnumber<optional>

Far clipping plane distance.

frustumIndexnumber<optional>
0

Frustum index.

setPitch(angle)

Pitch the camera to the angle in radians

Parameters:
NameTypeDescription
anglenumber

Delta pitch angle in radians

setPitchYawRoll(pitch, yaw, roll)

Sets camera orientation from Euler angles.

Parameters:
NameTypeDescription
pitchnumber

Pitch angle in radians.

yawnumber

Yaw angle in radians.

rollnumber

Roll angle in radians.

setRoll(angle)

Roll the camera to the angle in radians

Parameters:
NameTypeDescription
anglenumber

Delta roll angle in radians

setRotation(rot, upopt, rightopt, backopt)

Sets camera orientation from a quaternion.

Parameters:
NameTypeAttributesDescription
rotQuat

Rotation quaternion.

upVec3<optional>

Base up vector.

rightVec3<optional>

Base right vector.

backVec3<optional>

Base backward vector.

setViewAngle(angle)

Sets camera view angle in degrees

Parameters:
NameTypeDescription
anglenumber

View angle

setViewportSize(width, height)

Sets viewport size and updates projection.

Parameters:
NameTypeDescription
widthnumber

Viewport width in pixels.

heightnumber

Viewport height in pixels.

setYaw(angle)

Yaw the camera to the angle in radians

Parameters:
NameTypeDescription
anglenumber

Delta yaw angle in radians

slide(du, dv, dn)

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

Parameters:
NameTypeDescription
dunumber

delta X

dvnumber

delta Y

dnnumber

delta Z

stopFlying()

Breaks the flight.

unproject(x, y, distopt, outPosopt) → {Vec3}

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

Parameters:
NameTypeAttributesDescription
xnumber

Screen X coordinate in pixels.

ynumber

Screen Y coordinate in pixels.

distnumber<optional>

Optional projection distance for orthographic mode.

outPosVec3<optional>

Optional output world position for orthographic mode.

Returns:
  • Direction vector.
Type: 
Vec3

unproject2v(pos, distopt, outPosopt) → {Vec3}

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

Parameters:
NameTypeAttributesDescription
posVec2

Screen coordinates in pixels.

distnumber<optional>

Optional projection distance for orthographic mode.

outPosVec3<optional>

Optional output world position for orthographic mode.

Returns:
  • Direction vector.
Type: 
Vec3

(abstract) update()

Updates camera view space

viewDistance(cartesian, distanceopt)

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

Parameters:
NameTypeAttributesDefaultDescription
cartesianVec3

Target cartesian point.

distancenumber<optional>
10000.0

Distance from the target.