Struct glamour::Transform3

source ·
#[repr(transparent)]
pub struct Transform3<Src: Unit, Dst: Unit> { pub matrix: Matrix4<Src::Scalar>, /* private fields */ }
Expand description

3D transform represented as a 4x4 column-major matrix.

This is a strongly typed wrapper around a Matrix4, where that matrix describes how to map between units.

Fields§

§matrix: Matrix4<Src::Scalar>

Underlying matrix.

Implementations§

source§

impl<Src, Dst> Transform3<Src, Dst>
where Src: Unit, Src::Scalar: FloatScalar, Dst: Unit<Scalar = Src::Scalar>,

source

pub const IDENTITY: Self = _

Identity matrix.

source

pub const fn from_matrix_unchecked(matrix: Matrix4<Src::Scalar>) -> Self

Create from matrix.

source

pub fn from_matrix(matrix: Matrix4<Src::Scalar>) -> Option<Self>

Create from matrix, checking if the matrix is invertible.

source

pub fn then<Dst2: Unit<Scalar = Dst::Scalar>>( self, other: Transform3<Dst, Dst2> ) -> Transform3<Src, Dst2>

Perform matrix multiplication such that other’s transformation applies after self.

This may change the target coordinate space - that is, the resulting transform takes points and vectors from Src to Dst2.

This operation is equivalent to other.matrix * self.matrix - that is, the multiplication order is the reverse of the order of the effects of the transformation.

source

pub fn then_rotate(self, axis: Vector3<Dst>, angle: Angle<Src::Scalar>) -> Self

Shorthand for .then(Transform3::from_angle(angle)).

This does not change the target coordinate space.

source

pub fn then_scale(self, scale: Vector3<Dst>) -> Self

Shorthand for .then(Transform3::from_scale(scale)).

This does not change the target coordinate space.

§Example
let a = Transform3::<f32, f32>::IDENTITY
    .then_scale((2.0, 3.0, 4.0).into());
let b = Transform3::<f32, f32>::from_scale((2.0, 3.0, 4.0).into());
assert_eq!(a, b);
source

pub fn then_translate(self, translation: Vector3<Dst>) -> Self

Shorthand for .then(Transform3::from_scale(scale)).

This does not change the target coordinate space.

source

pub fn from_axis_angle(axis: Vector3<Src>, angle: Angle<Src::Scalar>) -> Self

Create rotation transform.

§Example
struct A;
impl Unit for A { type Scalar = f64; }
struct B;
impl Unit for B { type Scalar = f64; }

type Transform = Transform3<A, B>;

let translate = Transform::from_axis_angle(Vector3::Z, Angle::FRAG_PI_2);
let a: Vector3<A> = Vector3 { x: 10.0, y: 20.0, z: 30.0 };
let b: Vector3<B> = translate.map(a);
assert_abs_diff_eq!(b, vec3!(-20.0, 10.0, 30.0), epsilon = 0.000001);
source

pub fn from_scale(scale: Vector3<Src>) -> Self

Create scaling transform.

§Example
struct A;
impl Unit for A { type Scalar = f32; }
struct B;
impl Unit for B { type Scalar = f32; }

type Transform = Transform3<A, B>;

let scale = Transform::from_scale(Vector3 { x: 2.0, y: 3.0, z: 1.0 });
let a: Vector3<A> = Vector3 { x: 10.0, y: 20.0, z: 30.0 };
let b: Vector3<B> = scale.map(a);
assert_abs_diff_eq!(b, vec3!(20.0, 60.0, 30.0));
source

pub fn from_translation(translation: Vector3<Src>) -> Self

Create translation transform.

§Example
struct A;
impl Unit for A { type Scalar = f32; }
struct B;
impl Unit for B { type Scalar = f32; }

type Transform = Transform3<A, B>;

let translate = Transform::from_translation(Vector3 { x: 10.0, y: 20.0, z: 30.0 });
let a: Point3<A> = Point3 { x: 1.0, y: 2.0, z: 30.0 };
let b: Point3<B> = translate.map(a);
assert_abs_diff_eq!(b, point!(11.0, 22.0, 60.0));
source

pub fn from_scale_rotation_translation( scale: Vector3<Src>, axis: Vector3<Src>, angle: Angle<Src::Scalar>, translation: Vector3<Src> ) -> Self

Create scaling, rotation, and translation matrix.

Note: This internally converts axis and angle to a quaternion and calls glam::Mat4::from_scale_rotation_translation().

§Example

type Transform = Transform3<f32, f32>;

let a = Transform::from_scale_rotation_translation(
    (2.0, 3.0, 1.0).into(),
    (0.0, 0.0, 1.0).into(),
    Angle::from_degrees(90.0),
    (10.0, 20.0, 30.0).into(),
);

// While this is equivalent, it introduces a significant amount of
// floating point imprecision.
let b = Transform::from_scale((2.0, 3.0, 1.0).into())
    .then_rotate((0.0, 0.0, 1.0).into(), Angle::from_degrees(90.0))
    .then_translate((10.0, 20.0, 30.0).into());

assert_abs_diff_eq!(a, b, epsilon = 0.001);
source

pub fn map_vector(&self, vector: Vector3<Src>) -> Vector3<Dst>

source

pub fn map_point(&self, point: Point3<Src>) -> Point3<Dst>

Map point from Src to Dst, including perspective correction.

See glam::Mat4::project_point3() and glam::DMat4::project_point3().

source

pub fn inverse(&self) -> Transform3<Dst, Src>

Invert the matrix.

See glam::Mat4::inverse() and glam::DMat4::inverse().

Trait Implementations§

source§

impl<Src, Dst> AbsDiffEq for Transform3<Src, Dst>
where Src: Unit, Src::Scalar: FloatScalar, Dst: Unit,

§

type Epsilon = <Matrix4<<Src as Unit>::Scalar> as AbsDiffEq>::Epsilon

Used for specifying relative comparisons.
source§

fn default_epsilon() -> Self::Epsilon

The default tolerance to use when testing values that are close together. Read more
source§

fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool

A test for equality that uses the absolute difference to compute the approximate equality of two numbers.
source§

fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool

The inverse of AbsDiffEq::abs_diff_eq.
source§

impl<Src: Unit, Dst: Unit> Clone for Transform3<Src, Dst>

source§

fn clone(&self) -> Self

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<Src, Dst> Debug for Transform3<Src, Dst>
where Src: Unit, Src::Scalar: FloatScalar, Dst: Unit,

source§

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

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

impl<Src, Dst> Default for Transform3<Src, Dst>
where Src: Unit, Src::Scalar: FloatScalar, Dst: Unit,

source§

fn default() -> Self

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

impl<Src, Dst, Dst2> Mul<Transform3<Dst, Dst2>> for Transform3<Src, Dst>
where Src: Unit, Src::Scalar: FloatScalar, Dst: Unit<Scalar = Src::Scalar>, Dst2: Unit<Scalar = Src::Scalar>,

§

type Output = Transform3<Src, Dst2>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Transform3<Dst, Dst2>) -> Self::Output

Performs the * operation. Read more
source§

impl<Src: Unit, Dst: Unit> PartialEq for Transform3<Src, Dst>

source§

fn eq(&self, other: &Self) -> 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<Src, Dst> RelativeEq for Transform3<Src, Dst>
where Src: Unit, Src::Scalar: FloatScalar, Dst: Unit,

source§

fn default_max_relative() -> Self::Epsilon

The default relative tolerance for testing values that are far-apart. Read more
source§

fn relative_eq( &self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon ) -> bool

A test for equality that uses a relative comparison if the values are far apart.
source§

fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon ) -> bool

The inverse of RelativeEq::relative_eq.
source§

impl<Src, Dst> TransformMap<Point3<Src>> for Transform3<Src, Dst>
where Src: Unit, Src::Scalar: FloatScalar, Dst: Unit<Scalar = Src::Scalar>,

§

type Output = Point3<Dst>

Result type of the transformation.
source§

fn map(&self, value: Point3<Src>) -> Self::Output

Map T to Self::Output.
source§

impl<Src, Dst> TransformMap<Vector3<Src>> for Transform3<Src, Dst>
where Src: Unit, Src::Scalar: FloatScalar, Dst: Unit<Scalar = Src::Scalar>,

§

type Output = Vector3<Dst>

Result type of the transformation.
source§

fn map(&self, value: Vector3<Src>) -> Self::Output

Map T to Self::Output.
source§

impl<Src: Unit, Dst: Unit> TransparentWrapper<Matrix4<<Src as Unit>::Scalar>> for Transform3<Src, Dst>

source§

fn wrap(s: Inner) -> Self
where Self: Sized,

Convert the inner type into the wrapper type.
source§

fn wrap_ref(s: &Inner) -> &Self

Convert a reference to the inner type into a reference to the wrapper type.
source§

fn wrap_mut(s: &mut Inner) -> &mut Self

Convert a mutable reference to the inner type into a mutable reference to the wrapper type.
source§

fn wrap_slice(s: &[Inner]) -> &[Self]
where Self: Sized,

Convert a slice to the inner type into a slice to the wrapper type.
source§

fn wrap_slice_mut(s: &mut [Inner]) -> &mut [Self]
where Self: Sized,

Convert a mutable slice to the inner type into a mutable slice to the wrapper type.
source§

fn peel(s: Self) -> Inner
where Self: Sized,

Convert the wrapper type into the inner type.
source§

fn peel_ref(s: &Self) -> &Inner

Convert a reference to the wrapper type into a reference to the inner type.
source§

fn peel_mut(s: &mut Self) -> &mut Inner

Convert a mutable reference to the wrapper type into a mutable reference to the inner type.
source§

fn peel_slice(s: &[Self]) -> &[Inner]
where Self: Sized,

Convert a slice to the wrapped type into a slice to the inner type.
source§

fn peel_slice_mut(s: &mut [Self]) -> &mut [Inner]
where Self: Sized,

Convert a mutable slice to the wrapped type into a mutable slice to the inner type.
source§

impl<Src, Dst> UlpsEq for Transform3<Src, Dst>
where Src: Unit, Src::Scalar: FloatScalar, Dst: Unit,

source§

fn default_max_ulps() -> u32

The default ULPs to tolerate when testing values that are far-apart. Read more
source§

fn ulps_eq(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool

A test for equality that uses units in the last place (ULP) if the values are far apart.
source§

fn ulps_ne(&self, other: &Rhs, epsilon: Self::Epsilon, max_ulps: u32) -> bool

The inverse of UlpsEq::ulps_eq.
source§

impl<Src: Unit, Dst: Unit> Zeroable for Transform3<Src, Dst>

source§

fn zeroed() -> Self

source§

impl<Src: Unit, Dst: Unit> Copy for Transform3<Src, Dst>

source§

impl<Src: Unit, Dst: Unit> Pod for Transform3<Src, Dst>

Auto Trait Implementations§

§

impl<Src, Dst> Freeze for Transform3<Src, Dst>
where <Src as Unit>::Scalar: Freeze,

§

impl<Src, Dst> RefUnwindSafe for Transform3<Src, Dst>
where Dst: RefUnwindSafe, <Src as Unit>::Scalar: RefUnwindSafe,

§

impl<Src, Dst> Send for Transform3<Src, Dst>
where Dst: Send,

§

impl<Src, Dst> Sync for Transform3<Src, Dst>
where Dst: Sync,

§

impl<Src, Dst> Unpin for Transform3<Src, Dst>
where Dst: Unpin, <Src as Unit>::Scalar: Unpin,

§

impl<Src, Dst> UnwindSafe for Transform3<Src, Dst>
where Dst: UnwindSafe, <Src as Unit>::Scalar: UnwindSafe,

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
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> CheckedBitPattern for T
where T: AnyBitPattern,

§

type Bits = T

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
source§

fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
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,

§

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 T
where U: Into<T>,

§

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

§

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

impl<T> AnyBitPattern for T
where T: Pod,

source§

impl<T> NoUninit for T
where T: Pod,

source§

impl<T> PodValue for T
where T: Copy + Debug + Default + PartialEq + Pod + Send + Sync + Serializable + 'static,

source§

impl<T> Serializable for T