From 63e6474d408ee6fffaa1da5dee6d0bb26e3b2ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Tue, 8 Oct 2013 21:00:25 +0200 Subject: [PATCH] Re-add look_at methods for isometries. --- src/structs/iso.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/structs/iso.rs b/src/structs/iso.rs index 81c26cf5..1923ae39 100644 --- a/src/structs/iso.rs +++ b/src/structs/iso.rs @@ -51,6 +51,37 @@ pub struct Iso4 { translation: Vec4 } +impl Iso3 { + /// Reorient and translate this transformation such that its local `x` axis points to a given + /// direction. Note that the usually known `look_at` function does the same thing but with the + /// `z` axis. See `look_at_z` for that. + /// + /// # Arguments + /// * eye - The new translation of the transformation. + /// * at - The point to look at. `at - eye` is the direction the matrix `x` axis will be + /// aligned with. + /// * up - Vector pointing up. The only requirement of this parameter is to not be colinear + /// with `at`. Non-colinearity is not checked. + pub fn look_at(&mut self, eye: &Vec3, at: &Vec3, up: &Vec3) { + self.rotation.look_at(&(*at - *eye), up); + self.translation = eye.clone(); + } + + /// Reorient and translate this transformation such that its local `z` axis points to a given + /// direction. + /// + /// # Arguments + /// * eye - The new translation of the transformation. + /// * at - The point to look at. `at - eye` is the direction the matrix `x` axis will be + /// aligned with + /// * up - Vector pointing `up`. The only requirement of this parameter is to not be colinear + /// with `at`. Non-colinearity is not checked. + pub fn look_at_z(&mut self, eye: &Vec3, at: &Vec3, up: &Vec3) { + self.rotation.look_at_z(&(*at - *eye), up); + self.translation = eye.clone(); + } +} + iso_impl!(Iso2, Rot2, Vec2) double_dispatch_binop_decl_trait!(Iso2, Iso2MulRhs) mul_redispatch_impl!(Iso2, Iso2MulRhs)