Skip to main content

Transform3D

Struct Transform3D 

#[repr(C)]
pub struct Transform3D { pub basis: Basis, pub origin: Vector3, }
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:

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

§All matrix types

DimensionOrthogonal basisAffine transformProjective transform
2DTransform2D (2x3)
3DBasis (3x3)Transform3D (3x4)Projection (4x4)

§Transform operations

OperationTransform3DNotes
Applytransform * vSupports Aabb, Plane, Vector3.
Apply inversetransform.xform_inv(v)Supports Aabb, Plane, Vector3.
Apply, no translatetransform.basis * vSupports Vector3.
Apply inverse, no translatetransform.basis.xform_inv(v)Supports Vector3.

§Godot docs

Transform3D (stable)

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§

§

impl Transform3D

pub const IDENTITY: Transform3D

The identity transform, with no translation, rotation or scaling applied. When applied to other data structures, IDENTITY performs no transformation.

Godot equivalent: Transform3D.IDENTITY

pub const FLIP_X: Transform3D

Transform3D with mirroring applied perpendicular to the YZ plane.

Godot equivalent: Transform3D.FLIP_X

pub const FLIP_Y: Transform3D

Transform3D with mirroring applied perpendicular to the XZ plane.

Godot equivalent: Transform3D.FLIP_Y

pub const FLIP_Z: Transform3D

Transform3D with mirroring applied perpendicular to the XY plane.

Godot equivalent: Transform3D.FLIP_Z

pub const fn new(basis: Basis, origin: Vector3) -> Transform3D

Create a new transform from a Basis and a Vector3.

Godot equivalent: Transform3D(Basis basis, Vector3 origin)

pub const fn from_cols( a: Vector3, b: Vector3, c: Vector3, origin: Vector3, ) -> Transform3D

Create a new transform from 4 matrix-columns.

Godot equivalent: Transform3D(Vector3 x_axis, Vector3 y_axis, Vector3 z_axis, Vector3 origin), see Basis for why it’s changed

pub fn from_projection(proj: &Projection) -> Transform3D

Constructs a Transform3D from a Projection by trimming the last row of the projection matrix.

Godot equivalent: Transform3D(Projection from)

pub fn affine_inverse(&self) -> Transform3D

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

pub fn interpolate_with(&self, other: &Transform3D, weight: f32) -> Transform3D

Returns a transform interpolated between this transform and another by a given weight (on the range of 0.0 to 1.0).

pub fn is_finite(&self) -> bool

Returns true if this transform is finite by calling is_finite on the basis and origin.

pub fn orthonormalized(&self) -> Transform3D

Returns the transform with the basis orthogonal (90 degrees), and normalized axis vectors (scale of 1 or -1).

Godot equivalent: Transform3D.orthonormalized()

pub fn rotated(&self, axis: Vector3, angle: f32) -> Transform3D

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, axis: Vector3, angle: f32) -> Transform3D

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: Vector3) -> Transform3D

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: Vector3) -> Transform3D

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: Vector3) -> Transform3D

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: Vector3) -> Transform3D

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

§

impl Transform3D

pub fn looking_at(&self, target: Vector3) -> Transform3D

To set the default parameters, use looking_at_ex and its builder methods. See the book for detailed usage instructions. Returns a copy of this transform rotated so that the forward axis (-Z) points towards the target position.

The up axis (+Y) points as close to the up vector as possible while staying perpendicular to the forward axis. The resulting transform is orthonormalized. The existing rotation, scale, and skew information from the original transform is discarded. The target and up vectors cannot be zero, cannot be parallel to each other, and are defined in global/parent space.

If use_model_front is true, the +Z axis (asset front) is treated as forward (implies +X is left) and points toward the target position. By default, the -Z axis (camera forward) is treated as forward (implies +X is right).

pub fn looking_at_ex<'ex>(&'ex self, target: Vector3) -> ExLookingAt<'ex>

Returns a copy of this transform rotated so that the forward axis (-Z) points towards the target position.

The up axis (+Y) points as close to the up vector as possible while staying perpendicular to the forward axis. The resulting transform is orthonormalized. The existing rotation, scale, and skew information from the original transform is discarded. The target and up vectors cannot be zero, cannot be parallel to each other, and are defined in global/parent space.

If use_model_front is true, the +Z axis (asset front) is treated as forward (implies +X is left) and points toward the target position. By default, the -Z axis (camera forward) is treated as forward (implies +X is right).

Trait Implementations§

§

impl ApproxEq for Transform3D

§

fn approx_eq(&self, other: &Transform3D) -> bool

Returns if the two transforms are approximately equal, by comparing basis and origin separately.

§

impl Clone for Transform3D

§

fn clone(&self) -> Transform3D

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for Transform3D

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for Transform3D

§

fn default() -> Transform3D

Returns the “default value” for a type. Read more
§

impl Display for Transform3D

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value with the given formatter. Read more

The output is similar to Godot’s, but calls the columns a/b/c instead of X/Y/Z. See Basis for why.

§

impl DynamicSend for Transform3D

§

impl From<Basis> for Transform3D

§

fn from(basis: Basis) -> Transform3D

Create a new transform with origin (0,0,0) from this basis.

§

impl From<Transform3D> for Projection

§

fn from(trans: Transform3D) -> Projection

Converts to this type from the input type.
§

impl FromGodot for Transform3D

§

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

Converts the Godot representation to this type, returning Err on failure.
§

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

⚠️ Converts the Godot representation to this type. Read more
§

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

Performs the conversion from a Variant, returning Err on failure.
§

fn from_variant(variant: &Variant) -> Self

⚠️ Performs the conversion from a Variant. Read more
§

impl GodotConvert for Transform3D

§

type Via = Transform3D

The type through which Self is represented in Godot.
§

fn godot_shape() -> GodotShape

Which “shape” this type has for property registration (e.g. builtin, enum, …). Read more
§

impl GodotImmutable for Transform3D

§

fn into_runtime_immutable(self) -> Self

§

impl IntoDynamicSend for Transform3D

§

impl Mul<Aabb> for Transform3D

§

fn mul(self, rhs: Aabb) -> <Transform3D as Mul<Aabb>>::Output

Transforms each coordinate in rhs.position and rhs.end() individually by this transform, then creates an Aabb containing all of them.

§

type Output = Aabb

The resulting type after applying the * operator.
§

impl Mul<Plane> for Transform3D

§

type Output = Plane

The resulting type after applying the * operator.
§

fn mul(self, rhs: Plane) -> <Transform3D as Mul<Plane>>::Output

Performs the * operation. Read more
§

impl Mul<Vector3> for Transform3D

§

type Output = Vector3

The resulting type after applying the * operator.
§

fn mul(self, rhs: Vector3) -> <Transform3D as Mul<Vector3>>::Output

Performs the * operation. Read more
§

impl Mul<f32> for Transform3D

§

type Output = Transform3D

The resulting type after applying the * operator.
§

fn mul(self, rhs: f32) -> <Transform3D as Mul<f32>>::Output

Performs the * operation. Read more
§

impl Mul for Transform3D

§

type Output = Transform3D

The resulting type after applying the * operator.
§

fn mul(self, rhs: Transform3D) -> <Transform3D as Mul>::Output

Performs the * operation. Read more
§

impl PartialEq for Transform3D

§

fn eq(&self, other: &Transform3D) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

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

impl ToGodot for Transform3D

§

type Pass = ByValue

Whether arguments of this type are passed by value or by reference. Read more
§

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

Converts this type to Godot representation, optimizing for zero-copy when possible. Read more
§

fn to_godot_owned(&self) -> Self::Via

Converts this type to owned Godot representation. Read more
§

fn to_variant(&self) -> Variant

Converts this type to a Variant.
§

impl XformInv<Aabb> for Transform3D

§

fn xform_inv(&self, rhs: Aabb) -> Aabb

Inversely transforms each vertex in given Aabb individually by this transformation matrix, under the assumption that the transformation basis is orthonormal (i.e. rotation/reflection is fine, scaling/skew is not), and then creates an Aabb encompassing all of them.

For transforming by inverse of an affine transformation (e.g. with scaling) transform.affine_inverse() * aabb can be used instead. See Transform3D::affine_inverse().

Godot equivalent: aabb * transform

§

impl XformInv<Plane> for Transform3D

§

fn xform_inv(&self, rhs: Plane) -> Plane

Inversely transforms (multiplies) the Plane by the given Transform3D transformation matrix.

transform.xform_inv(plane) is equivalent to transform.affine_inverse() * plane. See Transform3D::affine_inverse().

Godot equivalent: plane * transform

§

impl XformInv<Vector3> for Transform3D

§

fn xform_inv(&self, rhs: Vector3) -> Vector3

Inversely transforms given Vector3 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 Transform3D::affine_inverse().

Godot equivalent: aabb * transform

§

impl BuiltinExport for Transform3D

§

impl Copy for Transform3D

§

impl Element for Transform3D

§

impl Export for Transform3D

§

impl GodotType for Transform3D

§

impl SimpleVar for Transform3D

§

impl StructuralPartialEq for Transform3D

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
§

impl<T> AsArg<T> for T
where T: ToGodot<Pass = ByValue>,

§

fn into_arg<'arg>(self) -> CowArg<'arg, T>
where T: 'arg,

§

impl<T> AsArg<Variant> for T
where T: ToGodot<Pass = ByValue>,

§

fn into_arg<'arg>(self) -> CowArg<'arg, Variant>
where T: 'arg,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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§

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

Source§

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

Source§

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

impl<T> Var for T
where T: SimpleVar,

§

type PubType = T

Type used in generated Rust getters/setters for #[var(pub)].
§

fn var_get(field: &T) -> <T as GodotConvert>::Via

Get property value via FFI-level Via type. Called for internal (non-pub) getters registered with Godot.
§

fn var_set(field: &mut T, value: <T as GodotConvert>::Via)

Set property value via FFI-level Via type. Called for internal (non-pub) setters registered with Godot.
§

fn var_pub_get(field: &T) -> <T as Var>::PubType

Get property value as PubType. Called for #[var(pub)] getters exposed in Rust API.
§

fn var_pub_set(field: &mut T, value: <T as Var>::PubType)

Set property value as PubType. Called for #[var(pub)] setters exposed in Rust API.
§

impl<T> AsDirectElement<T> for T
where T: Element<Pass = ByValue> + ToGodot,