aboutsummaryrefslogtreecommitdiff
path: root/Spear/Math/MatrixUtils.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Spear/Math/MatrixUtils.hs')
-rw-r--r--Spear/Math/MatrixUtils.hs26
1 files changed, 9 insertions, 17 deletions
diff --git a/Spear/Math/MatrixUtils.hs b/Spear/Math/MatrixUtils.hs
index 2c1d083..dcc1965 100644
--- a/Spear/Math/MatrixUtils.hs
+++ b/Spear/Math/MatrixUtils.hs
@@ -1,7 +1,6 @@
1module Spear.Math.MatrixUtils 1module Spear.Math.MatrixUtils
2( 2(
3 Rotation(..) 3 fastNormalMatrix
4, fastNormalMatrix
5, rpgTransform 4, rpgTransform
6, pltTransform 5, pltTransform
7, rpgInverse 6, rpgInverse
@@ -16,9 +15,6 @@ import Spear.Math.Vector2 as V2
16import Spear.Math.Vector3 as V3 15import Spear.Math.Vector3 as V3
17 16
18 17
19data Rotation = Yaw | Pitch | Roll deriving Eq
20
21
22-- | Compute the normal matrix of the given matrix. 18-- | Compute the normal matrix of the given matrix.
23fastNormalMatrix :: Matrix4 -> Matrix3 19fastNormalMatrix :: Matrix4 -> Matrix3
24fastNormalMatrix m = 20fastNormalMatrix m =
@@ -31,21 +27,17 @@ fastNormalMatrix m =
31 27
32-- | Maps the given 2D transformation matrix to a 3D transformation matrix. 28-- | Maps the given 2D transformation matrix to a 3D transformation matrix.
33rpgTransform 29rpgTransform
34 :: Float -- ^ The height above the ground. 30 :: Float -- ^ The height above the ground
35 -> Float -- ^ Angle of rotation. 31 -> Float -- ^ Angle of rotation
36 -> Rotation -- ^ How the 2D rotation should be interpreted in 3D. 32 -> Vector3 -- ^ Axis of rotation
37 -> Matrix3 33 -> Matrix3
38 -> Matrix4 34 -> Matrix4
39rpgTransform h a rtype mat = 35rpgTransform h a axis mat =
40 {-let r = let r' = M3.right mat in vec3 (V2.x r') (V2.y r') 0 36 {-let r = let r' = M3.right mat in vec3 (V2.x r') (V2.y r') 0
41 u = V3.unity 37 u = V3.unity
42 f = let f' = M3.forward mat in vec3 (V2.x f') 0 (V2.y f') 38 f = let f' = M3.forward mat in vec3 (V2.x f') 0 (V2.y f')
43 t = (vec3 0 h 0) + let t' = M3.position mat in vec3 (V2.x t') 0 (V2.y t')-} 39 t = (vec3 0 h 0) + let t' = M3.position mat in vec3 (V2.x t') 0 (V2.y t')-}
44 let rot = case rtype of 40 let mat' = axisAngle axis a
45 Yaw -> rotY
46 Pitch -> rotX
47 Roll -> rotZ
48 mat' = rot a
49 r = M4.right mat' 41 r = M4.right mat'
50 u = M4.up mat' 42 u = M4.up mat'
51 f = M4.forward mat' 43 f = M4.forward mat'
@@ -79,9 +71,9 @@ pltTransform mat =
79-- 71--
80-- Use this in games such as RPGs and RTSs. 72-- Use this in games such as RPGs and RTSs.
81rpgInverse 73rpgInverse
82 :: Float -- ^ The height above the ground. 74 :: Float -- ^ The height above the ground
83 -> Float -- ^ Angle of rotation. 75 -> Float -- ^ Angle of rotation
84 -> Rotation -- ^ How the 2D rotation should be interpreted in 3D. 76 -> Vector3 -- ^ Axis of rotation
85 -> Matrix3 77 -> Matrix3
86 -> Matrix4 78 -> Matrix4
87rpgInverse h a rot = M4.inverseTransform . rpgTransform h a rot 79rpgInverse h a rot = M4.inverseTransform . rpgTransform h a rot