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>
impl<Kind> Projection<Kind>
sourcepub fn coordinates(self, orientation: CoordinateOrientation) -> Self
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();
sourcepub fn screen(self, orientation: ScreenOrientation) -> Self
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>
impl Projection<Perspective>
sourcepub fn perspective(
vertical_fov_radians: f32,
aspect_ratio: AspectRatio,
clip_planes: ClipPlanes
) -> Self
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 radiansaspect_ratio
: the aspect ratio of the projectionclip_planes
: the near and far clip planes of the view frustum.ClipPlanes
are always defined by near and far values, regardless of the projection’sCoordinateOrientation
.
§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();
sourcepub fn stereo_matrices(
self,
left_eye: StereoDisplacement,
right_eye: StereoDisplacement
) -> (Matrix4, Matrix4)
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>
impl Projection<Orthographic>
sourcepub fn orthographic(
clip_planes_x: Range<f32>,
clip_planes_y: Range<f32>,
clip_planes_z: ClipPlanes
) -> Self
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>
impl<Kind: Clone> Clone for Projection<Kind>
source§fn clone(&self) -> Projection<Kind>
fn clone(&self) -> Projection<Kind>
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more