Skip to main content

Camera

Struct Camera 

Source
pub struct Camera {
    pub pos: [f64; 3],
    pub right: [f64; 3],
    pub down: [f64; 3],
    pub forward: [f64; 3],
}
Expand description

Camera state. All vectors are in voxel-world units (1 unit = 1 voxel); the basis is right-handed with down aligned to +z (i.e. z grows downward into the map, matching voxlap’s coordinate system).

§Examples

use roxlap_core::Camera;

let cam = Camera::default();
assert_eq!(cam.pos, [1024.0, 1024.0, 128.0]);
assert_eq!(cam.forward, [0.0, 1.0, 0.0]); // looking +y (north)

Fields§

§pos: [f64; 3]

Camera position (ipo / dpoint3d in voxlaptest).

§right: [f64; 3]

Right vector (ist).

§down: [f64; 3]

Down vector (ihe).

§forward: [f64; 3]

Forward vector (ifo).

Implementations§

Source§

impl Camera

Source

pub fn from_yaw_pitch(pos: [f64; 3], yaw: f64, pitch: f64) -> Self

Build a camera from a position plus yaw / pitch (radians), with no roll.

This is the canonical voxlap-convention constructor: it reproduces oracle.c::set_camera_yaw_pitch bit-for-bit, so the frustum cull (which requires right × down = +forward) accepts sprites and the render matches the bit-exact oracle goldens. Any project that hand-rolls right = [-sin yaw, cos yaw, 0] should call this instead — that hand-rolled form is exactly this basis, and copying it by hand is the usual source of chirality mistakes.

yaw sweeps the world’s horizontal (x/y) plane: yaw = 0 looks down +x, increasing yaw turns toward +y. pitch tilts toward +z (down): pitch = 0 is level, positive pitch aims downward.

See the crate-level handedness notes for why the rendered image is horizontally mirrored versus a real camera and what to do if you need an un-mirrored world.

§Examples
use roxlap_core::Camera;

let cam = Camera::from_yaw_pitch([1024.0, 1024.0, 128.0], 0.0, 0.0);
// yaw = 0, pitch = 0 → looking down +x.
assert_eq!(cam.forward, [1.0, 0.0, 0.0]);
assert_eq!(cam.right, [0.0, 1.0, 0.0]);
assert_eq!(cam.down, [0.0, 0.0, 1.0]);

// Canonical chirality: right × down == +forward. The sprite
// frustum cull depends on this; `Camera::default`'s placeholder
// basis does *not* satisfy it.
let cross = [
    cam.right[1] * cam.down[2] - cam.right[2] * cam.down[1],
    cam.right[2] * cam.down[0] - cam.right[0] * cam.down[2],
    cam.right[0] * cam.down[1] - cam.right[1] * cam.down[0],
];
assert_eq!(cross, cam.forward);
Source

pub fn orbit(yaw: f64, pitch: f64, dist: f64, center: [f64; 3]) -> Self

Orbit camera: look at center from dist voxels away, at the given yaw / pitch. Heading conventions match Camera::from_yaw_pitch; the position is placed dist behind the forward axis so center sits on the view ray.

§Examples
use roxlap_core::Camera;

// yaw = 0 → forward = +x, so the eye sits at center − dist·(+x).
let cam = Camera::orbit(0.0, 0.0, 100.0, [1024.0, 1024.0, 128.0]);
assert_eq!(cam.forward, [1.0, 0.0, 0.0]);
assert_eq!(cam.pos, [924.0, 1024.0, 128.0]);
Source

pub fn look_at(eye: [f64; 3], target: [f64; 3]) -> Self

Look from eye toward target, with no roll (the right axis stays in the world’s horizontal plane). Produces the same canonical chirality as Camera::from_yaw_pitch by recovering yaw / pitch from the look direction.

If eye == target (or the look direction is purely vertical), yaw collapses to 0; the resulting basis is still orthonormal and correctly handed.

§Examples
use roxlap_core::Camera;

// Looking from x=924 toward x=1024 (i.e. down +x).
let cam = Camera::look_at([924.0, 1024.0, 128.0], [1024.0, 1024.0, 128.0]);
assert_eq!(cam.forward, [1.0, 0.0, 0.0]);
assert_eq!(cam.right, [0.0, 1.0, 0.0]);

Trait Implementations§

Source§

impl Clone for Camera

Source§

fn clone(&self) -> Camera

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Camera

Source§

impl Debug for Camera

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Camera

Source§

fn default() -> Self

Centred at the middle of a 2048-VSID map, looking +y, level. Matches the placeholder vectors voxlaptest’s oracle writes into the .vxl header (see tests/oracle/oracle.c).

Caution: this placeholder basis is left-handed (right × down = -forward). It is fine for the world raycaster, but the sprite frustum cull requires the canonical right-handed chirality (right × down = +forward) and will reject every sprite under this basis. For an interactive camera build the basis with Camera::from_yaw_pitch / Camera::orbit / Camera::look_at instead of starting from default() and rotating it. See the crate-level handedness notes.

Source§

impl PartialEq for Camera

Source§

fn eq(&self, other: &Camera) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Camera

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.