[−][src]Struct gramit::transform::Transform
A builder struct for homogeneous transformation matrices.
A Transform
is used to construct arbitrary affine transformations starting from the identity
transformation, primarily by composing translation, scaling, shear, and rotation
transformations. The final matrix is obtained via the finish()
method.
Example
use gramit::transform::Transform; // `mat` is a matrix that represents the effect of _first_ shearing the x axis 1 unit in the // y direction, _then_ rotating about the y axis 180 degrees. let mat: Mat4 = Transform::new() .shear_x(1.0, 0.0) .rotate(Vec3::y(), Angle::from_degrees(180.0)) .finish(); //assert_approx_eq!( // (mat * vec3!(1.0, 0.0, 0.0).homogeneous()).homogenize(), // vec3!(1.0, -1.0, 0.0));
Note that each builder method applies its transformation after those of preceding builder methods. In matrix terms, this corresponds to multiplying the new transformation on the left, rather than the right. In other words, the above code computes the following matrix:
ROT((1, 0, 0), 180°) * SHEAR_X(1)
where ROT(axis, angle)
is a rotation about axis axis
by angle angle
and SHEAR_X(dist)
is a shear by distance dist
that fixes the x-axis.
Methods
impl Transform
[src]
pub fn new() -> Transform
[src]
Create a new Transform
.
Tranform
s initially represent the identity transformation (i.e. no transformation at all),
and are built into more useful transformations via other methods on the struct.
pub fn translate(self, offset: Vec3) -> Transform
[src]
Translate by the given offset.
pub fn scale(self, factor: Vec3) -> Transform
[src]
Scale by the given factors.
The scaling is performed independently per-axis, using the corresponding factor from the factor vector.
pub fn shear_x(self, y_amount: f32, z_amount: f32) -> Transform
[src]
Shear by the given amount, fixing the yz plane.
This will shear the x axis by the given amounts along the y and z axes.
pub fn shear_y(self, x_amount: f32, z_amount: f32) -> Transform
[src]
Shear by the given amount, fixing the xz plane.
This will shear the y axis by the given amounts along the x and z axes.
pub fn shear_z(self, x_amount: f32, y_amount: f32) -> Transform
[src]
Shear by the given amount, fixing the xy plane.
This will shear the z axis by the given amounts along the x and y axes.
pub fn rotate(self, axis: Vec3, angle: Angle) -> Transform
[src]
Rotate about the given axis by the given angle.
pub fn arbitrary(self, transform: Mat4) -> Transform
[src]
Apply an arbitrary affine transformation, represented by a homogenous matrix.
pub fn finish(&self) -> Mat4
[src]
Consume the Transform
and acquire the resulting homogeneous transformation matrix.
Trait Implementations
impl Clone for Transform
[src]
impl Copy for Transform
[src]
impl Default for Transform
[src]
impl PartialEq<Transform> for Transform
[src]
impl Debug for Transform
[src]
impl StructuralPartialEq for Transform
[src]
Auto Trait Implementations
impl Send for Transform
impl Sync for Transform
impl Unpin for Transform
impl UnwindSafe for Transform
impl RefUnwindSafe for Transform
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,