import Camera from '@mobilizing/library/js/Mobilizing/renderer/3D/three/scene/Camera.js'
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 | constructor(params: Object) |
Member Summary
Public Members | ||
public | aspect: * | |
public | autoClear: * | |
public | ||
public | ||
public | ||
public | autoRender: * | |
public | ||
public | clearColor: * | |
public | ||
public | context: * | |
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 | transform: * | |
public | type: * | |
public | ||
public | viewport: * |
Private Members | ||
private | _camera: * |
Method Summary
Public Methods | ||
public | ||
public | gets the aspect ratio of the camera view | |
public | getClearAlpha(): * | |
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 | getNativeObject(): * | |
public | Gets cam near plane | |
public | getRenderTexture(): * | |
public | getWolrdDirection(): * | |
public | Gets current zoom value. | |
public | 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 | setAutoClear(val: Boolean) Change the autoClear property of this camera. | |
public | setAutoClearColor(val: Boolean) Change the autoClearColor property of this camera. | |
public | setAutoClearDepth(val: Boolean) Change the setAutoClearDepth property of this camera. | |
public | setAutoClearStencil(val: Boolean) 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 | setFarPlane(far: Number) Sets cam far plane | |
public | setHorizontalShift(the: Number) 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 | setNearPlane(near: Number) Sets cam near plane | |
public | setOrthoPlanes(left: Number, right: Number, top: Number, bottom: Number) Method to recompute the frame of ortho cam. | |
public | Sets cam far and near planes | |
public | setRenderTexture(renderTexture: RenderTexture) Set the RenderTexture to render on. | |
public | Tries to adjust the cam z distance so that 1 world unit == 1 screen pixel. | |
public | setVerticalShift(the: Number) Sets the vertical shift ratio of the camera view | |
public | 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:
Name | Type | Attribute | Description |
params | Object | Parameters object, given by the constructor. | |
params.context | Context |
| mobilizing context to use |
params.type | String |
| One of "perspective", "ortho" or "cube" |
params.fov | Number |
| vertical field of view |
params.cubeResolution | Number |
| if the type is "cube", defines the size of the cubemap, must be a power of 2 |
params.near | Number |
| near plane |
params.far | Number |
| far plane |
params.viewport | 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.layer | Context |
| the layer in which to render the camera, that is the scene it is |
params.position | Vector3 |
| the position where to create the camera in space |
params.verticalshift | Number |
| vertical lens shift in % |
params.horizontalshift | Number |
| horizontal lens shift in % |
params.autoRender | Boolean |
| Should the camera automatically renders itself or not |
params.autoClear | Boolean |
| Should the camera automatically clears itself or not |
params.autoUpdateMatrix | Boolean |
| 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 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 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 getNativeObject(): * source
Return:
* | the Three.js native object used in this class |
public getRenderTexture(): * source
Return:
* |
public getWolrdDirection(): * source
Return:
* |
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:
Name | Type | Attribute | Description |
Vector3 | Object | 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
public setAspect(the: Number) source
Sets the aspect ratio of the camera view
Params:
Name | Type | Attribute | Description |
the | Number | ratio (ex. 4/3) |
public setAutoClear(val: Boolean) source
Change the autoClear property of this camera. Needed to had a "trail effect"
Params:
Name | Type | Attribute | Description |
val | Boolean |
public setAutoClearColor(val: Boolean) source
Change the autoClearColor property of this camera. Needed to had a "trail effect"
Params:
Name | Type | Attribute | Description |
val | Boolean |
public setAutoClearDepth(val: Boolean) source
Change the setAutoClearDepth property of this camera.
Params:
Name | Type | Attribute | Description |
val | Boolean |
public setAutoClearStencil(val: Boolean) source
Change the setAutoClearStencil property of this camera.
Params:
Name | Type | Attribute | Description |
val | Boolean |
public setAutoRender(val: Bool) source
Set the autoRender flag, which means that the camera will render itself automatically.
Params:
Name | Type | Attribute | Description |
val | Bool | 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.
public setFOV(fov: *) source
set the vertical field of view in degrees
Params:
Name | Type | Attribute | Description |
fov | * | {Number} default to 35 degree |
public setFarPlane(far: Number) source
Sets cam far plane
Params:
Name | Type | Attribute | Description |
far | Number | plane value |
public setHorizontalShift(the: Number) source
Sets the horizontal shift ratio of the camera view
Params:
Name | Type | Attribute | Description |
the | Number | ratio (1 -> 100%) |
public setLayer(name: String) source
Set this camera layer's name, which should match a renderer's scene name
Params:
Name | Type | Attribute | Description |
name | String |
public setNearPlane(near: Number) source
Sets cam near plane
Params:
Name | Type | Attribute | Description |
near | Number | 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.
public setRenderTexture(renderTexture: RenderTexture) source
Set the RenderTexture to render on. By default, the camera renders on the Context canvas.
Params:
Name | Type | Attribute | Description |
renderTexture | RenderTexture | 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:
Name | Type | Attribute | Description |
the | Number | 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:
Name | Type | Attribute | Description |
zoom | Number | value |
Private Methods
private updateProjectionMatrix() source
recompute the projection matrix of this camera to reflect properly properties changes