From 48bcc15a9971368c232bd800493cbf688958bb08 Mon Sep 17 00:00:00 2001
From: Marc Sunet <jeannekamikaze@gmail.com>
Date: Sat, 1 Sep 2012 13:15:35 +0200
Subject: Added translation and rotation constructors

---
 Spear/Math/Matrix3.hs | 28 +++++++++++++++++++++++++++-
 Spear/Math/Matrix4.hs | 30 ++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/Spear/Math/Matrix3.hs b/Spear/Math/Matrix3.hs
index 06c06a2..b295cbd 100644
--- a/Spear/Math/Matrix3.hs
+++ b/Spear/Math/Matrix3.hs
@@ -11,7 +11,9 @@ module Spear.Math.Matrix3
     -- * Construction
 ,   mat3
 ,   mat3fromVec
-,   transform
+,   transform
+,   translation
+,   rotation
 ,   Spear.Math.Matrix3.id
     -- * Transformations
     -- ** Translation
@@ -153,6 +155,30 @@ transform r f p = mat3
     (V2.x r) (V2.x f) (V2.x p)
     (V2.y r) (V2.y f) (V2.y p)
     0        0        1
+
+
+-- | Get the translation part of the given transformation matrix.
+translation :: Matrix3 -> Matrix3
+translation (Matrix3
+    a00 a10 a20
+    a01 a11 a21
+    a02 a12 a22)
+    = mat3
+    1   0   a20
+    0   1   a21
+    0   0   a22
+
+
+-- | Get the rotation part of the given transformationmatrix.
+rotation :: Matrix3 -> Matrix3
+rotation (Matrix3
+    a00 a10 a20
+    a01 a11 a21
+    a02 a12 a22)
+    = mat3
+    a00 a10 0
+    a01 a11 0
+    a02 a12 1
 
 
 -- | Return the identity matrix.
diff --git a/Spear/Math/Matrix4.hs b/Spear/Math/Matrix4.hs
index 85ab39f..5c54aea 100644
--- a/Spear/Math/Matrix4.hs
+++ b/Spear/Math/Matrix4.hs
@@ -13,6 +13,8 @@ module Spear.Math.Matrix4
 ,   mat4
 ,   mat4fromVec
 ,   transform
+,   translation
+,   rotation
 ,   lookAt
 ,   Spear.Math.Matrix4.id
     -- * Transformations
@@ -186,6 +188,34 @@ transform right up fwd pos = mat4
     0                 0              0               1
 
 
+-- | Get the translation part of the given transformation matrix.
+translation :: Matrix4 -> Matrix4
+translation (Matrix4
+    a00 a10 a20 a30
+    a01 a11 a21 a31
+    a02 a12 a22 a32
+    a03 a13 a23 a33)
+    = mat4
+    1   0   0   a30
+    0   1   0   a31
+    0   0   1   a32
+    0   0   0   a33    
+
+
+-- | Get the rotation part of the given transformation matrix.
+rotation :: Matrix4 -> Matrix4
+rotation (Matrix4
+    a00 a10 a20 a30
+    a01 a11 a21 a31
+    a02 a12 a22 a32
+    a03 a13 a23 a33)
+    = mat4
+    a00 a10 a20 0
+    a01 a11 a21 0
+    a02 a12 a22 0
+    a03 a13 a23 1    
+
+
 -- | Build a transformation 'Matrix4' defined by the given position and target.
 lookAt :: Vector3 -- ^ Eye position.
        -> Vector3 -- ^ Target point.
-- 
cgit v1.2.3