Struct gdnative::core_types::Transform2D
source · [−]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
sourceimpl Transform2D
impl Transform2D
sourcepub const IDENTITY: Transform2D = Self{
a: Vector2::new(1.0, 0.0),
b: Vector2::new(0.0, 1.0),
origin: Vector2::new(0.0, 0.0),}
pub const IDENTITY: Transform2D = Self{ a: Vector2::new(1.0, 0.0), b: Vector2::new(0.0, 1.0), origin: Vector2::new(0.0, 0.0),}
Represents the identity transform.
sourcepub const fn from_basis_origin(
basis_vector_a: Vector2,
basis_vector_b: Vector2,
origin: Vector2
) -> Transform2D
pub const fn from_basis_origin(
basis_vector_a: Vector2,
basis_vector_b: Vector2,
origin: Vector2
) -> Transform2D
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 ]
sourcepub fn from_scale_rotation_origin(
scale: Vector2,
rotation: f32,
origin: Vector2
) -> Transform2D
pub fn from_scale_rotation_origin(
scale: Vector2,
rotation: f32,
origin: Vector2
) -> Transform2D
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
.
sourcepub 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.
sourcepub 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).
sourcepub 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).
sourcepub fn xform(&self, v: Vector2) -> Vector2
pub fn xform(&self, v: Vector2) -> Vector2
Transforms the given Vector2, Rect2, or PoolVector2Array by this transform.
sourcepub fn xform_inv(&self, v: Vector2) -> Vector2
pub fn xform_inv(&self, v: Vector2) -> Vector2
Inverse-transforms the given Vector2, Rect2, or PoolVector2Array by this transform.
sourcepub fn translated(&self, translation: Vector2) -> Transform2D
pub fn translated(&self, translation: Vector2) -> Transform2D
Translates the transform by the given offset, relative to the transform’s basis vectors.
Unlike rotated() and scaled(), this does not use matrix multiplication.
sourcepub fn set_rotation(&mut self, rotation: f32)
pub fn set_rotation(&mut self, rotation: f32)
Sets the transform’s rotation (argument rotation
in radians).
sourcepub fn rotated(&self, rotation: f32) -> Transform2D
pub fn rotated(&self, rotation: f32) -> Transform2D
Rotates the transform by the given angle (in radians), using matrix multiplication. This will modify the transform’s origin.
sourcepub fn scaled(&self, scale: Vector2) -> Transform2D
pub fn scaled(&self, scale: Vector2) -> Transform2D
Scales the transform by the given scale factor, using matrix multiplication. This will modify the transform’s origin.
sourcepub 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). NOTE: This method assumes both Transform2Ds are affine transformations.
sourcepub fn is_equal_approx(&self, other: Transform2D) -> bool
pub fn is_equal_approx(&self, other: Transform2D) -> bool
Returns true if this transform and transform are approximately equal, by calling is_equal_approx on each component.
Trait Implementations
sourceimpl Clone for Transform2D
impl Clone for Transform2D
sourcefn clone(&self) -> Transform2D
fn clone(&self) -> Transform2D
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl CoerceFromVariant for Transform2D
impl CoerceFromVariant for Transform2D
fn coerce_from_variant(v: &Variant) -> Transform2D
sourceimpl Debug for Transform2D
impl Debug for Transform2D
sourceimpl<'de> Deserialize<'de> for Transform2D
impl<'de> Deserialize<'de> for Transform2D
sourcefn deserialize<__D>(
__deserializer: __D
) -> Result<Transform2D, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<Transform2D, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
sourceimpl Export for Transform2D
impl Export for Transform2D
sourcefn export_info(_hint: Option<<Transform2D as Export>::Hint>) -> ExportInfo
fn export_info(_hint: Option<<Transform2D as Export>::Hint>) -> ExportInfo
ExportInfo
given an optional typed hint.sourceimpl FromVariant for Transform2D
impl FromVariant for Transform2D
fn from_variant(variant: &Variant) -> Result<Transform2D, FromVariantError>
sourceimpl Mul<Transform2D> for Transform2D
impl Mul<Transform2D> for Transform2D
type Output = Transform2D
type Output = Transform2D
*
operator.sourcefn mul(self, rhs: Transform2D) -> <Transform2D as Mul<Transform2D>>::Output
fn mul(self, rhs: Transform2D) -> <Transform2D as Mul<Transform2D>>::Output
*
operation. Read more