Cauldron3D.View (Cauldron3D v0.2.2)

Copy Markdown View Source

A camera fitted to a picture: the projection from the world to pixels.

view = Cauldron3D.View.new(camera, {320, 200})
Cauldron3D.View.to_camera(view, point)

Pixel {0, 0} is the top left. :pixel_aspect is a pixel's height over its width, 1.0 for square pixels; a taller pixel squeezes the picture's height so circles stay round.

A point in camera space is {right, up, depth}. Projected, it is {x, y, nearness, w}: the pixel position, a value that grows toward the camera and changes linearly across the picture (for comparing what is in front), and the factor attributes are carried through by for perspective-correct interpolation (1 / depth in perspective, 1.0 orthographic).

Summary

Functions

Whether a point in the world is in front of the camera's near plane.

The view of camera in a picture {width, height}. Takes :pixel_aspect, default 1.0.

A camera-space point projected: {x, y, nearness, w}. The depth must be above zero in perspective.

The direction from the camera through the centre of pixel {x, y}, in the world, not of length one.

A world point in camera space, {right, up, depth}.

Types

t()

@type t() :: %Cauldron3D.View{
  camera: Cauldron3D.Camera.t(),
  center_x: float(),
  center_y: float(),
  forward: Cauldron3D.Vec.t(),
  height: pos_integer(),
  near: float(),
  origin: Cauldron3D.Vec.t(),
  perspective?: boolean(),
  right: Cauldron3D.Vec.t(),
  scale_x: float(),
  scale_y: float(),
  up: Cauldron3D.Vec.t(),
  width: pos_integer()
}

Functions

in_front?(view, point)

@spec in_front?(t(), Cauldron3D.Vec.t()) :: boolean()

Whether a point in the world is in front of the camera's near plane.

new(camera, arg, opts \\ [])

@spec new(Cauldron3D.Camera.t(), {pos_integer(), pos_integer()}, keyword()) :: t()

The view of camera in a picture {width, height}. Takes :pixel_aspect, default 1.0.

project(view, arg)

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

A camera-space point projected: {x, y, nearness, w}. The depth must be above zero in perspective.

ray(view, x, y)

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

The direction from the camera through the centre of pixel {x, y}, in the world, not of length one.

to_camera(view, point)

@spec to_camera(t(), Cauldron3D.Vec.t()) :: Cauldron3D.Vec.t()

A world point in camera space, {right, up, depth}.