godot::builtin

Struct Transform2D

#[repr(C)]
pub struct Transform2D { pub a: Vector2, pub b: Vector2, pub origin: Vector2, }
Expand description

Affine 2D transform (2x3 matrix).

Represents transformations such as translation, rotation, or scaling.

Expressed as a 2x3 matrix, this transform consists of a two column vectors a and b representing the basis of the transform, as well as the origin:

[ a.x  b.x  origin.x ]
[ a.y  b.y  origin.y ]

§All matrix types

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

§Godot docs

Transform2D (stable)

Fields§

§a: Vector2

The first basis vector.

Godot equivalent: Transform2D.x, see Basis for why it’s changed

§b: Vector2

The second basis vector.

Godot equivalent: Transform2D.y, see Basis for why it’s changed

§origin: Vector2

The origin of the transform. The coordinate space defined by this transform starts at this point.

Godot equivalent: Transform2D.origin

Implementations§

§

impl Transform2D

pub const IDENTITY: Transform2D = _

The identity transform, with no translation, rotation or scaling applied. When applied to other data structures, IDENTITY performs no transformation.

Godot equivalent: Transform2D.IDENTITY

pub const FLIP_X: Transform2D = _

The Transform2D that will flip something along its X axis.

Godot equivalent: Transform2D.FLIP_X

pub const FLIP_Y: Transform2D = _

The Transform2D that will flip something along its Y axis.

Godot equivalent: Transform2D.FLIP_Y

pub const fn from_cols(a: Vector2, b: Vector2, origin: Vector2) -> Transform2D

Create a new Transform2D with the given column vectors.

Godot equivalent: Transform2D(Vector2 x_axis, Vector2 y_axis, Vector2 origin), see Basis for why it’s changed

pub fn from_angle(angle: f32) -> Transform2D

Create a new Transform2D which will rotate by the given angle.

pub fn from_angle_origin(angle: f32, origin: Vector2) -> Transform2D

Create a new Transform2D which will rotate by angle and translate by origin.

Godot equivalent: Transform2D(float rotation, Vector2 position)

pub fn from_angle_scale_skew_origin( angle: f32, scale: Vector2, skew: f32, origin: Vector2, ) -> Transform2D

Create a new Transform2D which will rotate by angle, scale by scale, skew by skew and translate by origin.

Godot equivalent: Transform2D(float rotation, Vector2 scale, float skew, Vector2 position)

pub fn affine_inverse(&self) -> Transform2D

Returns the inverse of the transform, under the assumption that the transformation is composed of rotation, scaling and translation.

Godot equivalent: Transform2D.affine_inverse()

pub fn determinant(&self) -> f32

Returns the determinant of the basis matrix.

If the basis is uniformly scaled, then its determinant equals the square of the scale factor.

A negative determinant means the basis was flipped, so one part of the scale is negative. A zero determinant means the basis isn’t invertible, and is usually considered invalid.

Godot equivalent: Transform2D.determinant()

pub fn rotation(&self) -> f32

Returns the transform’s rotation (in radians).

Godot equivalent: Transform2D.get_rotation()

pub fn scale(&self) -> Vector2

Returns the transform’s scale.

Godot equivalent: Transform2D.get_scale()

pub fn skew(&self) -> f32

Returns the transform’s skew (in radians).

Godot equivalent: Transform2D.get_skew()

pub fn interpolate_with(&self, other: &Transform2D, weight: f32) -> Transform2D

Returns a transform interpolated between this transform and another by a given weight (on the range of 0.0 to 1.0).

Godot equivalent: Transform2D.interpolate_with()

pub fn is_finite(&self) -> bool

Returns true if this transform is finite, by calling Vector2::is_finite() on each component.

Godot equivalent: Transform2D.is_finite()

pub fn orthonormalized(&self) -> Transform2D

Returns the transform with the basis orthogonal (90 degrees), and normalized axis vectors (scale of 1 or -1).

Godot equivalent: Transform2D.orthonormalized()

pub fn rotated(&self, angle: f32) -> Transform2D

Returns a copy of the transform rotated by the given angle (in radians). This method is an optimized version of multiplying the given transform X with a corresponding rotation transform R from the left, i.e., R * X. This can be seen as transforming with respect to the global/parent frame.

Godot equivalent: Transform2D.rotated()

pub fn rotated_local(&self, angle: f32) -> Transform2D

Returns a copy of the transform rotated by the given angle (in radians). This method is an optimized version of multiplying the given transform X with a corresponding rotation transform R from the right, i.e., X * R. This can be seen as transforming with respect to the local frame.

Godot equivalent: Transform2D.rotated_local()

pub fn scaled(&self, scale: Vector2) -> Transform2D

Returns a copy of the transform scaled by the given scale factor. This method is an optimized version of multiplying the given transform X with a corresponding scaling transform S from the left, i.e., S * X. This can be seen as transforming with respect to the global/parent frame.

Godot equivalent: Transform2D.scaled()

pub fn scaled_local(&self, scale: Vector2) -> Transform2D

Returns a copy of the transform scaled by the given scale factor. This method is an optimized version of multiplying the given transform X with a corresponding scaling transform S from the right, i.e., X * S. This can be seen as transforming with respect to the local frame.

Godot equivalent: Transform2D.scaled_local()

pub fn translated(&self, offset: Vector2) -> Transform2D

Returns a copy of the transform translated by the given offset. This method is an optimized version of multiplying the given transform X with a corresponding translation transform T from the left, i.e., T * X. This can be seen as transforming with respect to the global/parent frame.

Godot equivalent: Transform2D.translated()

pub fn translated_local(&self, offset: Vector2) -> Transform2D

Returns a copy of the transform translated by the given offset. This method is an optimized version of multiplying the given transform X with a corresponding translation transform T from the right, i.e., X * T. This can be seen as transforming with respect to the local frame.

Godot equivalent: Transform2D.translated()

pub fn basis_xform(&self, v: Vector2) -> Vector2

Returns a vector transformed (multiplied) by the basis matrix. This method does not account for translation (the origin vector).

Godot equivalent: Transform2D.basis_xform()

pub fn basis_xform_inv(&self, v: Vector2) -> Vector2

Returns a vector transformed (multiplied) by the inverse basis matrix. This method does not account for translation (the origin vector).

Godot equivalent: Transform2D.basis_xform_inv()

Trait Implementations§

§

impl ApproxEq for Transform2D

§

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

Returns if the two transforms are approximately equal, by comparing each component separately.

§

impl ArrayElement for Transform2D

§

impl Clone for Transform2D

§

fn clone(&self) -> Transform2D

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 Transform2D

§

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

Formats the value using the given formatter. Read more
§

impl Default for Transform2D

§

fn default() -> Transform2D

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

impl Display for Transform2D

§

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

Formats the value with the given formatter. Read more

The output is similar to Godot’s, but calls the columns a/b instead of X/Y. See Basis for why.

§

impl Export for Transform2D

§

fn export_hint() -> PropertyHintInfo

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

fn as_node_class() -> Option<ClassName>

If this is a class inheriting Node, returns the ClassName; otherwise None. Read more
§

impl FromGodot for Transform2D

§

fn try_from_godot( via: <Transform2D as GodotConvert>::Via, ) -> Result<Transform2D, 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 Transform2D

§

type Via = Transform2D

The type through which Self is represented in Godot.
§

impl Mul<Rect2> for Transform2D

§

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

Transforms each coordinate in rhs.position and rhs.end() individually by this transform, then creates a Rect2 containing all of them.

§

type Output = Rect2

The resulting type after applying the * operator.
§

impl Mul<Vector2> for Transform2D

§

type Output = Vector2

The resulting type after applying the * operator.
§

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

Performs the * operation. Read more
§

impl Mul<f32> for Transform2D

§

type Output = Transform2D

The resulting type after applying the * operator.
§

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

Performs the * operation. Read more
§

impl Mul for Transform2D

§

type Output = Transform2D

The resulting type after applying the * operator.
§

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

Performs the * operation. Read more
§

impl PartialEq for Transform2D

§

fn eq(&self, other: &Transform2D) -> 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 Transform2D

§

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

Target type of to_godot(), which differs from Via for pass-by-reference types.
§

fn to_godot(&self) -> <Transform2D 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 Transform2D

§

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

§

fn set_property(&mut self, value: <Transform2D 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 Copy for Transform2D

§

impl GodotType for Transform2D

§

impl StructuralPartialEq for Transform2D

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 T)

🔬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.