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>
impl<Src, Dst> Transform3<Src, Dst>
sourcepub const fn from_matrix_unchecked(matrix: Matrix4<Src::Scalar>) -> Self
pub const fn from_matrix_unchecked(matrix: Matrix4<Src::Scalar>) -> Self
Create from matrix.
sourcepub fn from_matrix(matrix: Matrix4<Src::Scalar>) -> Option<Self>
pub fn from_matrix(matrix: Matrix4<Src::Scalar>) -> Option<Self>
Create from matrix, checking if the matrix is invertible.
sourcepub fn then<Dst2: Unit<Scalar = Dst::Scalar>>(
self,
other: Transform3<Dst, Dst2>
) -> Transform3<Src, Dst2>
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.
sourcepub fn then_rotate(self, axis: Vector3<Dst>, angle: Angle<Src::Scalar>) -> Self
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.
sourcepub fn then_scale(self, scale: Vector3<Dst>) -> Self
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);
sourcepub fn then_translate(self, translation: Vector3<Dst>) -> Self
pub fn then_translate(self, translation: Vector3<Dst>) -> Self
Shorthand for .then(Transform3::from_scale(scale))
.
This does not change the target coordinate space.
sourcepub fn from_axis_angle(axis: Vector3<Src>, angle: Angle<Src::Scalar>) -> Self
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);
sourcepub fn from_scale(scale: Vector3<Src>) -> Self
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));
sourcepub fn from_translation(translation: Vector3<Src>) -> Self
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));
sourcepub fn from_scale_rotation_translation(
scale: Vector3<Src>,
axis: Vector3<Src>,
angle: Angle<Src::Scalar>,
translation: Vector3<Src>
) -> Self
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);
sourcepub fn map_vector(&self, vector: Vector3<Src>) -> Vector3<Dst>
pub fn map_vector(&self, vector: Vector3<Src>) -> Vector3<Dst>
Map vector from Src
to Dst
.
See glam::Mat4::transform_vector3()
and
glam::DMat4::transform_vector3()
.
sourcepub fn map_point(&self, point: Point3<Src>) -> Point3<Dst>
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()
.
sourcepub fn inverse(&self) -> Transform3<Dst, Src>
pub fn inverse(&self) -> Transform3<Dst, Src>
Invert the matrix.
Trait Implementations§
source§impl<Src, Dst> AbsDiffEq for Transform3<Src, Dst>
impl<Src, Dst> AbsDiffEq for Transform3<Src, Dst>
§type Epsilon = <Matrix4<<Src as Unit>::Scalar> as AbsDiffEq>::Epsilon
type Epsilon = <Matrix4<<Src as Unit>::Scalar> as AbsDiffEq>::Epsilon
source§fn default_epsilon() -> Self::Epsilon
fn default_epsilon() -> Self::Epsilon
source§fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
source§fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
AbsDiffEq::abs_diff_eq
.source§impl<Src, Dst> Debug for Transform3<Src, Dst>
impl<Src, Dst> Debug for Transform3<Src, Dst>
source§impl<Src, Dst> Default for Transform3<Src, Dst>
impl<Src, Dst> Default for Transform3<Src, Dst>
source§impl<Src, Dst, Dst2> Mul<Transform3<Dst, Dst2>> for Transform3<Src, Dst>
impl<Src, Dst, Dst2> Mul<Transform3<Dst, Dst2>> for Transform3<Src, Dst>
§type Output = Transform3<Src, Dst2>
type Output = Transform3<Src, Dst2>
*
operator.source§impl<Src: Unit, Dst: Unit> PartialEq for Transform3<Src, Dst>
impl<Src: Unit, Dst: Unit> PartialEq for Transform3<Src, Dst>
source§impl<Src, Dst> RelativeEq for Transform3<Src, Dst>
impl<Src, Dst> RelativeEq for Transform3<Src, Dst>
source§fn default_max_relative() -> Self::Epsilon
fn default_max_relative() -> Self::Epsilon
source§fn relative_eq(
&self,
other: &Self,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon
) -> bool
fn relative_eq( &self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon ) -> bool
source§fn relative_ne(
&self,
other: &Rhs,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon
) -> bool
fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon ) -> bool
RelativeEq::relative_eq
.source§impl<Src, Dst> TransformMap<Point3<Src>> for Transform3<Src, Dst>
impl<Src, Dst> TransformMap<Point3<Src>> for Transform3<Src, Dst>
source§impl<Src, Dst> TransformMap<Vector3<Src>> for Transform3<Src, Dst>
impl<Src, Dst> TransformMap<Vector3<Src>> for Transform3<Src, Dst>
source§impl<Src: Unit, Dst: Unit> TransparentWrapper<Matrix4<<Src as Unit>::Scalar>> for Transform3<Src, Dst>
impl<Src: Unit, Dst: Unit> TransparentWrapper<Matrix4<<Src as Unit>::Scalar>> for Transform3<Src, Dst>
source§fn wrap_ref(s: &Inner) -> &Self
fn wrap_ref(s: &Inner) -> &Self
source§fn wrap_mut(s: &mut Inner) -> &mut Self
fn wrap_mut(s: &mut Inner) -> &mut Self
source§fn wrap_slice(s: &[Inner]) -> &[Self]where
Self: Sized,
fn wrap_slice(s: &[Inner]) -> &[Self]where
Self: Sized,
source§fn wrap_slice_mut(s: &mut [Inner]) -> &mut [Self]where
Self: Sized,
fn wrap_slice_mut(s: &mut [Inner]) -> &mut [Self]where
Self: Sized,
source§fn peel_ref(s: &Self) -> &Inner
fn peel_ref(s: &Self) -> &Inner
source§fn peel_mut(s: &mut Self) -> &mut Inner
fn peel_mut(s: &mut Self) -> &mut Inner
source§impl<Src, Dst> UlpsEq for Transform3<Src, Dst>
impl<Src, Dst> UlpsEq for Transform3<Src, Dst>
impl<Src: Unit, Dst: Unit> Copy for Transform3<Src, Dst>
impl<Src: Unit, Dst: Unit> Pod for Transform3<Src, Dst>
Auto Trait Implementations§
impl<Src, Dst> Freeze for Transform3<Src, Dst>
impl<Src, Dst> RefUnwindSafe for Transform3<Src, Dst>
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>
impl<Src, Dst> UnwindSafe for Transform3<Src, Dst>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
§type Bits = T
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
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self
.