From 2d6b4e785c284c4b196252a5503c355e8cee86cf Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Sun, 6 Dec 2015 19:48:37 +1100 Subject: [PATCH] Add Matrix4::{from_scale, from_uniform_scale} functions --- src/matrix.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/matrix.rs b/src/matrix.rs index 9bb96c0..77b344e 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -214,7 +214,7 @@ impl Matrix4 { } impl Matrix4 { - /// Create a translation matrix from a Vector3 + /// Create a homogeneous transformation matrix from a translation vector. #[inline] pub fn from_translation(v: Vector3) -> Matrix4 { Matrix4::new(S::one(), S::zero(), S::zero(), S::zero(), @@ -225,7 +225,22 @@ impl Matrix4 { } impl Matrix4 { - /// Create a transformation matrix that will cause a vector to point at + /// Create a homogeneous transformation matrix from a set of scale values. + #[inline] + pub fn from_scale(x: S, y: S, z: S) -> Matrix4 { + Matrix4::new(x, S::zero(), S::zero(), S::zero(), + S::zero(), y, S::zero(), S::zero(), + S::zero(), S::zero(), z, S::zero(), + S::zero(), S::zero(), S::zero(), S::one()) + } + + /// Create a homogeneous transformation matrix from a scale value. + #[inline] + pub fn from_uniform_scale(value: S) -> Matrix4 { + Matrix4::from_scale(value, value, value) + } + + /// Create a homogeneous transformation matrix that will cause a vector to point at /// `dir`, using `up` for orientation. pub fn look_at(eye: Point3, center: Point3, up: Vector3) -> Matrix4 { let f = (center - eye).normalize();