- added translate to Matrix
- fixed spaces and tabs
This commit is contained in:
parent
1c5b6f0b7a
commit
1cf9f8d4ef
2 changed files with 17 additions and 0 deletions
|
@ -250,6 +250,15 @@ impl<S: BaseNum> Matrix4<S> {
|
||||||
pub fn identity() -> Matrix4<S> {
|
pub fn identity() -> Matrix4<S> {
|
||||||
Matrix4::from_value(one())
|
Matrix4::from_value(one())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a translation matrix from a Vector3
|
||||||
|
#[inline]
|
||||||
|
pub fn from_translation(v: &Vector3<S>) -> Matrix4<S> {
|
||||||
|
Matrix4::new(one(), zero(), zero(), zero(),
|
||||||
|
zero(), one(), zero(), zero(),
|
||||||
|
zero(), zero(), one(), zero(),
|
||||||
|
v.x, v.y, v.z, one())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: BaseFloat>
|
impl<S: BaseFloat>
|
||||||
|
|
|
@ -328,6 +328,14 @@ fn test_invert() {
|
||||||
assert!(mat_f.invert().unwrap().mul_m(&mat_f).is_identity());
|
assert!(mat_f.invert().unwrap().mul_m(&mat_f).is_identity());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_from_translation() {
|
||||||
|
let mat = Matrix4::from_translation(&Vector3::new(1.0f64, 2.0f64, 3.0f64));
|
||||||
|
let vertex = Vector4::new(0.0f64, 0.0f64, 0.0f64, 1.0f64);
|
||||||
|
let res = mat.mul_v(&vertex);
|
||||||
|
assert_eq!(res, Vector4::new(1., 2., 3., 1.));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_predicates() {
|
fn test_predicates() {
|
||||||
// Matrix2
|
// Matrix2
|
||||||
|
|
Loading…
Reference in a new issue