Struct gdnative::prelude::Transform

source ·
pub struct Transform {
    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; 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

source

pub const IDENTITY: Transform = Self{ basis: Basis::IDENTITY, origin: Vector3::ZERO,}

Identity transform; leaves objects unchanged when applied.

source

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

source

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

source

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

source

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 ]
source

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

Returns this transform, with its origin moved by a certain translation

source

pub fn translated_local(&self, translation: Vector3) -> Transform

Returns this transform, with its origin moved by a certain translation

source

pub fn xform(&self, v: Vector3) -> Vector3

Returns a vector transformed (multiplied) by the matrix.

source

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.

source

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

source

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.

source

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.

source

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.

source

pub fn scaled(&self, scale: Vector3) -> Transform

Scales basis and origin of the transform by the given scale factor, using matrix multiplication.

source

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

source

pub fn orthonormalized(&self) -> Transform

Returns the transform with the basis orthogonal (90 degrees), and normalized axis vectors.

source

pub fn orthogonalized(&self) -> Transform

Returns the transform with the basis orthogonal (90 degrees), but without normalizing the axis vectors.

source

pub fn is_equal_approx(&self, other: &Transform) -> bool

source

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

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.

source

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 Clone for Transform

source§

fn clone(&self) -> Transform

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl CoerceFromVariant for Transform

source§

impl Debug for Transform

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for Transform

source§

fn default() -> Transform

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

impl<'de> Deserialize<'de> for Transform

source§

fn deserialize<__D>(
    __deserializer: __D
) -> Result<Transform, <__D as Deserializer<'de>>::Error>where
    __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Export for Transform

§

type Hint = NoHint

A type-specific hint type that is valid for the type being exported. Read more
source§

fn export_info(_hint: Option<<Transform as Export>::Hint>) -> ExportInfo

Returns ExportInfo given an optional typed hint.
source§

impl FromVariant for Transform

source§

impl Mul<Transform> for Transform

§

type Output = Transform

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl MulAssign<Transform> for Transform

source§

fn mul_assign(&mut self, rhs: Transform)

Performs the *= operation. Read more
source§

impl PartialEq<Transform> for Transform

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

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

impl Serialize for Transform

source§

fn serialize<__S>(
    &self,
    __serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
    __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl ToVariant for Transform

source§

impl Copy for Transform

source§

impl StructuralPartialEq for Transform

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere
    T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
    U: From<T>,

const: unstable · 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> OwnedToVariant for Twhere
    T: ToVariant,

source§

impl<T> ToOwned for Twhere
    T: Clone,

§

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, U> TryFrom<U> for Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
    U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere
    T: for<'de> Deserialize<'de>,