SceneCamera:look_at
methodAim the camera at a world-space point. up defaults to world Y.
-- A world-space point; up is +Y unless given.
camera.pos = vec3(6, 4, 0)
camera:look_at(vec3(0, 0.5, 0))handle4 methods, 3 fields
The scene's camera. Read/write .pos, .rotation, .fov (radians); aim it with :look_at; tween it with :animate.
Scene.cameraScene.cameraThe examples on this page start from:
local vec3 = datumhue.math.vec3
local scene = datumhue.scene.new({ width = 320, height = 240 })
scene:mount({ width = 320, height = 240 })
scene:directional_light({ direction = vec3(-1, -2, -1) })
scene:cube({ pos = vec3(0, 0.5, 0) })
local camera = scene.camera| Field | Type | Access | Description |
|---|---|---|---|
pos | Vec3 | read/write | Camera world-space position. |
rotation | Quat | read/write | Camera orientation. |
fov | number | read/write | Vertical field of view in radians. |
Aim the camera at a world-space point. up defaults to world Y.
-- A world-space point; up is +Y unless given.
camera.pos = vec3(6, 4, 0)
camera:look_at(vec3(0, 0.5, 0))SceneCamera:animate(opts: scene.CameraAnimateOptions)Tween the camera's position, orientation, and field of view over duration seconds with the given easing curve.
-- Fly in over 2 seconds, ending aimed at the cube; fov is in radians.
camera:animate({
pos = vec3(0, 2, 4),
look_at = vec3(0, 0.5, 0),
fov = math.rad(40),
duration = 2,
easing = "cubic_in_out",
})opts scene.CameraAnimateOptions options 6 keys
| Key | Type | Default | Description |
|---|---|---|---|
| pos | Vec3 | the position is not tweened | Target world-space position. |
| rotation | Quat | the orientation is not tweened unless look_at is given | Target orientation. Mutually exclusive with look_at. |
| look_at | Vec3 | the orientation is not tweened unless rotation is given | World-space point to end up facing. Resolved to a target rotation once, when the tween starts — against pos when both are given, so the end pose faces the point; the camera does not track the point afterwards. Mutually exclusive with rotation. |
| fov | number | the field of view is not tweened | Target vertical field of view in radians. Ignored on a non-perspective camera, like .fov assignment. |
| duration | number | 1 | Tween duration in seconds. |
| easing | Easing | "linear" | Easing curve. |
In the guide: 3D scenes
SceneCamera:set_orthographic(height: number)Switch the camera to an orthographic projection. height is the world-space vertical extent visible; the horizontal extent follows the scene's aspect ratio.
In the guide: 3D scenes
SceneCamera:set_perspective(fov: number)Switch the camera to a perspective projection with the given vertical field of view (radians).