aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeanne-Kamikaze <jeannekamikaze@gmail.com>2013-03-13 15:04:00 +0100
committerJeanne-Kamikaze <jeannekamikaze@gmail.com>2013-03-13 15:04:00 +0100
commit60985b91aba4bc62bd9cb3056f08c6e8bf591679 (patch)
tree9888da9a9a079c146416a0ab8cb219202f76a956
parentfd9d8e0a6137700990cf2f96133c2fc65270c49a (diff)
Added rotate
-rw-r--r--Spear/Math/Spatial3.hs22
1 files changed, 15 insertions, 7 deletions
diff --git a/Spear/Math/Spatial3.hs b/Spear/Math/Spatial3.hs
index 7d0420a..e0069b0 100644
--- a/Spear/Math/Spatial3.hs
+++ b/Spear/Math/Spatial3.hs
@@ -8,7 +8,9 @@ module Spear.Math.Spatial3
8where 8where
9 9
10import Spear.Math.Vector 10import Spear.Math.Vector
11import Spear.Math.Matrix4 as M hiding (scale) 11import qualified Spear.Math.Matrix4 as M
12
13type Matrix4 = M.Matrix4
12 14
13class Spatial3 s where 15class Spatial3 s where
14 -- | Gets the spatial's internal Obj3. 16 -- | Gets the spatial's internal Obj3.
@@ -37,6 +39,13 @@ class Spatial3 s where
37 strafeRight :: Float -> s -> s 39 strafeRight :: Float -> s -> s
38 strafeRight a s = let o = getObj3 s in setObj3 s $ o { p = p o + scale a (r o) } 40 strafeRight a s = let o = getObj3 s in setObj3 s $ o { p = p o + scale a (r o) }
39 41
42 -- | Rotate the spatial about the given axis.
43 rotate :: Vector3 -> Float -> s -> s
44 rotate axis a s =
45 let t = transform s
46 axis' = M.inverseTransform t `M.muld` axis
47 in setTransform (t * M.axisAngle axis' a) s
48
40 -- | Rotate the spatial about its local X axis. 49 -- | Rotate the spatial about its local X axis.
41 pitch :: Float -> s -> s 50 pitch :: Float -> s -> s
42 pitch a s = 51 pitch a s =
@@ -93,12 +102,7 @@ class Spatial3 s where
93 -- | Set the spatial's transform. 102 -- | Set the spatial's transform.
94 setTransform :: Matrix4 -> s -> s 103 setTransform :: Matrix4 -> s -> s
95 setTransform t s = 104 setTransform t s =
96 let o = Obj3 105 let o = Obj3 (M.right t) (M.up t) (scale (-1) $ M.forward t) (M.position t)
97 { r = M.right t
98 , u = M.up t
99 , f = scale (-1) $ M.forward t
100 , p = M.position t
101 }
102 in setObj3 s o 106 in setObj3 s o
103 107
104 -- | Set the spatial's position. 108 -- | Set the spatial's position.
@@ -144,6 +148,10 @@ data Obj3 = Obj3
144 , p :: Vector3 148 , p :: Vector3
145 } deriving Show 149 } deriving Show
146 150
151instance Spatial3 Obj3 where
152 getObj3 = id
153 setObj3 _ o' = o'
154
147fromVectors :: Right3 -> Up3 -> Forward3 -> Position3 -> Obj3 155fromVectors :: Right3 -> Up3 -> Forward3 -> Position3 -> Obj3
148fromVectors = Obj3 156fromVectors = Obj3
149 157