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
| Dimension | Orthogonal basis | Affine transform | Projective transform |
|---|---|---|---|
| 2D | Transform2D (2x3) | ||
| 3D | Basis (3x3) | Transform3D (3x4) | Projection (4x4) |
§Transform operations
| Operation | Transform2D | Notes |
|---|---|---|
| Apply | transform * v | Supports Rect2 and Vector2. |
| Apply inverse | transform.xform_inv(v) | Supports Rect2 and Vector2. |
| Apply, no translate | transform.basis_xform(v) | Supports Vector2. |
| Apply inverse, no translate | transform.basis_xform_inv(v) | Supports Vector2. |
§Godot docs
Fields§
§a: Vector2The first basis vector.
Godot equivalent: Transform2D.x, see Basis for why it’s changed
b: Vector2The second basis vector.
Godot equivalent: Transform2D.y, see Basis for why it’s changed
origin: Vector2The origin of the transform. The coordinate space defined by this transform starts at this point.
Godot equivalent: Transform2D.origin
Implementations§
§impl Transform2D
impl Transform2D
pub const IDENTITY: 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
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
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
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
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
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
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
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
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
pub fn rotation(&self) -> f32
Returns the transform’s rotation (in radians).
Godot equivalent: Transform2D.get_rotation()
pub fn scale(&self) -> Vector2
pub fn scale(&self) -> Vector2
Returns the transform’s scale.
Godot equivalent: Transform2D.get_scale()
pub fn skew(&self) -> f32
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
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
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
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
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
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
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
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
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
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
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
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
impl ApproxEq for Transform2D
§fn approx_eq(&self, other: &Transform2D) -> bool
fn approx_eq(&self, other: &Transform2D) -> bool
Returns if the two transforms are approximately equal, by comparing each component separately.
§impl Clone for Transform2D
impl Clone for Transform2D
§fn clone(&self) -> Transform2D
fn clone(&self) -> Transform2D
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for Transform2D
impl Debug for Transform2D
§impl Default for Transform2D
impl Default for Transform2D
§fn default() -> Transform2D
fn default() -> Transform2D
§impl Display for Transform2D
impl Display for Transform2D
§impl DynamicSend for Transform2D
impl DynamicSend for Transform2D
type Inner = Transform2D
fn extract_if_safe(self) -> Option<<Transform2D as DynamicSend>::Inner>
§impl Export for Transform2D
impl Export for Transform2D
§fn export_hint() -> PropertyHintInfo
fn export_hint() -> PropertyHintInfo
§impl FromGodot for Transform2D
impl FromGodot for Transform2D
§fn try_from_godot(
via: <Transform2D as GodotConvert>::Via,
) -> Result<Transform2D, ConvertError>
fn try_from_godot( via: <Transform2D as GodotConvert>::Via, ) -> Result<Transform2D, 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 Transform2D
impl GodotConvert for Transform2D
§type Via = Transform2D
type Via = Transform2D
Self is represented in Godot.§impl GodotImmutable for Transform2D
impl GodotImmutable for Transform2D
fn into_runtime_immutable(self) -> Self
§impl IntoDynamicSend for Transform2D
impl IntoDynamicSend for Transform2D
type Target = Transform2D
fn into_dynamic_send(self) -> <Transform2D as IntoDynamicSend>::Target
§impl Mul<Rect2> for Transform2D
impl Mul<Rect2> for Transform2D
§impl Mul<Vector2> for Transform2D
impl Mul<Vector2> for Transform2D
§impl Mul<f32> for Transform2D
impl Mul<f32> for Transform2D
§impl Mul for Transform2D
impl Mul for Transform2D
§type Output = Transform2D
type Output = Transform2D
* operator.§fn mul(self, rhs: Transform2D) -> <Transform2D as Mul>::Output
fn mul(self, rhs: Transform2D) -> <Transform2D as Mul>::Output
* operation. Read more§impl PartialEq for Transform2D
impl PartialEq for Transform2D
§impl ToGodot for Transform2D
impl ToGodot for Transform2D
§fn to_godot(&self) -> <Transform2D as GodotConvert>::Via
fn to_godot(&self) -> <Transform2D as GodotConvert>::Via
§fn to_godot_owned(&self) -> Self::Via
fn to_godot_owned(&self) -> Self::Via
§fn to_variant(&self) -> Variant
fn to_variant(&self) -> Variant
§impl Var for Transform2D
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
fn var_hint() -> PropertyHintInfo
GodotType::property_info, e.g. for enums/newtypes.§impl XformInv<Rect2> for Transform2D
impl XformInv<Rect2> for Transform2D
§fn xform_inv(&self, rhs: Rect2) -> Rect2
fn xform_inv(&self, rhs: Rect2) -> Rect2
Inversely transforms (multiplies) the given Rect2 by this Transform2D transformation matrix, under the assumption that the transformation basis is orthonormal (i.e. rotation/reflection is fine, scaling/skew is not).
For transforming by inverse of an affine transformation (e.g. with scaling) transform.affine_inverse() * vector can be used instead. See: Transform2D::affine_inverse().
Godot equivalent: rect2 * transform or transform.inverse() * rect2
§impl XformInv<Vector2> for Transform2D
impl XformInv<Vector2> for Transform2D
§fn xform_inv(&self, rhs: Vector2) -> Vector2
fn xform_inv(&self, rhs: Vector2) -> Vector2
Inversely transforms (multiplies) the given Vector2 by this transformation matrix,
under the assumption that the transformation basis is orthonormal (i.e. rotation/reflection is fine, scaling/skew is not).
For transforming by inverse of an affine transformation (e.g. with scaling) transform.affine_inverse() * vector can be used instead. See: Transform2D::affine_inverse().
Godot equivalent: vector * transform or transform.inverse() * vector
impl ArrayElement for Transform2D
impl BuiltinExport for Transform2D
impl Copy for Transform2D
impl GodotType for Transform2D
impl StructuralPartialEq for Transform2D
Auto Trait Implementations§
impl Freeze for Transform2D
impl RefUnwindSafe for Transform2D
impl Send for Transform2D
impl Sync for Transform2D
impl Unpin for Transform2D
impl UnwindSafe for Transform2D
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)