Expand description
Affine 3D transform (3x4 matrix).
Used for 3D linear transformations. Uses a basis + origin representation.
Expressed as a 3x4 matrix, this transform consists of 3 basis (column) vectors a
, b
, c
as well as an origin o
; more information in Self::from_basis_origin()
:
[ a.x b.x c.x o.x ]
[ a.y b.y c.y o.y ]
[ a.z b.z c.z o.z ]
See also Transform in the Godot API doc.
Fields§
§basis: Basis
The basis is a matrix containing 3 vectors as its columns. They can be interpreted as the basis vectors of the transformed coordinate system.
origin: Vector3
The new origin of the transformed coordinate system.
Implementations§
source§impl Transform
impl Transform
sourcepub const IDENTITY: Transform = Self{ basis: Basis::IDENTITY, origin: Vector3::ZERO,}
pub const IDENTITY: Transform = Self{ basis: Basis::IDENTITY, origin: Vector3::ZERO,}
Identity transform; leaves objects unchanged when applied.
sourcepub const FLIP_X: Transform = Self{ basis: Basis::FLIP_X, origin: Vector3::ZERO,}
pub const FLIP_X: Transform = Self{ basis: Basis::FLIP_X, origin: Vector3::ZERO,}
Transform that mirrors along the X axis (perpendicular to the YZ plane).
sourcepub const FLIP_Y: Transform = Self{ basis: Basis::FLIP_Y, origin: Vector3::ZERO,}
pub const FLIP_Y: Transform = Self{ basis: Basis::FLIP_Y, origin: Vector3::ZERO,}
Transform that mirrors along the Y axis (perpendicular to the XZ plane).
sourcepub const FLIP_Z: Transform = Self{ basis: Basis::FLIP_Z, origin: Vector3::ZERO,}
pub const FLIP_Z: Transform = Self{ basis: Basis::FLIP_Z, origin: Vector3::ZERO,}
Transform that mirrors along the Z axis (perpendicular to the XY plane).
sourcepub const fn from_basis_origin(
basis_vector_a: Vector3,
basis_vector_b: Vector3,
basis_vector_c: Vector3,
origin: Vector3
) -> Transform
pub const fn from_basis_origin(
basis_vector_a: Vector3,
basis_vector_b: Vector3,
basis_vector_c: Vector3,
origin: Vector3
) -> 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, 0)
.
The 3 vectors need to be linearly independent.
Basis vectors are stored as column vectors in the matrix, see also Basis::from_basis_vectors()
.
The construction Transform::from_basis_origin(a, b, c, o)
will create the following 3x4 matrix:
[ a.x b.x c.x o.x ]
[ a.y b.y c.y o.y ]
[ a.z b.z c.z o.z ]
sourcepub fn translated(&self, translation: Vector3) -> Transform
👎Deprecated: translated
is not relative to the transform’s coordinate system and thus inconsistent with GDScript. Please use translated_global() instead. This method will be renamed to translated_local in gdnative 0.12.
pub fn translated(&self, translation: Vector3) -> Transform
translated
is not relative to the transform’s coordinate system and thus inconsistent with GDScript. Please use translated_global() instead. This method will be renamed to translated_local in gdnative 0.12.Returns this transform, with its origin moved by a certain translation
sourcepub fn translated_local(&self, translation: Vector3) -> Transform
pub fn translated_local(&self, translation: Vector3) -> Transform
Returns this transform, with its origin moved by a certain translation
sourcepub fn xform(&self, v: Vector3) -> Vector3
pub fn xform(&self, v: Vector3) -> Vector3
Returns a vector transformed (multiplied) by the matrix.
sourcepub fn xform_inv(&self, v: Vector3) -> Vector3
pub fn xform_inv(&self, v: Vector3) -> Vector3
Returns a vector transformed (multiplied) by the transposed basis matrix.
Note: This results in a multiplication by the inverse of the matrix only if it represents a rotation-reflection.
sourcepub fn inverse(&self) -> Transform
pub fn inverse(&self) -> Transform
Returns the inverse of the transform, under the assumption that the transformation is composed of rotation and translation (no scaling, use affine_inverse for transforms with scaling).
sourcepub fn affine_inverse(&self) -> Transform
pub fn affine_inverse(&self) -> Transform
Returns the inverse of the transform, under the assumption that the transformation is composed of rotation, scaling and translation.
sourcepub fn rotated(&self, axis: Vector3, phi: f32) -> Transform
pub fn rotated(&self, axis: Vector3, phi: f32) -> Transform
In-place rotation of the transform around the given axis by the given angle (in radians), using matrix multiplication. The axis must be a normalized vector. Due to nature of the operation, a new transform is created first.
sourcepub fn looking_at(&self, target: Vector3, up: Vector3) -> Transform
pub fn looking_at(&self, target: Vector3, up: Vector3) -> Transform
Returns a copy of the transform rotated such that its -Z axis points towards the target position.
The transform will first be rotated around the given up vector, and then fully aligned to the target by a further rotation around an axis perpendicular to both the target and up vectors.
sourcepub fn scaled(&self, scale: Vector3) -> Transform
pub fn scaled(&self, scale: Vector3) -> Transform
Scales basis and origin of the transform by the given scale factor, using matrix multiplication.
sourcepub fn translated_global(&self, translation: Vector3) -> Transform
pub fn translated_global(&self, translation: Vector3) -> Transform
Translates the transform by the given offset, relative to the transform’s basis vectors.
This method will be renamed to translated
in gdnative 0.11
sourcepub fn orthonormalized(&self) -> Transform
pub fn orthonormalized(&self) -> Transform
Returns the transform with the basis orthogonal (90 degrees), and normalized axis vectors.
sourcepub fn orthogonalized(&self) -> Transform
pub fn orthogonalized(&self) -> Transform
Returns the transform with the basis orthogonal (90 degrees), but without normalizing the axis vectors.
pub fn is_equal_approx(&self, other: &Transform) -> bool
sourcepub fn sphere_interpolate_with(&self, other: &Transform, weight: f32) -> Transform
👎Deprecated: This is the Godot 4 rename of interpolate_with
. It will be removed in favor of the original Godot 3 naming in a future version.
pub fn sphere_interpolate_with(&self, other: &Transform, weight: f32) -> Transform
interpolate_with
. It will be removed in favor of the original Godot 3 naming in a future version.Interpolates the transform to other Transform by weight amount (on the range of 0.0 to 1.0). Assuming the two transforms are located on a sphere surface.
sourcepub fn interpolate_with(&self, other: &Transform, weight: f32) -> Transform
pub fn interpolate_with(&self, other: &Transform, weight: f32) -> Transform
Interpolates the transform to other Transform by weight amount (on the range of 0.0 to 1.0). Assuming the two transforms are located on a sphere surface.
Trait Implementations§
source§impl CoerceFromVariant for Transform
impl CoerceFromVariant for Transform
fn coerce_from_variant(v: &Variant) -> Transform
source§impl<'de> Deserialize<'de> for Transform
impl<'de> Deserialize<'de> for Transform
source§fn deserialize<__D>(
__deserializer: __D
) -> Result<Transform, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<Transform, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
source§impl FromVariant for Transform
impl FromVariant for Transform
fn from_variant(variant: &Variant) -> Result<Transform, FromVariantError>
source§impl MulAssign<Transform> for Transform
impl MulAssign<Transform> for Transform
source§fn mul_assign(&mut self, rhs: Transform)
fn mul_assign(&mut self, rhs: Transform)
*=
operation. Read more