LS.Components.Camera Class
Camera contains the info about a camera (matrices, near far planes, clear color, etc)
Constructor
LS.Components.Camera
-
object
Parameters:
-
object
Objectto configure from
Item Index
Methods
- fromViewMatrix
- getCenter
- getEye
- getFront
- getLocalPoint
- getLocalVector
- getLocalViewport
- getModelMatrix
- getModelViewProjectionMatrix
- getProjectionMatrix
- getRay
- getRight
- getTop
- getUp
- getViewMatrix
- getViewProjectionMatrix
- isPointInCamera
- lookAt
- lookAtFromMatrix
- move
- orbit
- panning
- project
- projectNodeCenter
- resetVectors
- rotate
- setCustomProjectionMatrix
- setDistanceToCenter
- setEulerAngles
- setOrientation
- setOrthographic
- setPerspective
- setViewportInPixels
- unproject
- updateFrustumPlanes
- updateMatrices
- updateVectors
Methods
fromViewMatrix
-
mat
uses a view matrix to compute the eye,center,up vectors
Parameters:
-
mat
Mat4the given view matrix
getCenter
-
out
returns the center of the camera (position where the camera is pointing) in global coordinates
Parameters:
-
out
Vec3output vector [optional]
Returns:
position in global coordinates
getEye
-
out
Returns the eye (position of the camera) in global coordinates Takes into account if it is a camera attached to a node The result of this function wont match the _eye property if the camera is a node camera
Parameters:
-
out
Vec3output vector [optional]
Returns:
position in global coordinates
getFront
-
out
returns the front vector of the camera
Parameters:
-
out
Vec3output vector [optional]
Returns:
position in global coordinates
getLocalPoint
-
v
-
dest
transform a local coordinate to global coordinates
Parameters:
-
v
Vec3vector
-
dest
Vec3where to store the output, if not provided a vec3 is created
Returns:
v in global coordinates
getLocalVector
-
v
-
dest
rotate a local coordinate to global coordinates (skipping translation)
Parameters:
-
v
Vec3vector
-
dest
Vec3where to store the output, if not provided a vec3 is created
Returns:
v in global coordinates
getLocalViewport
-
[viewport=null]
-
[result=vec4]
returns the viewport in pixels applying the local camera viewport to the full viewport of the canvas
Parameters:
-
[viewport=null]
Vec4 optionalviewport info, otherwise the canvas dimensions will be used (not the current viewport)
-
[result=vec4]
Vec4 optionalwhere to store the result, if omited it is created
Returns:
the viewport info of the camera in pixels
getModelMatrix
-
m
returns the inverse of the viewmatrix
Parameters:
-
m
Mat4optional output container
Returns:
matrix
getModelViewProjectionMatrix
-
model
-
out
returns the model view projection matrix computed from a passed model
Parameters:
-
model
Mat4model matrix
-
out
Mat4optional output container
Returns:
matrix
getProjectionMatrix
-
m
returns the projection matrix
Parameters:
-
m
Mat4optional output container
Returns:
matrix
getRay
-
x
-
y
-
viewport
-
skip_local_viewport
-
result
given an x and y position, returns the ray {start, dir}
Parameters:
-
x
Number -
y
Number -
viewport
Vec4viewport coordinates (if omited full viewport is used using the camera viewport)
-
skip_local_viewport
Booleanignore the local camera viewport configuration when computing the viewport
-
result
LS.Ray[optional] to reuse ray
Returns:
{origin:vec3, direction:vec3} or null is values are undefined or NaN
getRight
-
out
returns the right vector of the camera
Parameters:
-
out
Vec3output vector [optional]
Returns:
position in global coordinates
getTop
-
out
returns the top vector of the camera (different from up, this one is perpendicular to front and right)
Parameters:
-
out
Vec3output vector [optional]
Returns:
position in global coordinates
getUp
-
out
returns the up vector of the camera
Parameters:
-
out
Vec3output vector [optional]
Returns:
position in global coordinates
getViewMatrix
-
m
returns the viewmatrix
Parameters:
-
m
Mat4optional output container
Returns:
matrix
getViewProjectionMatrix
-
m
-
force
returns the view projection matrix
Parameters:
-
m
Mat4optional output container
-
force
Booleanoptional force to update
Returns:
matrix
isPointInCamera
-
x
-
y
-
viewport
Returns true if the 2D point (in screen space coordinates) is inside the camera viewport area
Parameters:
-
x
Number -
y
Number -
viewport
Vec4viewport coordinates (if omited full viewport is used)
Returns:
lookAt
-
eye
-
center
-
up
Positions the camera at eye, pointing at center, and facing up as vertical. If the camera is a node camera, then the node transform is modified (plus the center to match the focalLength)
Parameters:
-
eye
Vec3 -
center
Vec3 -
up
Vec3
lookAtFromMatrix
-
matrix
-
is_model
Positions the camera using a matrix that contains the position an orientation (NOT FULLY TESTED) If the camera is a node camera, then the node transform is modified (plus the center to match the focalLength)
Parameters:
-
matrix
Mat4 -
is_model
Booleanif false the matrix is assumed to be a view matrix, otherwise a model (inverse of view)
move
-
delta
moves the camera by adding the delta vector to center and eye
Parameters:
-
delta
Vec3
orbit
-
angle_in_deg
-
axis
-
center
Rotates the camera eye around a center
Parameters:
-
angle_in_deg
Number -
axis
Vec3 -
center
Vec3optional
panning
-
x
-
y
Pans the camera (move acording to view)
Parameters:
-
x
Number -
y
Number
project
-
vec
-
[viewport=null]
-
result
Converts a 3D point to its 2D position in canvas space
Parameters:
-
vec
Vec33D position we want to proyect to 2D
-
[viewport=null]
Vec4 optionalviewport info (if omited full canvas viewport is used)
-
result
Vec3where to store the result, if omited it is created
Returns:
the coordinates in 2D
projectNodeCenter
-
vec
-
[viewport=null]
-
result
It tells you the 2D position of a node center in the screen
Parameters:
-
vec
Vec33D position we want to proyect to 2D
-
[viewport=null]
Vec4 optionalviewport info (if omited full canvas viewport is used)
-
result
Vec3where to store the result, if omited it is created
Returns:
the coordinates in 2D
resetVectors
-
focalDist
resets eye, center and up, so they are in [0,0,0],[0,0,-focalDist] and [0,1,0]
Parameters:
-
focalDist
Number[optional] it not set it will be 1
rotate
-
angle_in_deg
-
axis
-
in_local_space
rotate the camera around its center
Parameters:
-
angle_in_deg
Number -
axis
Vec3 -
in_local_space
Booleanallows to specify if the axis is in local space or global space
setCustomProjectionMatrix
-
mat
overwrites the current projection matrix with a given one (it also blocks the camera from modifying the projection matrix)
Parameters:
-
mat
Mat4the given projection matrix (or null to disable it)
setDistanceToCenter
-
new_distance
-
move_eye
changes the distance between eye and center ( it could move the center or the eye, depending on the parameters )
Parameters:
-
new_distance
Number -
move_eye
Booleanif this is true it moves the eye closer, otherwise it moves the center closer to the eye
setEulerAngles
-
yaw
-
pitch
-
roll
orients the camera (changes where is facing) using euler angles (yaw,pitch,roll)
Parameters:
-
yaw
Number -
pitch
Number -
roll
Number
setOrientation
-
q
orients the camera (changes where is facing) according to the rotation supplied
Parameters:
-
q
Quat
setOrthographic
-
left
-
right
-
bottom
-
top
-
near
-
far
set camera in orthographic mode and sets the planes
Parameters:
-
left
Number -
right
Number -
bottom
Number -
top
Number -
near
Number -
far
Number
setPerspective
-
fov
-
aspect
-
near
-
far
set camera in perspective mode and sets the properties
Parameters:
-
fov
Numberin degrees
-
aspect
Numberthe aspect modifier (not the real final aspect, leave it to one)
-
near
Numberdistance
-
far
Numberdistance
setViewportInPixels
-
left
-
right
-
width
-
height
Sets the viewport in pixels (using the gl.canvas as reference)
Parameters:
-
left
Number -
right
Number -
width
Number -
height
Number
unproject
-
vec
-
[viewport=null]
-
result
Converts a screen space 2D vector (with a Z value) to its 3D equivalent position
Parameters:
-
vec
Vec32D position we want to proyect to 3D
-
[viewport=null]
Vec4 optionalviewport info (if omited full canvas viewport is used)
-
result
Vec3where to store the result, if omited it is created
Returns:
the coordinates in 2D
updateFrustumPlanes
()
Float32Array
Update the frustum planes according to viewprojection_matrix, used for visibility testing
Returns:
planes
updateMatrices
()
Update matrices according to the eye,center,up,fov,aspect,...
updateVectors
-
model
apply a transform to all the vectors (eye,center,up) using a matrix
Parameters:
-
model
Mat4matrix
Properties
aspect
Number
The camera aspect ratio
Default: 1
background_color
Vec4
the clear color
center
Vec3
The center where the camera points (in local space, node space)
Default: [0,0,0]
eye
Vec3
The position of the camera (in local space, node space)
Default: [0,100,100]
far
Number
The far plane
Default: 1000
focalLength
Number
The distance between the center and the eye point When focalLength is modified it will change the center so it matches the distance.
Default: (depends)
fov
Number
The field of view in degrees
Default: 45
frame_color_texture
GL.Texture
contains the color texture used by the RenderFrameContext
frame_depth_texture
GL.Texture
contains the depth texture used by the RenderFrameContext
frustum_size
Number
The frustum size when working in ORTHOGRAPHIC
Default: 50
mustUpdate
Boolean
to force updating projection and view matrix
near
Number
The near plane
Default: 1
orthographic
Vec4
The frustum size when working in pure ORTHOGRAPHIC left,right,bottom,top (near and far are in the near,far properties)
Default: 50
projection_matrix
Mat4
The projection matrix of the camera (cannot be set manually, use setCustomProjectionMatrix instead)
render_to_texture
GL.Texture
returns the texture from the render frame context
type
Vec3
Camera type, could be Camera.PERSPECTIVE or Camera.ORTHOGRAPHIC
Default: Camera.PERSPECTIVE;
up
Vec3
The up vector of the camera (in local space, node space)
Default: [0,1,0]
view_matrix
Vec4
The view matrix of the camera
viewport
Vec4
The viewport in normalized coordinates (left,bottom, width, height)