Camera
Enum
Class | Type | Name | Interface Description |
---|---|---|---|
Enum | Enum | Enum.CameraClearType | • Function: Defines how the camera clears the buffer. |
Enum | Enum | Enum.CameraType | • Function: Defines the type of camera (e.g., perspective camera or orthographic camera). |
CameraType
Type | Enumeration Members | Interface Description |
---|---|---|
Enum | Ortho | Orthographic Camera |
Enum | Perspective | Perspective Camera |
CameraClearType
Type | Enumeration Members | Interface Description |
---|---|---|
Enum | Color | Clear color only |
Enum | ColorDepth | Clear color and depth |
Enum | ColorDepthStencil | Clear color, depth and stencil |
Enum | ColorStencil | Clear color and stencil |
Enum | Depth | Clear depth only |
Enum | DepthStencil | Clear depth and stencil |
Enum | Dont | Clear nothing |
Enum | Stencil | Clear stencil only |
Enum | Texture | Clear color with a texture |
Enum | TextureDepth | Clear depth with a texture |
Camera
Type | Name | Interface Description | Example |
---|---|---|---|
Variables | clearColor: Color | • Function: Defines the color used when the camera clears the buffer. | Code block 1 cam.clearColor = new 2 API.Color(1,0,0); |
Variables | clearType: CameraClearType | • Function: Specifies how the camera clears the buffer. | Code block 1 cam.clearType = 2 API.CameraClearType.ColorDep 3 thStencil; |
Examples
clearColor: Color
cam.clearColor = new APJS.Color(1,1,0);
clearType: CameraClearType
cam.clearType = APJS.CameraClearType.ColorDepthStencil;
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;
this.time += deltaTime;
camera.clearType = APJS.CameraClearType.Color;
camera.clearColor = new APJS.Color(
(Math.cos(this.time) + 1) * 0.5,
(Math.sin(this.time) + 1) * 0.5,
(this.time - Math.floor(this.time)));
}
}
Type | Name | Interface Description |
---|---|---|
Variables | orthographic.number | • Function: The height of the camera view in orthographic projection mode. |
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;
this.time += deltaTime;
camera.orthoHeight = 15 + Math.sin(this.time) * 3;
}
}
Type | Name | Interface Description |
---|---|---|
Variables | far: number | • Function: The distance of the camera's far clipping plane. |
Variables | near: number | • Function: The distance of the camera's near clipping plane. |
Examples
far: number
cam.far = 100;
near: number
cam.near = 0.1;
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;
this.time += deltaTime;
console.log(`near:${camera.near}\nfar:${camera.far}`);
}
}
Type | Name | Interface Description |
---|---|---|
Variables | fov: number | • Function: The field of view (FOV) of the camera, used in perspective projection mode. |
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;
this.time += deltaTime;
camera.fov = 60 + Math.sin(this.time) * 30;
}
}
Type | Name | Interface Description |
---|---|---|
Variables | inputTexture: Texture | null | • Function: Input texture which can serve as the input source for camera rendering. |
Example
cam.inputTexture = tex;
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
private texture;// get a texture in some way
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;
if (camera.inputTexture === null)
camera.inputTexture = this.texture;
else
camera.inputTexture = null;
}
}
Type | Name | Interface Description |
---|---|---|
Variables | renderLayer: LayerSet | • Function: Specify the layers visible to the camera. |
Example
cam.renderLayer = 1;
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;
console.log('renderLayer:',camera.renderLayer);
}
}
Type | Name | Interface Description |
---|---|---|
Variables | renderTexture: Texture | • Function: The output texture of camera rendering. |
Example
cam.renderTexture = outputTex;
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;
console.log('renderTexture:',camera.renderTexture.name);
}
}
Type | Name | Interface Description |
---|---|---|
Variables | viewport: Rect | • Function: Defines the viewport area rendered by the camera. |
Example
cam.viewport = new APJS.Rect(0,0,1,1);
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;
console.log('viewport:',camera.viewport);
}
}
Type | Name | Interface Description |
---|---|---|
Variables | renderOrder: number | • Function: Defines the rendering order of the camera. |
Example
camera.renderLayer = 2;
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;
console.log('renderLayer:',camera.renderLayer);
}
}
Type | Name | Interface Description |
---|---|---|
Variables | projectionMatrix: Matrix4x4f [Read Only] | • Function: The projection matrix of the camera. |
Example
let mat = cam.projectionMatrix;
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;
console.log('projectionMatrix:',camera.projectionMatrix);
}
}
Type | Name | Interface Description |
---|---|---|
Variables | cameraType: CameraType | • Function: The type of camera (perspective or orthographic). |
Example
cam.cameraType = APJS.CameraType.Ortho;
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;
console.log('cameraType:',camera.cameraType);
}
}
Type | Name | Interface Description |
---|---|---|
Functions | viewportWorldToBoid(point: Vector3f): Vector3f | • Function: Convert viewport coordinates to world coordinates. |
Example
camera.viewportToWorldPoint(new Vector3f(0.5,0.5,0.5));
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;
let viewportPoint = new Vector3f(0.5, 0.5, 0.5);
let worldPoint = camera.viewportToWorldPoint(viewportPoint);
console.log(`Viewport point ${viewportPoint} converted to world point ${worldPoint}`);
}
}
Type | Name | Interface Description |
---|---|---|
Functions | worldToViewportPoint(point: Vector3f): Vector3f | • Function: Convert world coordinates to viewport coordinates. |
Example
let viewportPoint = camera.worldToViewportPoint(new Vector3f(10,10,10));
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;
let worldPoint = new Vector3f(10, 10, 10);
let viewportPoint = camera.worldToViewportPoint(worldPoint);
console.log(`World point ${worldPoint} converted to viewport point ${viewportPoint}`);
}
Type | Name | Interface Description |
---|---|---|
Functions | screenToWorldPoint(screen: Vector3f): Vector3f | • Function: Convert screen coordinates to world coordinates. |
Example
let worldPointFromScreen = camera.screenToWorldPoint(new Vector2f(400, 300), 10);
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;
let screenPoint = new Vector2f(400, 300);
let depth = 10;
let worldPointFromScreen = camera.screenToWorldPoint(screenPoint, depth);
console.log(`Screen point ${screenPoint} with depth ${depth} converted to world point ${worldPointFromScreen}.`);
}
Type | Name | Interface Description |
---|---|---|
Functions | worldToViewportPoint(point: Vector3f): Vector3f | • Function: Convert world coordinates to screen coordinates. |
Example
let camera = new Camera();
let worldPoint = new Vector3f(10, 10, 10);
let screenPoint = camera.worldToScreenPoint(worldPoint);
console.log(World point ${worldPoint} converted to screen point ${screenPoint}.);
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;
let worldPoint = new Vector3f(10, 10, 10);
let screenPoint = camera.worldToScreenPoint(worldPoint);
console.log(`World point ${worldPoint} converted to screen point ${screenPoint}.`);
}
Type | Name | Interface Description |
---|---|---|
Functions | getCameraToWorldMatrix(): Matrix4x4f | • Returns: Matrix4x4f • Description: The transformation matrix from camera space to world space. • Description: Get the matrix that transforms from camera space to world space. Use this to calculate where in the world a specific camera space point is located. |
Functions | getWorldToCameraMatrix(): Matrix4x4f | • Returns: Matrix4x4f • Description: The transformation matrix from world space to camera space. • Description: Retrieves the matrix that transforms coordinates from world space to camera space. This matrix is commonly known as the "view matrix" in graphics literature. It can be used to determine the position of game objects in camera space or to specify a custom camera location independent of its transform. |
Functions | getLookAt(): Vector3f | • Returns: Vector3f • Description: The forward direction vector of the camera. • Description: Gets the camera's forward direction, also known as the "look at" direction. |
Functions | viewportPointToRay(viewportPoint: Vector2f): Ray | • Parameters: viewportPoint: Vector2f • Returns: Ray • Description: A point in viewport space represented as a Vector2f. • Returns: Ray • Description: The calculated world space ray as a Ray object. • Description: Generates a ray from the specified position in the camera's viewport space. |
Examples
getCameraToWorldMatrix(): Matrix4x4f
let mat = camera.getCameraToWorldMatrix()
getWorldToCameraMatrix(): Matrix4x4f
let mat = camera.getWorldToCameraMatrix()
getLookAt(): Vector3f
let vec = camera.getLookAt();
viewportPointToRay(viewportPos: Vector2f): Ray;
let ray = camera.viewportPointToRay(new Vector2f(0.5, 0.5));
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Camera');
let camera = child?.getComponent('Camera') as APJS.Camera;
if(!camera) return;
console.log("cameraToWorldMatrix",camera.getCameraToWorldMatrix());
console.log("worldToCameraMatrix",camera.getWorldToCameraMatrix());
console.log("getLookAt",camera.getLookAt());
const ray = camera.viewportPointToRay(new APJS.Vector2f(0.5, 0.5));
console.log("ray",ray);
}
}