ExRatatui.ThreeD.Camera (ExRatatui v0.11.0)

Copy Markdown View Source

A perspective camera looking at a target.

The camera is plain data; orbit/3 and zoom/2 are pure helpers that return a new camera, so an application drives them from key events and keeps the result in its own state.

Fields

  • :position - {x, y, z} eye position
  • :target - {x, y, z} look-at point
  • :up - {x, y, z} up vector (defaults to +Y)
  • :fov - vertical field of view in radians (defaults to pi/4)
  • :near - near clip plane (defaults to 0.1)
  • :far - far clip plane (defaults to 100.0)

Examples

iex> %ExRatatui.ThreeD.Camera{}
%ExRatatui.ThreeD.Camera{
  position: {0.0, 2.0, 5.0},
  target: {0.0, 0.0, 0.0},
  up: {0.0, 1.0, 0.0},
  fov: 0.7853981633974483,
  near: 0.1,
  far: 100.0
}

iex> cam = %ExRatatui.ThreeD.Camera{position: {0.0, 0.0, 5.0}}
iex> ExRatatui.ThreeD.Camera.zoom(cam, -2.0).position
{0.0, 0.0, 3.0}

Summary

Functions

Orbit the camera around its target by yaw and pitch deltas (radians).

Move the camera toward or away from its target along the view direction.

Types

t()

@type t() :: %ExRatatui.ThreeD.Camera{
  far: float(),
  fov: float(),
  near: float(),
  position: vec3(),
  target: vec3(),
  up: vec3()
}

vec3()

@type vec3() :: {number(), number(), number()}

Functions

orbit(camera, yaw, pitch)

@spec orbit(t(), number(), number()) :: t()

Orbit the camera around its target by yaw and pitch deltas (radians).

Pitch is clamped to avoid gimbal lock at the poles.

zoom(camera, delta)

@spec zoom(t(), number()) :: t()

Move the camera toward or away from its target along the view direction.

A positive delta moves farther; the distance is clamped to a small minimum.