Cauldron3D.Camera (Cauldron3D v0.2.2)

Copy Markdown View Source

Where a picture is taken from: a position, a facing, and a projection.

The world is right-handed with z up. yaw turns about z, 0 facing +x and :math.pi() / 2 facing +y; pitch above zero looks up; roll above zero tips the picture clockwise. A :perspective camera sees fov radians across; an :orthographic one sees extent world units across, the same at every distance.

Cauldron3D.Camera.first_person({0.0, 0.0, 56.0}, yaw, pitch)
Cauldron3D.Camera.follow(target, yaw, distance: 120.0, height: 40.0)
Cauldron3D.Camera.side(target, extent: 640.0)
Cauldron3D.Camera.top_down(target, extent: 1024.0)

Summary

Functions

The camera's axes in the world: {forward, right, up}, each of length one.

A perspective camera at position looking along yaw and pitch. Takes new/1's options.

A perspective camera behind target, facing along yaw and looking down at it.

The direction yaw and pitch face, of length one.

A camera from options: :position, :yaw, :pitch, :roll, :projection, :fov, :extent and :near, each defaulting as the struct does.

An orthographic camera looking across the world at target from the -y side, as a side-scroller sees it. :extent (default 512.0) is how wide the view is; :distance (default 4096.0) how far back it stands.

An orthographic camera looking straight down at target, +y at the top of the picture. :extent (default 512.0) is how wide the view is; :distance (default 4096.0) how high it hangs.

Types

projection()

@type projection() :: :perspective | :orthographic

t()

@type t() :: %Cauldron3D.Camera{
  extent: float(),
  fov: float(),
  near: float(),
  pitch: float(),
  position: Cauldron3D.Vec.t(),
  projection: projection(),
  roll: float(),
  yaw: float()
}

Functions

basis(camera)

@spec basis(t()) :: {Cauldron3D.Vec.t(), Cauldron3D.Vec.t(), Cauldron3D.Vec.t()}

The camera's axes in the world: {forward, right, up}, each of length one.

first_person(position, yaw, pitch, opts \\ [])

@spec first_person(Cauldron3D.Vec.t(), number(), number(), keyword()) :: t()

A perspective camera at position looking along yaw and pitch. Takes new/1's options.

follow(target, yaw, opts \\ [])

@spec follow(Cauldron3D.Vec.t(), number(), keyword()) :: t()

A perspective camera behind target, facing along yaw and looking down at it.

Options

  • :distance — how far behind, default 128.0
  • :height — how far above the target the camera sits, default 48.0
  • :look_height — the height above the target the camera aims at, default 0.0
  • anything new/1 takes

forward(yaw, pitch)

@spec forward(number(), number()) :: Cauldron3D.Vec.t()

The direction yaw and pitch face, of length one.

new(opts \\ [])

@spec new(keyword()) :: t()

A camera from options: :position, :yaw, :pitch, :roll, :projection, :fov, :extent and :near, each defaulting as the struct does.

side(target, opts \\ [])

@spec side(Cauldron3D.Vec.t(), keyword()) :: t()

An orthographic camera looking across the world at target from the -y side, as a side-scroller sees it. :extent (default 512.0) is how wide the view is; :distance (default 4096.0) how far back it stands.

top_down(target, opts \\ [])

@spec top_down(Cauldron3D.Vec.t(), keyword()) :: t()

An orthographic camera looking straight down at target, +y at the top of the picture. :extent (default 512.0) is how wide the view is; :distance (default 4096.0) how high it hangs.