From 93597f0ef9105cb2e0e8da606fe8528a3529abf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Tue, 23 Jul 2013 18:41:57 +0200 Subject: [PATCH] Add look_at_z. Having a look_at which aligns the z-axis with the look_at direction is useful for cameras. It will exist only in 3d. --- src/adaptors/rotmat.rs | 11 +++++++++++ src/adaptors/transform.rs | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/src/adaptors/rotmat.rs b/src/adaptors/rotmat.rs index 1bef1a86..86a51438 100644 --- a/src/adaptors/rotmat.rs +++ b/src/adaptors/rotmat.rs @@ -86,6 +86,17 @@ impl Rotmat> xaxis.y.clone(), yaxis.y.clone(), zaxis.y.clone(), xaxis.z , yaxis.z , zaxis.z) } + + pub fn look_at_z(&mut self, at: &Vec3, up: &Vec3) + { + let zaxis = at.normalized(); + let xaxis = up.cross(&zaxis).normalized(); + let yaxis = zaxis.cross(&xaxis); + + self.submat = Mat3::new(xaxis.x.clone(), yaxis.x.clone(), zaxis.x.clone(), + xaxis.y.clone(), yaxis.y.clone(), zaxis.y.clone(), + xaxis.z , yaxis.z , zaxis.z) + } } impl diff --git a/src/adaptors/transform.rs b/src/adaptors/transform.rs index 00dba499..da3422bc 100644 --- a/src/adaptors/transform.rs +++ b/src/adaptors/transform.rs @@ -47,6 +47,12 @@ impl Transform>, Vec3> self.submat.look_at(&(*at - *eye), up); self.subtrans = eye.clone(); } + + pub fn look_at_z(&mut self, eye: &Vec3, at: &Vec3, up: &Vec3) + { + self.submat.look_at_z(&(*at - *eye), up); + self.subtrans = eye.clone(); + } } impl Dim for Transform