Skip to content

Camera

View and projection. Attach to a Node via setNode(node) so the camera’s position and orientation follow the node.

Returns: Camera — A new camera. Attach it to a node with setNode and set a tag so Scene.findCameraByTag can find it.

Method / propertyReturns / ParametersDescription
getTag()StringTag string (e.g. for findCameraByTag)
setTag(tag)tag (String) — Set the tag
nodeNode or nullNode 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.

MethodReturnsParametersDescription
getViewMatrix()(matrix)View matrix (world → view space)
getProjectionMatrix(aspect)(matrix)aspect (Num) — width/heightProjection matrix for the given aspect ratio
getFovYRadians()NumVertical FOV in radians
setFovYRadians(r)r (Num)Set vertical FOV (radians)
getNearPlane()NumNear clip plane distance
setNearPlane(n)n (Num)Set near plane
getFarPlane()NumFar 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()

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).