Struct citro3d::math::Projection

source ·
pub struct Projection<Kind> { /* private fields */ }
Expand description

Configuration for a 3D projection. See specific Kind implementations for constructors, e.g. Projection::perspective and Projection::orthographic.

To use the resulting projection, convert it to a Matrix4 with [From]/[Into].

Implementations§

source§

impl<Kind> Projection<Kind>

source

pub fn coordinates(self, orientation: CoordinateOrientation) -> Self

Set the coordinate system’s orientation for the projection. See CoordinateOrientation for more details.

§Example
let clip_planes = ClipPlanes {
    near: 0.1,
    far: 100.0,
};
let mtx: Matrix4 = Projection::perspective(40.0,  AspectRatio::TopScreen, clip_planes)
    .coordinates(CoordinateOrientation::LeftHanded)
    .into();
source

pub fn screen(self, orientation: ScreenOrientation) -> Self

Set the screen rotation for the projection. See ScreenOrientation for more details.

§Example
let clip_planes = ClipPlanes {
    near: 0.1,
    far: 100.0,
};
let mtx: Matrix4 = Projection::perspective(40.0, AspectRatio::TopScreen, clip_planes)
    .screen(ScreenOrientation::None)
    .into();
source§

impl Projection<Perspective>

source

pub fn perspective( vertical_fov_radians: f32, aspect_ratio: AspectRatio, clip_planes: ClipPlanes ) -> Self

Construct a projection matrix suitable for projecting 3D world space onto the 3DS screens.

§Parameters
  • vertical_fov: the vertical field of view, measured in radians
  • aspect_ratio: the aspect ratio of the projection
  • clip_planes: the near and far clip planes of the view frustum. ClipPlanes are always defined by near and far values, regardless of the projection’s CoordinateOrientation.
§Examples
let clip_planes = ClipPlanes {
    near: 0.01,
    far: 100.0,
};

let bottom: Matrix4 =
    Projection::perspective(PI / 4.0, AspectRatio::BottomScreen, clip_planes).into();

let top: Matrix4 =
    Projection::perspective(PI / 4.0, AspectRatio::TopScreen, clip_planes).into();
source

pub fn stereo_matrices( self, left_eye: StereoDisplacement, right_eye: StereoDisplacement ) -> (Matrix4, Matrix4)

Helper function to build both eyes’ perspective projection matrices at once. See StereoDisplacement for details on how to configure stereoscopy.

let (left, right) = StereoDisplacement::new(0.5, 2.0);
let (left_eye, right_eye) = Projection::perspective(
    PI / 4.0,
    AspectRatio::TopScreen,
    ClipPlanes {
        near: 0.01,
        far: 100.0,
    },
)
.stereo_matrices(left, right);
source§

impl Projection<Orthographic>

source

pub fn orthographic( clip_planes_x: Range<f32>, clip_planes_y: Range<f32>, clip_planes_z: ClipPlanes ) -> Self

Construct an orthographic projection. The X and Y clip planes are passed as ranges because their coordinates are always oriented the same way (+X right, +Y up).

The Z ClipPlanes, however, are always defined by near and far values, regardless of the projection’s CoordinateOrientation.

§Example
let mtx: Matrix4 = Projection::orthographic(
    0.0..240.0,
    0.0..400.0,
    ClipPlanes {
        near: 0.0,
        far: 100.0,
    },
)
.into();

Trait Implementations§

source§

impl<Kind: Clone> Clone for Projection<Kind>

source§

fn clone(&self) -> Projection<Kind>

Returns a copy of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
source§

impl<Kind: Debug> Debug for Projection<Kind>

source§

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

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

impl From<Projection<Orthographic>> for Matrix4

source§

fn from(projection: Projection<Orthographic>) -> Self

Converts to this type from the input type.
source§

impl From<Projection<Perspective>> for Matrix4

source§

fn from(projection: Projection<Perspective>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<Kind> RefUnwindSafe for Projection<Kind>
where Kind: RefUnwindSafe,

§

impl<Kind> Send for Projection<Kind>
where Kind: Send,

§

impl<Kind> Sync for Projection<Kind>
where Kind: Sync,

§

impl<Kind> Unpin for Projection<Kind>
where Kind: Unpin,

§

impl<Kind> UnwindSafe for Projection<Kind>
where Kind: UnwindSafe,

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.