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:
-
dtNumberdelta time from update
-
eEventmouse event or keyboard event
getFront
-
dest
gets the front vector normalized
Parameters:
-
destVec3[Optional]
Returns:
front vector
getLocalVector
-
v -
result
transform vector (only rotates) from local to global
Parameters:
-
vVec3 -
resultVec3[Optional]
Returns:
local point transformed
getLocalVector
-
v -
result
transform point from local to global
Parameters:
-
vVec3 -
resultVec3[Optional]
Returns:
local point transformed
getRay
-
x -
y -
[viewport=gl.viewport] -
[out]
gets the ray passing through one pixel
Parameters:
-
xNumber -
yNumber -
[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:
-
xNumber -
yNumber -
positionVec3Plane point
-
normalVec3Plane 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:
-
positionVec3 -
targetVec3 -
upVec3
move
-
v
move the position and the target
Parameters:
-
vVec3
moveLocal
-
v
move the position and the target using the local coordinates system of the camera
Parameters:
-
vVec3
orthographic
-
frustum_size -
near -
far -
aspect
changes the camera to orthographic mode (frustumsize is top-down)
Parameters:
-
frustum_sizeNumber -
nearNumber -
farNumber -
aspectNumber
perspective
-
fov -
aspect -
near -
far
changes the camera to perspective mode
Parameters:
-
fovNumber -
aspectNumber -
nearNumber -
farNumber
project
-
vec -
[viewport=gl.viewport] -
[result=vec3]
projects a point from 3D to 2D
Parameters:
-
vecVec3coordinate 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:
-
angleNumberin radians
-
axisVec3 -
[center=null]Vec3 optionalif another center is provided it rotates around it
rotate
-
angle -
axis
rotate over its position
Parameters:
-
angleNumberin radians
-
axisVec3
rotateLocal
-
angle -
axis
rotate over its position
Parameters:
-
angleNumberin radians
-
axisVec3in local coordinates
testBox
-
center -
halfsize
test if box is inside frustrum (you must call camera.extractPlanes() previously to update frustrum planes)
Parameters:
-
centerVec3center of the box
-
halfsizeVec3halfsize 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:
-
centerVec3 -
radiusNumber
Returns:
CLIP_OUTSIDE or CLIP_INSIDE or CLIP_OVERLAP
unproject
-
vec -
[viewport=gl.viewport] -
[result=vec3]
projects a point from 2D to 3D
Parameters:
-
vecVec3coordinate 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_matrixMat4
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]
