Struct godot::prelude::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 ]

Fields§

§a: Vector2

The first basis vector.

This is equivalent to the x field from godot.

§b: Vector2

The second basis vector.

This is equivalent to the y field from godot.

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

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 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 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 using the given formatter. Read more
§

impl Export for Transform2D

§

fn default_export_info() -> PropertyHintInfo

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

impl FromGodot for Transform2D

§

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

Performs the conversion.
§

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

⚠️ Performs the conversion. Read more
§

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

Performs the conversion from a Variant.
§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl ToGodot for Transform2D

§

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

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

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

Converts this type to the Godot type. Read more
§

fn to_variant(&self) -> Variant

Converts this type to a Variant.
§

impl TypeStringHint for Transform2D

§

fn type_string() -> String

Returns the representation of this type as a type string. Read more
§

impl Var for Transform2D

§

impl ArrayElement for Transform2D

§

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> 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,

§

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>,

§

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>,

§

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.