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
Dimension | Orthogonal basis | Affine transform | Projective transform |
---|---|---|---|
2D | Transform2D (2x3) | ||
3D | Basis (3x3) | Transform3D (3x4) | Projection (4x4) |
§Godot docs
Fields§
§cols: [Vector4; 4]
The columns of the projection matrix.
Implementations§
§impl Projection
impl Projection
pub const IDENTITY: 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 = _
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
pub fn determinant(&self) -> f32
Return the determinant of the matrix.
pub fn flipped_y(self) -> Projection
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 far_plane_half_extents(&self) -> Vector2
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
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
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
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
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
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
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
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
pub fn inverse(self) -> Projection
Returns a Projection that performs the inverse of this Projection’s projective transformation.
pub fn is_orthogonal(&self) -> bool
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
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
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
impl ApproxEq for Projection
fn approx_eq(&self, other: &Projection) -> bool
§impl ArrayElement for Projection
impl ArrayElement for Projection
fn debug_validate_elements(_array: &Array<Self>) -> Result<(), ConvertError>
§impl Clone for Projection
impl Clone for Projection
§fn clone(&self) -> Projection
fn clone(&self) -> Projection
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§impl Debug for Projection
impl Debug for Projection
§impl Default for Projection
impl Default for Projection
§fn default() -> Projection
fn default() -> Projection
§impl Display for Projection
impl Display for Projection
§fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
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
impl Export for Projection
§fn export_hint() -> PropertyHintInfo
fn export_hint() -> PropertyHintInfo
§fn as_node_class() -> Option<ClassName>
fn as_node_class() -> Option<ClassName>
§impl From<Transform3D> for Projection
impl From<Transform3D> for Projection
§fn from(trans: Transform3D) -> Projection
fn from(trans: Transform3D) -> Projection
§impl FromGodot for Projection
impl FromGodot for Projection
§fn try_from_godot(
via: <Projection as GodotConvert>::Via,
) -> Result<Projection, ConvertError>
fn try_from_godot( via: <Projection as GodotConvert>::Via, ) -> Result<Projection, ConvertError>
Err
on failure.§fn from_godot(via: Self::Via) -> Self
fn from_godot(via: Self::Via) -> Self
§fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
Variant
, returning Err
on failure.§fn from_variant(variant: &Variant) -> Self
fn from_variant(variant: &Variant) -> Self
§impl GodotConvert for Projection
impl GodotConvert for Projection
§type Via = Projection
type Via = Projection
Self
is represented in Godot.§impl Mul<Vector4> for Projection
impl Mul<Vector4> for Projection
§impl Mul for Projection
impl Mul for Projection
§type Output = Projection
type Output = Projection
*
operator.§fn mul(self, rhs: Projection) -> <Projection as Mul>::Output
fn mul(self, rhs: Projection) -> <Projection as Mul>::Output
*
operation. Read more§impl PartialEq for Projection
impl PartialEq for Projection
§impl ToGodot for Projection
impl ToGodot for Projection
§type ToVia<'v> = <Projection as GodotConvert>::Via
type ToVia<'v> = <Projection as GodotConvert>::Via
to_godot()
, which differs from Via
for pass-by-reference types.§fn to_godot(&self) -> <Projection as ToGodot>::ToVia<'_>
fn to_godot(&self) -> <Projection as ToGodot>::ToVia<'_>
§fn to_variant(&self) -> Variant
fn to_variant(&self) -> Variant
§impl Var for Projection
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
fn var_hint() -> PropertyHintInfo
GodotType::property_info
, e.g. for enums/newtypes.impl Copy for Projection
impl GodotType for Projection
impl StructuralPartialEq for Projection
Auto Trait Implementations§
impl Freeze for Projection
impl RefUnwindSafe for Projection
impl Send for Projection
impl Sync for Projection
impl Unpin for Projection
impl UnwindSafe for Projection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)