Skip to main content

Projection

Enum Projection 

Source
pub enum Projection {
    Perspective {
        fov_y: f32,
        near: f32,
    },
    Orthographic {
        half_height: f32,
        near: f32,
        far: f32,
    },
}
Expand description

How a camera flattens the world into clip space.

Two variants and one code path: stage 2’s milestone 5 is “orthographic camera mode proving the 2D story (z = z-index) is just a projection matrix swap”, and this enum is that proof’s shape. Nothing downstream of Camera::view_projection — not the shader, not the pipeline, not the render graph — can tell which variant produced the matrix it was handed.

Variants§

§

Perspective

Infinite-far reversed-Z perspective.

There is no far field, and its absence is the design: an infinite far plane is free under reversed-Z (it costs one matrix element, not precision) and it removes the “what should the far plane be?” question from every caller in a world measured in sectors.

Fields

§fov_y: f32

Vertical field of view, in radians.

§near: f32

Distance to the near plane. Must be positive; this is the only number that controls depth precision under reversed-Z, so it is worth raising rather than lowering.

§

Orthographic

Reversed-Z orthographic.

The 2D mode. half_height is half the visible world height; the width follows from the aspect ratio, so a resize changes what is visible horizontally and never squashes the picture.

Fields

§half_height: f32

Half the visible height, in world units.

§near: f32

Near plane distance along the view direction.

§far: f32

Far plane distance along the view direction. Finite, unlike the perspective case: an orthographic projection is linear in depth, so an infinite far plane would map every finite z to 1.0.

Implementations§

Source§

impl Projection

Source

pub fn matrix(self, aspect: f32) -> Mat4

The projection matrix for an aspect (width ÷ height) viewport.

The result maps to Y-up NDC with depth in 0..1. Y-up rather than Vulkan’s native Y-down because crcbl-vk submits a negative-height viewport, so the seam’s convention is +Y up and a backend that did not flip would be the one out of step. Depth 0..1 because that is what every backend this engine targets uses; only the direction is unusual.

§Panics

If aspect is not finite and positive, or if a distance is not positive — all of which are caller bugs that otherwise produce a NaN matrix and a blank screen with no error anywhere.

Source

pub const fn is_orthographic(self) -> bool

Whether this is the 2D mode.

Source

pub fn pixels_per_unit(self, height: f32) -> f32

How many pixels one unit of length subtends one unit from the eye, in a viewport height pixels tall.

Topic 25’s scale factor: the number that carries a frame’s size and field of view into a screen-space error, so a level’s stored error in world units becomes the pixels its simplification would cost. ClusterSelect::is_drawn divides it by the distance to the group’s sphere, which is where the perspective falloff comes from.

An orthographic projection has no falloff at all, so for that variant this is the whole scale factor and dividing it by a distance is wrong. The value returned is still the right one — half the viewport over half the visible height — and ForwardRenderer is what deals with the rest: it pairs an orthographic camera with a budget nothing satisfies, so the descent expands every group and draws the base level. That is the honest answer for a 2D mode rather than a distance term invented for it.

§Panics

On the same arguments matrix refuses: a field of view outside (0, π) or a non-positive half-height. height is not checked — a zero-height viewport gives zero pixels per unit, which is a budget nothing exceeds and a frame with no pixels in it.

Trait Implementations§

Source§

impl Clone for Projection

Source§

fn clone(&self) -> Self

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 Projection

Source§

impl Debug for Projection

Source§

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

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

impl Default for Projection

Source§

fn default() -> Self

A 45° vertical field of view with a 10 cm near plane.

Source§

impl PartialEq for Projection

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Projection

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> HalThreadSafe for T
where T: Send + Sync,

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.