aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Sunet <jeannekamikaze@gmail.com>2012-09-01 11:20:12 +0200
committerMarc Sunet <jeannekamikaze@gmail.com>2012-09-01 11:20:12 +0200
commit5bdb855e7143d13b05ac836978dd8e67017482df (patch)
treee0cdd0d36f6e6f1d2b035cc5f6c2368bba492e5d
parent47832170e1b107b6a937e9d46bf07d7502abe159 (diff)
Replaced Rotation for an arbitrary axis
-rw-r--r--Spear.lkshs6
-rw-r--r--Spear.lkshw4
-rw-r--r--Spear/Math/MatrixUtils.hs26
-rw-r--r--Spear/Scene/GameObject.hs81
-rw-r--r--Spear/Scene/Loader.hs17
5 files changed, 59 insertions, 75 deletions
diff --git a/Spear.lkshs b/Spear.lkshs
index 4b0d469..3e07004 100644
--- a/Spear.lkshs
+++ b/Spear.lkshs
@@ -1,14 +1,14 @@
1Version of session file format: 1Version of session file format:
2 1 2 1
3Time of storage: 3Time of storage:
4 "Fri Aug 31 22:25:44 CEST 2012" 4 "Sat Sep 1 10:54:22 CEST 2012"
5Layout: VerticalP (TerminalP {paneGroups = fromList [], paneTabs = Just TopP, currentPage = 1, detachedId = Nothing, detachedSize = Nothing}) (HorizontalP (TerminalP {paneGroups = fromList [("Browser",HorizontalP (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (HorizontalP (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 302) 217),("Debug",HorizontalP (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Just TopP, currentPage = 1, detachedId = Nothing, detachedSize = Nothing}) 256)], paneTabs = Just BottomP, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 663) 954 5Layout: VerticalP (TerminalP {paneGroups = fromList [], paneTabs = Just TopP, currentPage = 1, detachedId = Nothing, detachedSize = Nothing}) (HorizontalP (TerminalP {paneGroups = fromList [("Browser",HorizontalP (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (HorizontalP (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 327) 235),("Debug",HorizontalP (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Just TopP, currentPage = 1, detachedId = Nothing, detachedSize = Nothing}) 277)], paneTabs = Just BottomP, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 714) 954
6Population: [(Just (BreakpointsSt BreakpointsState),[SplitP RightP,SplitP TopP,GroupP "Debug",SplitP BottomP]),(Just (ErrorsSt ErrorsState),[SplitP RightP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Factory.hs" 1205)),[SplitP LeftP]),(Just (FilesSt FilesState),[SplitP RightP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Scene/GameObject.hs" 3114)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject.hs" 1432)),[SplitP LeftP]),(Just (InfoSt (InfoState Nothing)),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP BottomP,SplitP BottomP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Scene/Loader.hs" 17178)),[SplitP LeftP]),(Just (LogSt LogState),[SplitP RightP,SplitP BottomP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Math/MatrixUtils.hs" 1235)),[SplitP LeftP]),(Just (ModulesSt (ModulesState 328 (PackageScope False,False) (Nothing,Nothing) (ExpanderState {packageExp = ([],[]), packageExpNoBlack = ([[0]],[]), packageDExp = ([],[]), packageDExpNoBlack = ([],[]), workspaceExp = ([],[]), workspaceExpNoBlack = ([],[]), workspaceDExp = ([],[]), workspaceDExpNoBlack = ([],[]), systemExp = ([],[]), systemExpNoBlack = ([],[])}))),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP BottomP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Player.hs" 2249)),[SplitP LeftP]),(Just (SearchSt (SearchState {searchString = "putStrLn", searchScope = PackageScope False, searchMode = Prefix {caseSense = False}})),[SplitP RightP,SplitP TopP]),(Just (TraceSt TraceState),[SplitP RightP,SplitP TopP,GroupP "Debug",SplitP BottomP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Utils.hs" 587)),[SplitP LeftP]),(Just (VariablesSt VariablesState),[SplitP RightP,SplitP TopP,GroupP "Debug",SplitP BottomP]),(Just (WorkspaceSt WorkspaceState),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP TopP]),(Just (BufferSt (BufferStateTrans "_Eval.hs" "\n" 0)),[SplitP RightP,SplitP TopP,GroupP "Debug",SplitP TopP])] 6Population: [(Just (BreakpointsSt BreakpointsState),[SplitP RightP,SplitP TopP,GroupP "Debug",SplitP BottomP]),(Just (ErrorsSt ErrorsState),[SplitP RightP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Factory.hs" 1205)),[SplitP LeftP]),(Just (FilesSt FilesState),[SplitP RightP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Scene/GameObject.hs" 3114)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject.hs" 1432)),[SplitP LeftP]),(Just (InfoSt (InfoState Nothing)),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP BottomP,SplitP BottomP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Scene/Loader.hs" 17178)),[SplitP LeftP]),(Just (LogSt LogState),[SplitP RightP,SplitP BottomP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Math/MatrixUtils.hs" 1235)),[SplitP LeftP]),(Just (ModulesSt (ModulesState 328 (PackageScope False,False) (Nothing,Nothing) (ExpanderState {packageExp = ([],[]), packageExpNoBlack = ([[0]],[]), packageDExp = ([],[]), packageDExpNoBlack = ([],[]), workspaceExp = ([],[]), workspaceExpNoBlack = ([],[]), workspaceDExp = ([],[]), workspaceDExpNoBlack = ([],[]), systemExp = ([],[]), systemExpNoBlack = ([],[])}))),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP BottomP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Player.hs" 2249)),[SplitP LeftP]),(Just (SearchSt (SearchState {searchString = "putStrLn", searchScope = PackageScope False, searchMode = Prefix {caseSense = False}})),[SplitP RightP,SplitP TopP]),(Just (TraceSt TraceState),[SplitP RightP,SplitP TopP,GroupP "Debug",SplitP BottomP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Utils.hs" 587)),[SplitP LeftP]),(Just (VariablesSt VariablesState),[SplitP RightP,SplitP TopP,GroupP "Debug",SplitP BottomP]),(Just (WorkspaceSt WorkspaceState),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP TopP]),(Just (BufferSt (BufferStateTrans "_Eval.hs" "\n" 0)),[SplitP RightP,SplitP TopP,GroupP "Debug",SplitP TopP])]
7Window size: (1820,944) 7Window size: (1820,944)
8Completion size: 8Completion size:
9 (750,399) 9 (750,399)
10Workspace: Just "/home/jeanne/programming/haskell/Spear/Spear.lkshw" 10Workspace: Just "/home/jeanne/programming/haskell/Spear/Spear.lkshw"
11Active pane: Just "GameObject.hs" 11Active pane: Just "Modules"
12Toolbar visible: 12Toolbar visible:
13 True 13 True
14FindbarState: (False,FindState {entryStr = "986", entryHist = ["986","drawElements","56","drawArray","drawVA","f","SV","VAO","'VAO'","\170","\\","^"], replaceStr = "V3.", replaceHist = [], caseSensitive = True, entireWord = False, wrapAround = False, regex = False, lineNr = 1}) 14FindbarState: (False,FindState {entryStr = "986", entryHist = ["986","drawElements","56","drawArray","drawVA","f","SV","VAO","'VAO'","\170","\\","^"], replaceStr = "V3.", replaceHist = [], caseSensitive = True, entireWord = False, wrapAround = False, regex = False, lineNr = 1})
diff --git a/Spear.lkshw b/Spear.lkshw
index 79c18ef..ff27127 100644
--- a/Spear.lkshw
+++ b/Spear.lkshw
@@ -1,10 +1,10 @@
1Version of workspace file format: 1Version of workspace file format:
2 1 2 1
3Time of storage: 3Time of storage:
4 "Fri Aug 31 20:53:49 CEST 2012" 4 "Sat Sep 1 11:10:35 CEST 2012"
5Name of the workspace: 5Name of the workspace:
6 "Spear" 6 "Spear"
7File paths of contained packages: 7File paths of contained packages:
8 ["demos/simple-scene/simple-scene.cabal","Spear.cabal"] 8 ["demos/simple-scene/simple-scene.cabal","Spear.cabal"]
9Maybe file path of an active package: 9Maybe file path of an active package:
10 Just "demos/simple-scene/simple-scene.cabal" \ No newline at end of file 10 Just "Spear.cabal" \ No newline at end of file
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
diff --git a/Spear/Scene/GameObject.hs b/Spear/Scene/GameObject.hs
index f29ee09..d3b4e9e 100644
--- a/Spear/Scene/GameObject.hs
+++ b/Spear/Scene/GameObject.hs
@@ -3,7 +3,6 @@ module Spear.Scene.GameObject
3 GameObject 3 GameObject
4, GameStyle(..) 4, GameStyle(..)
5, AM.AnimationSpeed 5, AM.AnimationSpeed
6, Rotation(..)
7 -- * Construction 6 -- * Construction
8, goNew 7, goNew
9 -- * Accessors 8 -- * Accessors
@@ -54,10 +53,10 @@ data GameStyle
54-- | An object in the game scene. 53-- | An object in the game scene.
55data GameObject = GameObject 54data GameObject = GameObject
56 { gameStyle :: !GameStyle 55 { gameStyle :: !GameStyle
57 , rotation :: !Rotation
58 , renderer :: !(Either StaticModelRenderer AM.AnimatedModelRenderer) 56 , renderer :: !(Either StaticModelRenderer AM.AnimatedModelRenderer)
59 , collisioners :: ![Collisioner] 57 , collisioners :: ![Collisioner]
60 , transform :: !M3.Matrix3 58 , transform :: !M3.Matrix3
59 , axis :: Vector3
61 , angle :: Float 60 , angle :: Float
62 } 61 }
63 62
@@ -136,17 +135,17 @@ instance S2.Spatial2 GameObject where
136 135
137-- | Create a new game object. 136-- | Create a new game object.
138goNew :: GameStyle 137goNew :: GameStyle
139 -> Rotation
140 -> Either StaticModelResource AM.AnimatedModelResource 138 -> Either StaticModelResource AM.AnimatedModelResource
141 -> [Collisioner] 139 -> [Collisioner]
142 -> M3.Matrix3 140 -> M3.Matrix3 -- ^ Transform
141 -> Vector3 -- ^ Axis of rotation
143 -> GameObject 142 -> GameObject
144 143
145goNew style rtype (Left smr) cols transf = 144goNew style (Left smr) cols transf axis =
146 GameObject style rtype (Left $ SM.staticModelRenderer smr) cols transf 0 145 GameObject style (Left $ SM.staticModelRenderer smr) cols transf axis 0
147 146
148goNew style rtype (Right amr) cols transf = 147goNew style (Right amr) cols transf axis =
149 GameObject style rtype (Right $ AM.animatedModelRenderer 1 amr) cols transf 0 148 GameObject style (Right $ AM.animatedModelRenderer 1 amr) cols transf axis 0
150 149
151 150
152goUpdate :: Float -> GameObject -> GameObject 151goUpdate :: Float -> GameObject -> GameObject
@@ -160,6 +159,25 @@ goUpdate dt go =
160 } 159 }
161 160
162 161
162-- | Get the game object's ith bounding box.
163goAABB :: Int -> GameObject -> AABB
164goAABB i go = goAABB' $ (collisioners go) !! i
165
166goAABB' col = case col of
167 (AABBCol box) -> box
168 (CircleCol circle) -> aabbFromCircle circle
169
170
171-- | Get the game object's bounding boxes.
172goAABBs :: GameObject -> [AABB]
173goAABBs = fmap goAABB' . collisioners
174
175
176-- | Get the game object's 3D transform.
177go3Dtransform :: GameObject -> M4.Matrix4
178go3Dtransform go = rpgTransform 0 (angle go) (axis go) . S2.transform $ go
179
180
163-- | Get the game object's current animation. 181-- | Get the game object's current animation.
164currentAnimation :: Enum a => GameObject -> a 182currentAnimation :: Enum a => GameObject -> a
165currentAnimation go = case renderer go of 183currentAnimation go = case renderer go of
@@ -167,6 +185,11 @@ currentAnimation go = case renderer go of
167 Right amr -> AM.currentAnimation amr 185 Right amr -> AM.currentAnimation amr
168 186
169 187
188-- | Return the game object's number of collisioners.
189numCollisioners :: GameObject -> Int
190numCollisioners = length . collisioners
191
192
170-- | Set the game object's current animation. 193-- | Set the game object's current animation.
171setAnimation :: Enum a => a -> GameObject -> GameObject 194setAnimation :: Enum a => a -> GameObject -> GameObject
172setAnimation a go = case renderer go of 195setAnimation a go = case renderer go of
@@ -181,38 +204,14 @@ setAnimationSpeed s go = case renderer go of
181 Right amr -> go { renderer = Right $ AM.setAnimationSpeed s amr } 204 Right amr -> go { renderer = Right $ AM.setAnimationSpeed s amr }
182 205
183 206
184-- | Return the game object's number of collisioners.
185numCollisioners :: GameObject -> Int
186numCollisioners = length . collisioners
187
188
189-- | Manipulate the game object's collisioners.
190withCollisioners :: GameObject -> ([Collisioner] -> [Collisioner]) -> GameObject
191withCollisioners go f = go { collisioners = f $ collisioners go }
192
193
194-- | Set the game object's collisioners. 207-- | Set the game object's collisioners.
195setCollisioners :: GameObject -> [Collisioner] -> GameObject 208setCollisioners :: GameObject -> [Collisioner] -> GameObject
196setCollisioners go cols = go { collisioners = cols } 209setCollisioners go cols = go { collisioners = cols }
197 210
198 211
199-- | Get the game object's ith bounding box. 212-- | Manipulate the game object's collisioners.
200goAABB :: Int -> GameObject -> AABB 213withCollisioners :: GameObject -> ([Collisioner] -> [Collisioner]) -> GameObject
201goAABB i go = goAABB' $ (collisioners go) !! i 214withCollisioners go f = go { collisioners = f $ collisioners go }
202
203goAABB' col = case col of
204 (AABBCol box) -> box
205 (CircleCol circle) -> aabbFromCircle circle
206
207
208-- | Get the game object's bounding boxes.
209goAABBs :: GameObject -> [AABB]
210goAABBs = fmap goAABB' . collisioners
211
212
213-- | Get the game object's 3D transform.
214go3Dtransform :: GameObject -> M4.Matrix4
215go3Dtransform go = rpgTransform 0 (angle go) (rotation go) . S2.transform $ go
216 215
217 216
218-- | Render the game object. 217-- | Render the game object.
@@ -222,13 +221,13 @@ goRender sprog aprog cam go =
222 apu = animatedProgramUniforms aprog 221 apu = animatedProgramUniforms aprog
223 mat = S2.transform go 222 mat = S2.transform go
224 style = gameStyle go 223 style = gameStyle go
225 rtype = rotation go 224 axis' = axis go
226 a = angle go 225 a = angle go
227 in case renderer go of 226 in case renderer go of
228 Left smr -> 227 Left smr ->
229 goRender' style a rtype sprog spu mat cam (SM.bind spu smr) (SM.render spu smr) 228 goRender' style a axis' sprog spu mat cam (SM.bind spu smr) (SM.render spu smr)
230 Right amr -> 229 Right amr ->
231 goRender' style a rtype aprog apu mat cam (AM.bind apu amr) (AM.render apu amr) 230 goRender' style a axis' aprog apu mat cam (AM.bind apu amr) (AM.render apu amr)
232 231
233 232
234type Bind = IO () 233type Bind = IO ()
@@ -239,7 +238,7 @@ type Render = IO ()
239goRender' :: (ProgramUniforms u, Program p) 238goRender' :: (ProgramUniforms u, Program p)
240 => GameStyle 239 => GameStyle
241 -> Float 240 -> Float
242 -> Rotation 241 -> Vector3
243 -> p 242 -> p
244 -> u 243 -> u
245 -> M3.Matrix3 244 -> M3.Matrix3
@@ -247,10 +246,10 @@ goRender' :: (ProgramUniforms u, Program p)
247 -> Bind 246 -> Bind
248 -> Render 247 -> Render
249 -> IO () 248 -> IO ()
250goRender' style a rtype prog uniforms model cam bindRenderer render = 249goRender' style a axis prog uniforms model cam bindRenderer render =
251 let view = M4.inverseTransform $ Cam.transform cam 250 let view = M4.inverseTransform $ Cam.transform cam
252 modelview = case style of 251 modelview = case style of
253 RPG -> view * rpgTransform 0 a rtype model 252 RPG -> view * rpgTransform 0 a axis model
254 PLT -> view * pltTransform model 253 PLT -> view * pltTransform model
255 normalmat = fastNormalMatrix modelview 254 normalmat = fastNormalMatrix modelview
256 in do 255 in do
diff --git a/Spear/Scene/Loader.hs b/Spear/Scene/Loader.hs
index ea08385..f5d06a6 100644
--- a/Spear/Scene/Loader.hs
+++ b/Spear/Scene/Loader.hs
@@ -31,7 +31,7 @@ import Spear.Render.AnimatedModel as AM
31import Spear.Render.Material 31import Spear.Render.Material
32import Spear.Render.Program 32import Spear.Render.Program
33import Spear.Render.StaticModel as SM 33import Spear.Render.StaticModel as SM
34import qualified Spear.Scene.GameObject as GO 34import Spear.Scene.GameObject as GO
35import Spear.Scene.Graph 35import Spear.Scene.Graph
36import Spear.Scene.Light 36import Spear.Scene.Light
37import Spear.Scene.SceneResources 37import Spear.Scene.SceneResources
@@ -342,18 +342,18 @@ newLight _ = return ()
342-- Object Loading -- 342-- Object Loading --
343-------------------- 343--------------------
344 344
345loadGO :: GO.GameStyle -> SceneResources -> [Property] -> Matrix3 -> Setup GO.GameObject 345loadGO :: GameStyle -> SceneResources -> [Property] -> Matrix3 -> Setup GameObject
346loadGO style sceneRes props transf = do 346loadGO style sceneRes props transf = do
347 modelName <- asString . mandatory "model" $ props 347 modelName <- asString . mandatory "model" $ props
348 rtype <- asGORotation . mandatory "rotation" $ props 348 axis <- asVec3 . mandatory "axis" $ props
349 let animSpeed = asFloat . value "animation-speed" $ props 349 let animSpeed = asFloat . value "animation-speed" $ props
350 go <- case getAnimatedModel sceneRes modelName of 350 go <- case getAnimatedModel sceneRes modelName of
351 Just model -> 351 Just model ->
352 return $ GO.goNew style rtype (Right model) [] transf 352 return $ goNew style (Right model) [] transf axis
353 Nothing -> 353 Nothing ->
354 case getStaticModel sceneRes modelName of 354 case getStaticModel sceneRes modelName of
355 Just model -> 355 Just model ->
356 return $ GO.goNew style rtype (Left model) [] transf 356 return $ goNew style (Left model) [] transf axis
357 Nothing -> 357 Nothing ->
358 setupError $ "model " ++ modelName ++ " not found" 358 setupError $ "model " ++ modelName ++ " not found"
359 return $ case animSpeed of 359 return $ case animSpeed of
@@ -467,13 +467,6 @@ asRotation val = fmap parseRotation val
467 where parseRotation (ax:ay:az:order:_) = Rotation (read ax) (read ay) (read az) (readOrder order) 467 where parseRotation (ax:ay:az:order:_) = Rotation (read ax) (read ay) (read az) (readOrder order)
468 468
469 469
470asGORotation :: Functor f => f [String] -> f GO.Rotation
471asGORotation val = fmap parseRotation val
472 where parseRotation ["yaw"] = GO.Yaw
473 parseRotation ["pitch"] = GO.Pitch
474 parseRotation ["roll"] = GO.Roll
475
476
477data Rotation = Rotation 470data Rotation = Rotation
478 { ax :: Float 471 { ax :: Float
479 , ay :: Float 472 , ay :: Float