Skip to content

Frame3D

Mojo struct 🡭

Frame3D

@memory_only
struct Frame3D

A camera, the data extent it views, and the plot rect it draws into: everything needed to turn a data point into a pixel.

Built by _fit_frame3d, which measures the projected cube and chooses the scale and offset. Marks call to_pixel per vertex and depth to sort what to draw first.

Fields

  • camera (Camera3D)
  • extent (_Extent3D)
  • scale (Float64)
  • cx (Float64)
  • cy (Float64)

Implemented traits

AnyType, Deinitable, Movable

Methods

__init__

fn def __init__(out self, camera: Camera3D, extent: _Extent3D, scale: Float64, cx: Float64, cy: Float64)

Build a fitted frame.

Args:

  • camera (Camera3D): The view.
  • extent (_Extent3D): The data ranges.
  • scale (Float64): Pixels per unit of camera space, the same in both directions.
  • cx (Float64): Pixel x the camera-space origin lands on.
  • cy (Float64): Pixel y it lands on.
  • self (Self)

Returns:

Self

project

fn def project(self, x: Float64, y: Float64, z: Float64) -> Projected

A data point in camera space, normalised and projected but not yet in pixels.

Args:

  • self (Self)
  • x (Float64): Data x.
  • y (Float64): Data y.
  • z (Float64): Data z.

Returns:

Projected: Camera-space position and depth.

to_pixel

fn def to_pixel(self, x: Float64, y: Float64, z: Float64) -> Tuple[Float64, Float64]

A data point’s pixel position.

The y flip lives here: camera space points up, pixel rows grow downward, and this is the one place the two meet.

Args:

  • self (Self)
  • x (Float64): Data x.
  • y (Float64): Data y.
  • z (Float64): Data z.

Returns:

Tuple[Float64, Float64]: (pixel_x, pixel_y).

depth

fn def depth(self, x: Float64, y: Float64, z: Float64) -> Float64

A data point’s sort key, larger being farther from the camera.

Args:

  • self (Self)
  • x (Float64): Data x.
  • y (Float64): Data y.
  • z (Float64): Data z.

Returns:

Float64: The depth.