Camera
View and projection. Attach to a Node via setNode(node) so the camera’s position and orientation follow the node.
Constructor
Section titled “Constructor”Camera.new()
Section titled “Camera.new()”Returns: Camera — A new camera. Attach it to a node with setNode and set a tag so Scene.findCameraByTag can find it.
Tag & node
Section titled “Tag & node”| Method / property | Returns / Parameters | Description |
|---|---|---|
getTag() | String | Tag string (e.g. for findCameraByTag) |
setTag(tag) | — | tag (String) — Set the tag |
node | Node or null | Node this camera is attached to |
setNode(node) | — | node (Node) — Attach camera to this node |
The camera’s view matrix is derived from the node’s world transform. Set the node’s position/rotation to move the camera.
View & projection
Section titled “View & projection”| Method | Returns | Parameters | Description |
|---|---|---|---|
getViewMatrix() | (matrix) | — | View matrix (world → view space) |
getProjectionMatrix(aspect) | (matrix) | aspect (Num) — width/height | Projection matrix for the given aspect ratio |
getFovYRadians() | Num | — | Vertical FOV in radians |
setFovYRadians(r) | — | r (Num) | Set vertical FOV (radians) |
getNearPlane() | Num | — | Near clip plane distance |
setNearPlane(n) | — | n (Num) | Set near plane |
getFarPlane() | Num | — | Far clip plane distance |
setFarPlane(f) | — | f (Num) | Set far plane |
Use with Graphics.setViewMatrix and Graphics.setProjectionMatrix when drawing the scene.
var aspect = Window.getWidth() / Window.getHeight()var view = _camera.getViewMatrix()var proj = _camera.getProjectionMatrix(aspect)Graphics.setViewMatrix(view)Graphics.setProjectionMatrix(proj)_scene.draw()Coordinate conversion
Section titled “Coordinate conversion”worldToScreen(worldX, worldY, worldZ, viewportWidth, viewportHeight)
Section titled “worldToScreen(worldX, worldY, worldZ, viewportWidth, viewportHeight)”Returns: List of three numbers [screenX, screenY, depth] or null if the point is behind the camera.
Parameters:
worldX,worldY,worldZ(Num) — World-space position.viewportWidth,viewportHeight(Num) — Viewport size in pixels.
Convert a world position to screen coordinates. screenX, screenY are in pixel space; depth is the depth buffer value or distance.
screenToWorld(screenX, screenY, depth, viewportWidth, viewportHeight)
Section titled “screenToWorld(screenX, screenY, depth, viewportWidth, viewportHeight)”Returns: List of three numbers [worldX, worldY, worldZ] — World position at the given screen point and depth.
Parameters:
screenX,screenY(Num) — Screen coordinates (e.g. mouse position).depth(Num) — Depth value or distance (e.g. 0 = near plane, 1 = far plane, or linear depth depending on implementation).viewportWidth,viewportHeight(Num) — Viewport size.
Convert a screen point and depth back to world space (e.g. for placing objects at the cursor).