API Docs for:
Show:

RD.Camera Class

Camera wraps all the info about the camera (properties and view and projection matrices)

Constructor

RD.Camera

()

Methods

applyController

(
  • dt
  • e
)

Used to move the camera (helps during debug)

Parameters:

  • dt Number

    delta time from update

  • e Event

    mouse event or keyboard event

getFront

(
  • dest
)
Vec3

gets the front vector normalized

Parameters:

  • dest Vec3

    [Optional]

Returns:

Vec3:

front vector

getLocalVector

(
  • v
  • result
)
Vec3

transform vector (only rotates) from local to global

Parameters:

  • v Vec3
  • result Vec3

    [Optional]

Returns:

Vec3:

local point transformed

getLocalVector

(
  • v
  • result
)
Vec3

transform point from local to global

Parameters:

  • v Vec3
  • result Vec3

    [Optional]

Returns:

Vec3:

local point transformed

getRay

(
  • x
  • y
  • [viewport=gl.viewport]
  • [out]
)
Object

gets the ray passing through one pixel

Parameters:

  • x Number
  • y Number
  • [viewport=gl.viewport] Array optional
  • [out] Object optional

    { origin: vec3, direction: vec3 }

Returns:

Object:

ray object { origin: vec3, direction:vec3 }

getRayPlaneCollision

(
  • x
  • y
  • position
  • normal
  • [result=vec3]
  • [viewport=vec4]
)
Vec3

given a screen coordinate it cast a ray and returns the collision point with a given plane

Parameters:

  • x Number
  • y Number
  • position Vec3

    Plane point

  • normal Vec3

    Plane normal

  • [result=vec3] Vec3 optional
  • [viewport=vec4] Vec4 optional

Returns:

Vec3:

the collision point, or null

lookAt

(
  • position
  • target
  • up
)

configure view of the camera

Parameters:

  • position Vec3
  • target Vec3
  • up Vec3

move

(
  • v
)

move the position and the target

Parameters:

  • v Vec3

moveLocal

(
  • v
)

move the position and the target using the local coordinates system of the camera

Parameters:

  • v Vec3

orthographic

(
  • frustum_size
  • near
  • far
  • aspect
)

changes the camera to orthographic mode (frustumsize is top-down)

Parameters:

  • frustum_size Number
  • near Number
  • far Number
  • aspect Number

perspective

(
  • fov
  • aspect
  • near
  • far
)

changes the camera to perspective mode

Parameters:

  • fov Number
  • aspect Number
  • near Number
  • far Number

project

(
  • vec
  • [viewport=gl.viewport]
  • [result=vec3]
)
Vec3

projects a point from 3D to 2D

Parameters:

  • vec Vec3

    coordinate to project

  • [viewport=gl.viewport] Array optional
  • [result=vec3] Vec3 optional

Returns:

Vec3:

the projected point

rotate

(
  • angle
  • axis
  • [center=null]
)

rotate around its target position

Parameters:

  • angle Number

    in radians

  • axis Vec3
  • [center=null] Vec3 optional

    if another center is provided it rotates around it

rotate

(
  • angle
  • axis
)

rotate over its position

Parameters:

  • angle Number

    in radians

  • axis Vec3

rotateLocal

(
  • angle
  • axis
)

rotate over its position

Parameters:

  • angle Number

    in radians

  • axis Vec3

    in local coordinates

testBox

(
  • center
  • halfsize
)
Number

test if box is inside frustrum (you must call camera.extractPlanes() previously to update frustrum planes)

Parameters:

  • center Vec3

    center of the box

  • halfsize Vec3

    halfsize of the box (vector from center to corner)

Returns:

Number:

CLIP_OUTSIDE or CLIP_INSIDE or CLIP_OVERLAP

testSphere

(
  • center
  • radius
)
Number

test if sphere is inside frustrum (you must call camera.extractPlanes() previously to update frustrum planes)

Parameters:

  • center Vec3
  • radius Number

Returns:

Number:

CLIP_OUTSIDE or CLIP_INSIDE or CLIP_OVERLAP

unproject

(
  • vec
  • [viewport=gl.viewport]
  • [result=vec3]
)
Vec3

projects a point from 2D to 3D

Parameters:

  • vec Vec3

    coordinate to unproject

  • [viewport=gl.viewport] Array optional
  • [result=vec3] Vec3 optional

Returns:

Vec3:

the projected point

updateMatrices

()

update view projection matrices

updateVectors

(
  • model_matrix
)

update camera using a model_matrix as reference

Parameters:

  • model_matrix Mat4

Properties

aspect

Number

aspect (width / height)

Default: 1

far

Number

far distance

Default: 10000

fov

Number

fov angle in degrees

Default: 45

frustum_size

Number

size of frustrum when working in orthographic

Default: 50

near

Number

near distance

Default: 0.1

position

Vec3

Position where the camera eye is located

target

Vec3

Where the camera is looking at, the center of where is looking

type

Number

the camera type, RD.Camera.PERSPECTIVE || RD.Camera.ORTHOGRAPHIC

Default: RD.Camera.PERSPECTIVE

up

Vec3

Up vector

Default: [0,1,0]