API Docs for:
Show:

LS.Components.Camera Class

Module: LS

Camera contains the info about a camera (matrices, near far planes, clear color, etc)

Constructor

LS.Components.Camera

(
  • object
)

Parameters:

  • object String

    to configure from

Methods

fromViewMatrix

(
  • mat
)

uses a view matrix to compute the eye,center,up vectors

Parameters:

  • mat Mat4

    the given view matrix

getCenter

(
  • out
)
Vec3

returns the center of the camera (position where the camera is pointing) in global coordinates

Parameters:

  • out Vec3

    output vector [optional]

Returns:

Vec3:

position in global coordinates

getEye

(
  • out
)
Vec3

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 Vec3

    output vector [optional]

Returns:

Vec3:

position in global coordinates

getFront

(
  • out
)
Vec3

returns the front vector of the camera

Parameters:

  • out Vec3

    output vector [optional]

Returns:

Vec3:

position in global coordinates

getLocalPoint

(
  • v
  • dest
)
Vec3

transform a local coordinate to global coordinates

Parameters:

  • v Vec3

    vector

  • dest Vec3

    where to store the output, if not provided a vec3 is created

Returns:

Vec3:

v in global coordinates

getLocalVector

(
  • v
  • dest
)
Vec3

rotate a local coordinate to global coordinates (skipping translation)

Parameters:

  • v Vec3

    vector

  • dest Vec3

    where to store the output, if not provided a vec3 is created

Returns:

Vec3:

v in global coordinates

getLocalViewport

(
  • [viewport=null]
  • [result=vec4]
)
Vec4

returns the viewport in pixels applying the local camera viewport to the full viewport of the canvas

Parameters:

  • [viewport=null] Vec4 optional

    viewport info, otherwise the canvas dimensions will be used (not the current viewport)

  • [result=vec4] Vec4 optional

    where to store the result, if omited it is created

Returns:

Vec4:

the viewport info of the camera in pixels

getModelMatrix

(
  • m
)
Mat4

returns the inverse of the viewmatrix

Parameters:

  • m Mat4

    optional output container

Returns:

Mat4:

matrix

getModelViewProjectionMatrix

(
  • model
  • out
)
Mat4

returns the model view projection matrix computed from a passed model

Parameters:

  • model Mat4

    model matrix

  • out Mat4

    optional output container

Returns:

Mat4:

matrix

getProjectionMatrix

(
  • m
)
Mat4

returns the projection matrix

Parameters:

  • m Mat4

    optional output container

Returns:

Mat4:

matrix

getRayInPixel

(
  • x
  • y
  • viewport
  • skip_local_viewport
)
Object

given an x and y position, returns the ray {start, dir}

Parameters:

  • x Number
  • y Number
  • viewport Vec4

    viewport coordinates (if omited full viewport is used using the camera viewport)

  • skip_local_viewport Boolean

    ignore the local camera viewport configuration when computing the viewport

Returns:

Object:

{origin:vec3, direction:vec3} or null is values are undefined or NaN

getRight

(
  • out
)
Vec3

returns the right vector of the camera

Parameters:

  • out Vec3

    output vector [optional]

Returns:

Vec3:

position in global coordinates

getTop

(
  • out
)
Vec3

returns the top vector of the camera (different from up, this one is perpendicular to front and right)

Parameters:

  • out Vec3

    output vector [optional]

Returns:

Vec3:

position in global coordinates

getUp

(
  • out
)
Vec3

returns the up vector of the camera

Parameters:

  • out Vec3

    output vector [optional]

Returns:

Vec3:

position in global coordinates

getViewMatrix

(
  • m
)
Mat4

returns the viewmatrix

Parameters:

  • m Mat4

    optional output container

Returns:

Mat4:

matrix

getViewProjectionMatrix

(
  • m
  • force
)
Mat4

returns the view projection matrix

Parameters:

  • m Mat4

    optional output container

  • force Boolean

    optional force to update

Returns:

Mat4:

matrix

isPointInCamera

(
  • x
  • y
  • viewport
)
Boolean

Returns true if the 2D point (in screen space coordinates) is inside the camera viewport area

Parameters:

  • x Number
  • y Number
  • viewport Vec4

    viewport coordinates (if omited full viewport is used)

Returns:

Boolean:

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 Boolean

    if 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 Vec3

    optional

panning

(
  • x
  • y
)

Pans the camera (move acording to view)

Parameters:

  • x Number
  • y Number

project

(
  • vec
  • [viewport=null]
  • result
)
Vec3

Converts a 3D point to its 2D position in canvas space

Parameters:

  • vec Vec3

    3D position we want to proyect to 2D

  • [viewport=null] Vec4 optional

    viewport info (if omited full canvas viewport is used)

  • result Vec3

    where to store the result, if omited it is created

Returns:

Vec3:

the coordinates in 2D

projectNodeCenter

(
  • vec
  • [viewport=null]
  • result
)
Vec3

It tells you the 2D position of a node center in the screen

Parameters:

  • vec Vec3

    3D position we want to proyect to 2D

  • [viewport=null] Vec4 optional

    viewport info (if omited full canvas viewport is used)

  • result Vec3

    where to store the result, if omited it is created

Returns:

Vec3:

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 Boolean

    allows 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 Mat4

    the 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 Boolean

    if this is true it moves the eye closer, otherwise it moves the center closer to the eye

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 Number

    in degrees

  • aspect Number

    the aspect modifier (not the real final aspect, leave it to one)

  • near Number

    distance

  • far Number

    distance

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
)
Vec3

Converts a screen space 2D vector (with a Z value) to its 3D equivalent position

Parameters:

  • vec Vec3

    2D position we want to proyect to 3D

  • [viewport=null] Vec4 optional

    viewport info (if omited full canvas viewport is used)

  • result Vec3

    where to store the result, if omited it is created

Returns:

Vec3:

the coordinates in 2D

updateFrustumPlanes

() Float32Array

Update the frustum planes according to viewprojection_matrix, used for visibility testing

Returns:

Float32Array:

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 Mat4

    matrix

Properties

aspect

Number

The camera aspect ratio

Default: 1

background_color

Vec4

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 contains the RenderFrameContext where the scene was stored

LS.RenderFrameContext

frame_color_texture contains the color texture used by the RenderFrameContext

GL.Texture

frame_depth_texture contains the depth texture used by the RenderFrameContext

GL.Texture

frustum_size

Number

The frustum size when working in ORTHOGRAPHIC

Default: 50

mustUpdate

Boolean

near

Number

The near plane

Default: 1

orthographic left,right,bottom,top (near and far are in the near,far properties)

Vec4

The frustum size when working in pure ORTHOGRAPHIC

Default: 50

projection_matrix

Mat4

The projection matrix of the camera (cannot be set manually, use setCustomProjectionMatrix instead)

projection_matrix

Vec4

The view matrix of the camera

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]

viewport

Vec4

The viewport in normalized coordinates (left,bottom, width, height)

viewport_offset

Vec2

viewport_size

Vec2