Skip to content

UWAL / Camera2D

Classes ​

Camera2D ​

Camera manager class for scenes using 2D nodes and shapes.

Extends ​

  • Node2D

Properties ​

CullTest ​
ts
CullTest: 0 | 1 | 2 = 2;

Defaults to axis-aligned bounding box.

Constructors ​

Constructor ​
ts
new Camera2D(rendererWidth?, height?): Camera2D;
Parameters ​
ParameterTypeDefault valueDescription
rendererWidth?number | RenderStageinnerWidthWidth of the viewport or a Renderer instance.
height?numberinnerHeightHeight of the viewport, optional when called with a Renderer instance.
Returns ​

Camera2D

Overrides ​
ts
Node2D.constructor

Methods ​

UpdateProjectionMatrix() ​
ts
UpdateProjectionMatrix(): void;

Compute the projection matrix and write the result into the corresponding uniform buffer if present.

Returns ​

void

SetRenderPipeline() ​
ts
SetRenderPipeline(Pipeline): GPUBuffer;

Create and update an internal uniform buffer of this camera's projection matrix.

Parameters ​
ParameterTypeDescription
PipelineRenderPipelineInstancePipeline using this camera's projection.
Returns ​

GPUBuffer

Contains() ​
ts
Contains(Shape): boolean;

Check if a shape is contained in the camera's viewport when cull testing is performed. This method is called internally on every render when cull testing is enabled.

Parameters ​
ParameterTypeDescription
ShapeShape2D shape to test for culling.
Returns ​

boolean

Whether the shape is in the camera's viewport.

Destroy() ​
ts
Destroy(): void;

Destroy the internal projection matrix buffer.

Returns ​

void

Accessors ​

MatrixBuffer ​
Get Signature ​
ts
get MatrixBuffer(): GPUBuffer | undefined;
Returns ​

GPUBuffer | undefined

Matrix buffer created by the SetRenderPipeline method.

Size ​
Set Signature ​
ts
set Size(size): void;
Parameters ​
ParameterTypeDescription
sizenumber[] | Float32Array<ArrayBufferLike>Camera's viewport width and height.
Returns ​

void

PositionZ ​
Set Signature ​
ts
set PositionZ(z): void;
Parameters ​
ParameterTypeDescription
znumberCamera's position on the Z-axis used in light calculations.
Returns ​

void

Position3D ​
Get Signature ​
ts
get Position3D(): Float32Array<ArrayBufferLike>;
Returns ​

Float32Array<ArrayBufferLike>

Camera's position in 3D space.

Released under the MIT License.