RD.Camera Class
Camera wraps all the info about the camera (properties and view and projection matrices)
Constructor
RD.Camera
()
Item Index
Methods
Methods
applyController
-
dt
-
e
Used to move the camera (helps during debug)
Parameters:
-
dt
Numberdelta time from update
-
e
Eventmouse event or keyboard event
getFront
-
dest
gets the front vector normalized
Parameters:
-
dest
Vec3[Optional]
Returns:
front vector
getLocalVector
-
v
-
result
transform vector (only rotates) from local to global
Parameters:
-
v
Vec3 -
result
Vec3[Optional]
Returns:
local point transformed
getLocalVector
-
v
-
result
transform point from local to global
Parameters:
-
v
Vec3 -
result
Vec3[Optional]
Returns:
local point transformed
getRay
-
x
-
y
-
[viewport=gl.viewport]
-
[out]
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:
ray object { origin: vec3, direction:vec3 }
getRayPlaneCollision
-
x
-
y
-
position
-
normal
-
[result=vec3]
-
[viewport=vec4]
given a screen coordinate it cast a ray and returns the collision point with a given plane
Parameters:
-
x
Number -
y
Number -
position
Vec3Plane point
-
normal
Vec3Plane normal
-
[result=vec3]
Vec3 optional -
[viewport=vec4]
Vec4 optional
Returns:
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]
projects a point from 3D to 2D
Parameters:
-
vec
Vec3coordinate to project
-
[viewport=gl.viewport]
Array optional -
[result=vec3]
Vec3 optional
Returns:
the projected point
rotate
-
angle
-
axis
-
[center=null]
rotate around its target position
Parameters:
-
angle
Numberin radians
-
axis
Vec3 -
[center=null]
Vec3 optionalif another center is provided it rotates around it
rotate
-
angle
-
axis
rotate over its position
Parameters:
-
angle
Numberin radians
-
axis
Vec3
rotateLocal
-
angle
-
axis
rotate over its position
Parameters:
-
angle
Numberin radians
-
axis
Vec3in local coordinates
testBox
-
center
-
halfsize
test if box is inside frustrum (you must call camera.extractPlanes() previously to update frustrum planes)
Parameters:
-
center
Vec3center of the box
-
halfsize
Vec3halfsize of the box (vector from center to corner)
Returns:
CLIP_OUTSIDE or CLIP_INSIDE or CLIP_OVERLAP
testSphere
-
center
-
radius
test if sphere is inside frustrum (you must call camera.extractPlanes() previously to update frustrum planes)
Parameters:
-
center
Vec3 -
radius
Number
Returns:
CLIP_OUTSIDE or CLIP_INSIDE or CLIP_OVERLAP
unproject
-
vec
-
[viewport=gl.viewport]
-
[result=vec3]
projects a point from 2D to 3D
Parameters:
-
vec
Vec3coordinate to unproject
-
[viewport=gl.viewport]
Array optional -
[result=vec3]
Vec3 optional
Returns:
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]