Skip to content

3D Camera

3D camera methods control the viewpoint used when rendering 3D content. Cameras can be positioned, rotated, aimed at targets, and configured with custom projection settings.

Method
clearZBuffer(displayId : DisplayID) : ()
getCameraInfo(displayId : DisplayID) : table
lookAt(displayId : DisplayID, targetX : number, targetY : number, targetZ : number) : ()
setCameraPosition(displayId : DisplayID, x : number, y : number, z : number) : ()
setCameraRotation(displayId : DisplayID, pitch : number, yaw : number, roll : number) : ()
setCameraTarget(displayId : DisplayID, x : number, y : number, z : number) : ()
setupCamera(displayId : DisplayID, fov : number, near : number, far : number) : table

Clears the depth buffer for a display.

Call this before rendering a new 3D frame to ensure old depth information does not affect the current frame.

Requires: DisplayID

gpu.clearZBuffer(displayId)

Returns the current camera configuration for a display.

Requires: DisplayID

Returns: Camera information table.

local info = gpu.getCameraInfo(displayId)
print(info)

Rotates the camera to face a world position.

Requires: DisplayID, targetX : number, targetY : number, targetZ : number

gpu.lookAt(displayId, 0, 0, 0)

Moves the camera to a specific world position.

Requires: DisplayID, x : number, y : number, z : number

gpu.setCameraPosition(displayId, 0, 2, 5)

Sets the camera rotation directly.

Rotation values are provided as:

  • pitch - rotation around the X axis
  • yaw - rotation around the Y axis
  • roll - rotation around the Z axis

Requires: DisplayID, pitch : number, yaw : number, roll : number

gpu.setCameraRotation(displayId, 10, 30, 0)

Sets the point the camera should target.

This can be used instead of manually controlling rotation.

Requires: DisplayID, x : number, y : number, z : number

gpu.setCameraTarget(displayId, 0, 0, 0)

Initializes the camera projection settings.

Common values:

  • fov: 60
  • near: 0.1
  • far: 1000

Requires: DisplayID, fov : number, near : number, far : number

Returns: Camera information table.

local info = gpu.setupCamera(
displayId,
60,
0.1,
1000
)