matrices: implement Matrix4x4::translate
This commit is contained in:
parent
462c90e8c8
commit
117d7185e4
@ -223,6 +223,32 @@ impl Matrix4x4 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a 4x4 matrix representing a translation of x,y,z.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use rtchallenge::{matrices::Matrix4x4, tuples::Tuple};
|
||||||
|
///
|
||||||
|
/// let transform = Matrix4x4::translate(5., -3., 2.);
|
||||||
|
/// let p = Tuple::point(-3., 4., 5.);
|
||||||
|
/// assert_eq!(transform * p, Tuple::point(2., 1., 7.));
|
||||||
|
///
|
||||||
|
/// let inv = transform.inverse();
|
||||||
|
/// assert_eq!(inv * p, Tuple::point(-8., 7., 3.));
|
||||||
|
///
|
||||||
|
/// let v = Tuple::vector(-3., 4., 5.);
|
||||||
|
/// assert_eq!(transform * v, v);
|
||||||
|
/// ```
|
||||||
|
pub fn translate(x: f32, y: f32, z: f32) -> Matrix4x4 {
|
||||||
|
Matrix4x4::new(
|
||||||
|
[1., 0., 0., x],
|
||||||
|
[0., 1., 0., y],
|
||||||
|
[0., 0., 1., z],
|
||||||
|
[0., 0., 0., 1.],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/// Transpose self, returning a new matrix that has been reflected across the diagonal.
|
/// Transpose self, returning a new matrix that has been reflected across the diagonal.
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user