#[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 2 basis (column) vectors a and b, as well as an origin o; more information in Self::from_basis_origin():

[ a.x  b.x  o.x ]
[ a.y  b.y  o.y ]

Given linear independence, every point in the transformed coordinate system can be expressed as p = xa + yb + o, where x, y are the scaling factors and o is the origin.

See also Transform2D in the Godot API doc.

Fields

a: Vector2

The first basis vector of the transform.

When transforming the X unit vector (1, 0) under this transform, the resulting point is represented by a. Objects will move along a when moving on the X axis in the coordinate space of this transform.

(This field is called x in Godot, but was renamed to avoid confusion with the x vector component and less readable expressions such as x.y, y.x).

b: Vector2

The second basis vector of the transform.

When transforming the Y unit vector (0, 1) under this transform, the resulting point is represented by b. Objects will move along b when moving on the Y axis in the coordinate space of this transform.

(This field is called y in Godot, but was renamed to avoid confusion with the y vector component and less readable expressions such as x.y, y.x).

origin: Vector2

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

Implementations

Represents the identity transform.

Creates a new transform from three basis vectors and the coordinate system’s origin.

Each vector represents a basis vector in the transformed coordinate system. For example, a is the result of transforming the X unit vector (1, 0). The 2 vectors need to be linearly independent.

Basis vectors are stored as column vectors in the matrix. The construction Transform2D::from_basis_origin(a, b, o) will create the following 3x4 matrix:

[ a.x  b.x  o.x ]
[ a.y  b.y  o.y ]

Constructs the transform from a given scale, angle (in radians), and origin.

This is NOT equivalent to either of these two lines:

Transform2D::IDENTITY.scaled(scale).rotated(rotation).translated(origin)
Transform2D::IDENTITY.translated(origin).rotated(rotation).scaled(scale)

Those transformations do not preserve the given origin; see documentation for rotated, scaled, and translated.

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

Returns a vector transformed (multiplied) by the basis matrix.

This method does not account for translation (the origin vector).

Returns a vector transformed (multiplied) by the inverse basis matrix.

This method does not account for translation (the origin vector).

Transforms the given Vector2, Rect2, or PoolVector2Array by this transform.

Inverse-transforms the given Vector2, Rect2, or PoolVector2Array by this transform.

Translates the transform by the given offset, relative to the transform’s basis vectors.

Unlike rotated() and scaled(), this does not use matrix multiplication.

Returns the transform’s rotation (in radians).

Sets the transform’s rotation (argument rotation in radians).

Rotates the transform by the given angle (in radians), using matrix multiplication. This will modify the transform’s origin.

Returns the transform’s scale.

Sets the transform’s scale.

Scales the transform by the given scale factor, using matrix multiplication. This will modify the transform’s origin.

Returns a transform interpolated between this transform and another by a given weight (on the range of 0.0 to 1.0). NOTE: This method assumes both Transform2Ds are affine transformations.

Returns true if this transform and transform are approximately equal, by calling is_equal_approx on each component.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
A type-specific hint type that is valid for the type being exported. Read more
Returns ExportInfo given an optional typed hint.
The resulting type after applying the * operator.
Performs the * operation. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.