Repository

Camera

Camera class. Must be created by the user so that the current scene can be seen. If no camera is added to the scene, rendering is not done (nothing is seen, so nothing is rendered).

A Camera contains a transform object to be moved and rotated in space. Viewport can be defined by the user to create multicam rendering.

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public

aspect: *

public
public
public
public
public
public
public
public
public
public
public

dirty: *

public

far: *

public

fov: *

public
public

flag to know if we used setToPixel method to auto adjust camera pos to mimic 2D graphical spaces, that is with (0,0) in the top-left corner.

public

layers: *

public

name: *

public

near: *

public
public
public

type: *

public
public
Private Members
private

Method Summary

Public Methods
public
public

gets the aspect ratio of the camera view

public
public

Gets the clear color, which is the color used to paint the backgroud.

public

get the vertical field of view in degrees

public

Gets cam far plane

public
public

Gets cam near plane

public
public
public

Gets current zoom value.

public

lookAt(Vector3: Object)

Makes the cam "looks at" the argements coordinates.

public

perspectiveOffCenter(left: Number, right: Number, bottom: Number, top: Number, near: Number, far: Number)

Compute a perspective with offsets matrix

public

Sets the aspect ratio of the camera view

public

Change the autoClear property of this camera.

public

Change the autoClearColor property of this camera.

public

Change the setAutoClearDepth property of this camera.

public

Change the setAutoClearStencil property of this camera.

public

setAutoRender(val: Bool)

Set the autoRender flag, which means that the camera will render itself automatically.

public

setClearColor(Color: Color, Alpha: Number)

Set the clear color, which is the color used to paint the backgroud.

public

setFOV(fov: *)

set the vertical field of view in degrees

public

Sets cam far plane

public

Sets the horizontal shift ratio of the camera view

public

Set this camera layer's name, which should match a renderer's scene name

public

Sets cam near plane

public

setOrthoPlanes(left: Number, right: Number, top: Number, bottom: Number)

Method to recompute the frame of ortho cam.

public

setPlanes(near: Number, far: Number)

Sets cam far and near planes

public

Set the RenderTexture to render on.

public

Tries to adjust the cam z distance so that 1 world unit == 1 screen pixel.

public

Sets the vertical shift ratio of the camera view

public

setZoom(zoom: Number)

Zoom is for ortho cam and mimics the Z translation of perspective cams.

Private Methods
private

recompute the projection matrix of this camera to reflect properly properties changes

Public Constructors

public constructor(params: Object) source

Params:

NameTypeAttributeDescription
paramsObject

Parameters object, given by the constructor.

params.contextContext
  • optional

mobilizing context to use

params.typeString
  • optional
  • default: "perspective"

One of "perspective", "ortho" or "cube"

params.fovNumber
  • optional

vertical field of view

params.cubeResolutionNumber
  • optional
  • default: 1024

if the type is "cube", defines the size of the cubemap, must be a power of 2

params.nearNumber
  • optional
  • default: 1

near plane

params.farNumber
  • optional
  • default: 5000

far plane

params.viewportRect
  • optional
  • default: new Rect()

the Rect defining the viewport in normalize % (0 ~ 1), that is the portion of the rendering canvas to be used as a rendering surface for this camera

params.layerContext
  • optional

the layer in which to render the camera, that is the scene it is

params.positionVector3
  • optional
  • default: Vector(0,0,0)

the position where to create the camera in space

params.verticalshiftNumber
  • optional
  • default: 0

vertical lens shift in %

params.horizontalshiftNumber
  • optional
  • default: 0

horizontal lens shift in %

params.autoRenderBoolean
  • optional
  • default: true

Should the camera automatically renders itself or not

params.autoClearBoolean
  • optional
  • default: true

Should the camera automatically clears itself or not

params.autoUpdateMatrixBoolean
  • optional
  • default: true

Should the camera transformation matrix automatically updates itself or not

Example:

//this is how to use a parameters object in order to instanciate a Mobilizing.js object
    var mobilizingObject = new Mobilizing.Class({paramName1: value, paramName2: value});

Public Members

public aspect: * source

public autoClear: * source

public autoClearColor: boolean source

public autoClearDepth: boolean source

public autoClearStencil: boolean source

public autoRender: * source

public autoUpdateMatrix: * source

public clearColor: * source

public clearColorAplha: * source

public context: * source

public cubeResolution: * source

public dirty: * source

public far: * source

public fov: * source

public horizontalshift: * source

public isToPixel: boolean source

flag to know if we used setToPixel method to auto adjust camera pos to mimic 2D graphical spaces, that is with (0,0) in the top-left corner.

public layers: * source

public name: * source

public near: * source

public renderTexture: * source

public transform: * source

public type: * source

public verticalshift: * source

public viewport: * source

Private Members

private _camera: * source

Public Methods

public addLayer(name: String) source

Params:

NameTypeAttributeDescription
nameString

public getAspect(): Number source

gets the aspect ratio of the camera view

Return:

Number

cam aspect value

public getClearAlpha(): * source

Return:

*

public getClearColor(): Color source

Gets the clear color, which is the color used to paint the backgroud. Note: this is camera independant, each cam on the scene can have a different clear color, or a different background color.

Return:

Color

Color object associated to this clearColor

public getFOV(): Number source

get the vertical field of view in degrees

Return:

Number

Field Of View value

public getFarPlane(): Number source

Gets cam far plane

Return:

Number

far plane value

public getNativeObject(): * source

Return:

*

the Three.js native object used in this class

public getNearPlane(): Number source

Gets cam near plane

Return:

Number

far plane value

public getRenderTexture(): * source

Return:

*

public getWolrdDirection(): * source

Return:

*

public getZoom(): Number source

Gets current zoom value.

Return:

Number

zoom value

public lookAt(Vector3: Object) source

Makes the cam "looks at" the argements coordinates. Handy way to orient the cam or to make it follow an object in space.

Params:

NameTypeAttributeDescription
Vector3Object

the coordinates to look at.

public perspectiveOffCenter(left: Number, right: Number, bottom: Number, top: Number, near: Number, far: Number) source

Compute a perspective with offsets matrix

Params:

NameTypeAttributeDescription
leftNumber
rightNumber
bottomNumber
topNumber
nearNumber
farNumber

public setAspect(the: Number) source

Sets the aspect ratio of the camera view

Params:

NameTypeAttributeDescription
theNumber

ratio (ex. 4/3)

public setAutoClear(val: Boolean) source

Change the autoClear property of this camera. Needed to had a "trail effect"

Params:

NameTypeAttributeDescription
valBoolean

public setAutoClearColor(val: Boolean) source

Change the autoClearColor property of this camera. Needed to had a "trail effect"

Params:

NameTypeAttributeDescription
valBoolean

public setAutoClearDepth(val: Boolean) source

Change the setAutoClearDepth property of this camera.

Params:

NameTypeAttributeDescription
valBoolean

public setAutoClearStencil(val: Boolean) source

Change the setAutoClearStencil property of this camera.

Params:

NameTypeAttributeDescription
valBoolean

public setAutoRender(val: Bool) source

Set the autoRender flag, which means that the camera will render itself automatically.

Params:

NameTypeAttributeDescription
valBool

flag true/false

public setClearColor(Color: Color, Alpha: Number) source

Set the clear color, which is the color used to paint the backgroud. Note: this is camera independant, each cam on the scene can have a different clear color, or a different background color.

Params:

NameTypeAttributeDescription
ColorColor

Mobilizing.Color object

AlphaNumber

A number >= 0 && <= 1

public setFOV(fov: *) source

set the vertical field of view in degrees

Params:

NameTypeAttributeDescription
fov*

{Number} default to 35 degree

public setFarPlane(far: Number) source

Sets cam far plane

Params:

NameTypeAttributeDescription
farNumber

plane value

public setHorizontalShift(the: Number) source

Sets the horizontal shift ratio of the camera view

Params:

NameTypeAttributeDescription
theNumber

ratio (1 -> 100%)

public setLayer(name: String) source

Set this camera layer's name, which should match a renderer's scene name

Params:

NameTypeAttributeDescription
nameString

public setNearPlane(near: Number) source

Sets cam near plane

Params:

NameTypeAttributeDescription
nearNumber

plane value

public setOrthoPlanes(left: Number, right: Number, top: Number, bottom: Number) source

Method to recompute the frame of ortho cam. Is used internally for window resizing.

Params:

NameTypeAttributeDescription
leftNumber
rightNumber
topNumber
bottomNumber

public setPlanes(near: Number, far: Number) source

Sets cam far and near planes

Params:

NameTypeAttributeDescription
nearNumber

near plane value

farNumber

far plane value

public setRenderTexture(renderTexture: RenderTexture) source

Set the RenderTexture to render on. By default, the camera renders on the Context canvas.

Params:

NameTypeAttributeDescription
renderTextureRenderTexture

Mobilizing.RenderTexture object

public setToPixel() source

Tries to adjust the cam z distance so that 1 world unit == 1 screen pixel. Useful to make object move at the mouse or touch position x and y. For perspective cam only.

public setVerticalShift(the: Number) source

Sets the vertical shift ratio of the camera view

Params:

NameTypeAttributeDescription
theNumber

ratio (1 -> 100%)

public setZoom(zoom: Number) source

Zoom is for ortho cam and mimics the Z translation of perspective cams. This is expressed like a scale, zoom = 2 will double, .5 make it half.

Params:

NameTypeAttributeDescription
zoomNumber

value

Private Methods

private updateProjectionMatrix() source

recompute the projection matrix of this camera to reflect properly properties changes