Render3D. Camera3D

Camera3D - Position, rotation and lens for the 3D view

  • Looks down its -Z axis, rotation is vec3(pitch, yaw, roll)

Constructor

new Camera3D()

Create a camera, looking down -Z from z=10 by default

Members

align2D

Properties
TypeDescription
boolean

Line the 3D camera up with the 2D camera, so 3D things at z=0 sit on the 2D sprites

far

Properties
TypeDescription
number

Far clip distance, Infinity is allowed for a perspective view

fov

Properties
TypeDescription
number

Vertical field of view in radians

near

Properties
TypeDescription
number

Near clip distance

orthographic

Properties
TypeDescription
number

Visible height in world units for an orthographic view, 0 is perspective

pos

Properties
TypeDescription
Vector3

World position

rotation

Properties
TypeDescription
Vector3

Euler rotation, vec3(pitch, yaw, roll) in radians

Methods

follow(target, offset, percentopt)

Chase a target from an offset, easing toward it, and look at it

Parameters:
NameTypeAttributesDefaultDescription
targetVector3
offsetVector3

Where to sit relative to the target

percentnumber<optional>
1

How far to move toward the spot each call, 1 snaps

forward() → {Vector3}

Returns the direction the camera looks

Returns:
Type: 
Vector3

getMatrix() → {Matrix4}

Returns the camera's world transform

Returns:
Type: 
Matrix4

getProjectionMatrix(aspect) → {Matrix4}

Returns the projection matrix

Parameters:
NameTypeDescription
aspectnumber

Width over height

Returns:
Type: 
Matrix4

getViewMatrix() → {Matrix4}

Returns the view matrix, world to camera space

Returns:
Type: 
Matrix4

lookAt(target)

Point the camera at a target, sets pitch and yaw and clears roll

Parameters:
NameTypeDescription
targetVector3

orbit(target, distance, yaw, pitchopt)

Put the camera on an orbit around a target, looking at it

Parameters:
NameTypeAttributesDefaultDescription
targetVector3
distancenumber
yawnumber

Radians around Y

pitchnumber<optional>
0.5

Radians above the horizon

Returns the camera's right axis

Returns:
Type: 
Vector3

up() → {Vector3}

Returns the camera's up axis

Returns:
Type: 
Vector3

update2D(canvasHeightopt)

Line the 3D camera up with the 2D camera, called automatically when align2D is set

Parameters:
NameTypeAttributesDescription
canvasHeightnumber<optional>

Defaults to the main canvas height