godot::builtin

Struct Projection

#[repr(C)]
pub struct Projection { pub cols: [Vector4; 4], }
Expand description

A 4x4 matrix used for 3D projective transformations.

Projection can represent transformations such as translation, rotation, scaling, shearing, and perspective division. It consists of four Vector4 columns. It is used internally as Camera3D’s projection matrix.

For purely linear transformations (translation, rotation, and scale), it is recommended to use Transform3D, as that is more performant and has a lower memory footprint.

This builtin comes with two related types ProjectionEye and ProjectionPlane, that are type-safe pendants to Godot’s integers.

§All matrix types

DimensionOrthogonal basisAffine transformProjective transform
2DTransform2D (2x3)
3DBasis (3x3)Transform3D (3x4)Projection (4x4)

§Godot docs

Projection (stable)

Fields§

§cols: [Vector4; 4]

The columns of the projection matrix.

Implementations§

§

impl Projection

pub const IDENTITY: Projection = _

A Projection with no transformation defined. When applied to other data structures, no transformation is performed.

pub const ZERO: Projection = _

A Projection with all values initialized to 0. When applied to other data structures, they will be zeroed.

pub const fn new(cols: [Vector4; 4]) -> Projection

Create a new projection from a list of column vectors.

pub const fn from_diagonal(x: f32, y: f32, z: f32, w: f32) -> Projection

Create a diagonal matrix from the given values.

pub const fn from_cols( x: Vector4, y: Vector4, z: Vector4, w: Vector4, ) -> Projection

Create a matrix from four column vectors.

Godot equivalent: Projection(Vector4 x_axis, Vector4 y_axis, Vector4 z_axis, Vector4 w_axis)

pub fn create_depth_correction(flip_y: bool) -> Projection

Creates a new Projection that projects positions from a depth range of -1 to 1 to one that ranges from 0 to 1, and flips the projected positions vertically, according to flip_y.

Godot equivalent: Projection.create_depth_correction()

pub fn create_fit_aabb(aabb: Aabb) -> Projection

Creates a new Projection that scales a given projection to fit around a given AABB in projection space.

Godot equivalent: Projection.create_fit_aabb()

pub fn create_for_hmd( eye: ProjectionEye, aspect: f32, intraocular_dist: f32, display_width: f32, display_to_lens: f32, oversample: f32, near: f32, far: f32, ) -> Projection

Creates a new Projection for projecting positions onto a head-mounted display with the given X:Y aspect ratio, distance between eyes, display width, distance to lens, oversampling factor, and depth clipping planes.

Godot equivalent: Projection.create_for_hmd()

pub fn create_frustum( left: f32, right: f32, bottom: f32, top: f32, near: f32, far: f32, ) -> Projection

Creates a new Projection that projects positions in a frustum with the given clipping planes.

Godot equivalent: Projection.create_frustum()

pub fn create_frustum_aspect( size: f32, aspect: f32, offset: Vector2, near: f32, far: f32, flip_fov: bool, ) -> Projection

Creates a new Projection that projects positions in a frustum with the given size, X:Y aspect ratio, offset, and clipping planes.

flip_fov determines whether the projection’s field of view is flipped over its diagonal.

Godot equivalent: Projection.create_frustum_aspect()

pub fn create_light_atlas_rect(rect: Rect2) -> Projection

Creates a new Projection that projects positions into the given Rect2.

Godot equivalent: Projection.create_light_atlas_rect()

pub fn create_orthogonal( left: f32, right: f32, bottom: f32, top: f32, near: f32, far: f32, ) -> Projection

Creates a new Projection that projects positions using an orthogonal projection with the given clipping planes.

Godot equivalent: Projection.create_orthogonal()

pub fn create_orthogonal_aspect( size: f32, aspect: f32, near: f32, far: f32, flip_fov: bool, ) -> Projection

Creates a new Projection that projects positions using an orthogonal projection with the given size, X:Y aspect ratio, and clipping planes.

flip_fov determines whether the projection’s field of view is flipped over its diagonal.

Godot equivalent: Projection.create_orthogonal_aspect()

pub fn create_perspective( fov_y: f32, aspect: f32, near: f32, far: f32, flip_fov: bool, ) -> Projection

Creates a new Projection that projects positions using a perspective projection with the given Y-axis field of view (in degrees), X:Y aspect ratio, and clipping planes

flip_fov determines whether the projection’s field of view is flipped over its diagonal.

Godot equivalent: Projection.create_perspective()

pub fn create_perspective_hmd( fov_y: f32, aspect: f32, near: f32, far: f32, flip_fov: bool, eye: ProjectionEye, intraocular_dist: f32, convergence_dist: f32, ) -> Projection

Creates a new Projection that projects positions using a perspective projection with the given Y-axis field of view (in degrees), X:Y aspect ratio, and clipping distances. The projection is adjusted for a head-mounted display with the given distance between eyes and distance to a point that can be focused on.

flip_fov determines whether the projection’s field of view is flipped over its diagonal.

Godot equivalent: Projection.create_perspective_hmd()

pub fn create_fovy(fov_x: f32, aspect: f32) -> f32

Returns the vertical field of view of a projection (in degrees) which has the given horizontal field of view (in degrees) and aspect ratio.

Godot equivalent: Projection.get_fovy()

pub fn determinant(&self) -> f32

Return the determinant of the matrix.

pub fn flipped_y(self) -> Projection

Returns a copy of this projection, with the signs of the values of the Y column flipped.

pub fn aspect(&self) -> f32

Returns the X:Y aspect ratio of this Projection’s viewport.

pub fn far_plane_half_extents(&self) -> Vector2

Returns the dimensions of the far clipping plane of the projection, divided by two.

pub fn fov(&self) -> f32

Returns the horizontal field of view of the projection (in degrees).

Godot equivalent: Projection.get_fov()

pub fn lod_multiplier(&self) -> f32

Returns the factor by which the visible level of detail is scaled by this Projection.

Godot equivalent: Projection.get_lod_multiplier()

pub fn get_pixels_per_meter(&self, pixel_width: i64) -> i64

Returns the number of pixels with the given pixel width displayed per meter, after this Projection is applied.

Godot equivalent: Projection.get_pixels_per_meter()

pub fn get_projection_plane(&self, plane: ProjectionPlane) -> Plane

Returns the clipping plane of this Projection whose index is given by plane.

Godot equivalent: Projection.get_projection_plane()

pub fn viewport_half_extents(&self) -> Vector2

Returns the dimensions of the viewport plane that this Projection projects positions onto, divided by two.

Godot equivalent: Projection.get_viewport_half_extents()

pub fn z_far(&self) -> f32

Returns the distance for this Projection beyond which positions are clipped.

Godot equivalent: Projection.get_z_far()

pub fn z_near(&self) -> f32

Returns the distance for this Projection before which positions are clipped.

Godot equivalent: Projection.get_z_near()

pub fn inverse(self) -> Projection

Returns a Projection that performs the inverse of this Projection’s projective transformation.

pub fn is_orthogonal(&self) -> bool

Returns true if this Projection performs an orthogonal projection.

Godot equivalent: Projection.is_orthogonal()

pub fn jitter_offset(&self, offset: Vector2) -> Projection

Returns a Projection with the X and Y values from the given Vector2 added to the first and second values of the final column respectively.

Godot equivalent: Projection.jitter_offseted()

pub fn perspective_znear_adjusted(&self, new_znear: f32) -> Projection

Returns a Projection with the near clipping distance adjusted to be new_znear.

Note: The original Projection must be a perspective projection.

Godot equivalent: Projection.perspective_znear_adjusted()

Trait Implementations§

§

impl ApproxEq for Projection

§

fn approx_eq(&self, other: &Projection) -> bool

§

impl Clone for Projection

§

fn clone(&self) -> Projection

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
§

impl Debug for Projection

§

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

Formats the value using the given formatter. Read more
§

impl Default for Projection

§

fn default() -> Projection

Returns the “default value” for a type. Read more
§

impl Display for Projection

§

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

Formats Projection to match Godot’s string representation.

§Example
let proj = Projection::new([
    Vector4::new(1.0, 2.5, 1.0, 0.5),
    Vector4::new(0.0, 1.5, 2.0, 0.5),
    Vector4::new(0.0, 0.0, 3.0, 2.5),
    Vector4::new(3.0, 1.0, 4.0, 1.5),
]);

const FMT_RESULT: &str = r"
1, 0, 0, 3
2.5, 1.5, 0, 1
1, 2, 3, 4
0.5, 0.5, 2.5, 1.5
";

assert_eq!(format!("{}", proj), FMT_RESULT);
§

impl Export for Projection

§

fn export_hint() -> PropertyHintInfo

The export info to use for an exported field of this type, if no other export info is specified.
§

impl From<Transform3D> for Projection

§

fn from(trans: Transform3D) -> Projection

Converts to this type from the input type.
§

impl FromGodot for Projection

§

fn try_from_godot( via: <Projection as GodotConvert>::Via, ) -> Result<Projection, ConvertError>

Converts the Godot representation to this type, returning Err on failure.
§

fn from_godot(via: Self::Via) -> Self

⚠️ Converts the Godot representation to this type. Read more
§

fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>

Performs the conversion from a Variant, returning Err on failure.
§

fn from_variant(variant: &Variant) -> Self

⚠️ Performs the conversion from a Variant. Read more
§

impl GodotConvert for Projection

§

type Via = Projection

The type through which Self is represented in Godot.
§

impl Mul<Vector4> for Projection

§

type Output = Vector4

The resulting type after applying the * operator.
§

fn mul(self, rhs: Vector4) -> <Projection as Mul<Vector4>>::Output

Performs the * operation. Read more
§

impl Mul for Projection

§

type Output = Projection

The resulting type after applying the * operator.
§

fn mul(self, rhs: Projection) -> <Projection as Mul>::Output

Performs the * operation. Read more
§

impl ParamType for Projection

§

fn owned_to_arg<'v>(self) -> <Projection as ParamType>::Arg<'v>

Converts an owned value to the canonical argument type, which can be passed to impl AsArg<T>. Read more
§

impl PartialEq for Projection

§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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.
§

impl ToGodot for Projection

§

type ToVia<'v> = <Projection as GodotConvert>::Via

Target type of to_godot(), which can differ from Via for pass-by-reference types. Read more
§

fn to_godot(&self) -> <Projection as ToGodot>::ToVia<'_>

Converts this type to the Godot type by reference, usually by cloning.
§

fn to_variant(&self) -> Variant

Converts this type to a Variant.
§

impl Var for Projection

§

fn get_property(&self) -> <Projection as GodotConvert>::Via

§

fn set_property(&mut self, value: <Projection as GodotConvert>::Via)

§

fn var_hint() -> PropertyHintInfo

Specific property hints, only override if they deviate from GodotType::property_info, e.g. for enums/newtypes.
§

impl ArrayElement for Projection

§

impl AsArg<Projection> for Projection

§

impl Copy for Projection

§

impl GodotType for Projection

§

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> 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> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. 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.