aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Sunet <jeannekamikaze@gmail.com>2012-08-29 17:13:46 +0200
committerMarc Sunet <jeannekamikaze@gmail.com>2012-08-29 17:13:46 +0200
commit7822a0f647cccad70904918b89a249c54dd68c97 (patch)
tree1f5d0bbf75097c4ee1f33a2bf8ba3551e9f09870
parent894d156b25103b0ada31e498a610e0b7c90890f3 (diff)
GameObject takes a Matrix3; Loader changed to load 2D game objects
-rw-r--r--Spear.lkshw4
-rw-r--r--Spear/Scene/GameObject.hs9
-rw-r--r--Spear/Scene/Loader.hs64
3 files changed, 42 insertions, 35 deletions
diff --git a/Spear.lkshw b/Spear.lkshw
index 743f9cc..128fcfd 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 "Wed Aug 29 16:58:18 CEST 2012" 4 "Wed Aug 29 17:13:01 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 "Spear.cabal" \ No newline at end of file 10 Just "demos/simple-scene/simple-scene.cabal" \ No newline at end of file
diff --git a/Spear/Scene/GameObject.hs b/Spear/Scene/GameObject.hs
index dda7485..9f4d950 100644
--- a/Spear/Scene/GameObject.hs
+++ b/Spear/Scene/GameObject.hs
@@ -112,13 +112,14 @@ instance S2.Spatial2 GameObject where
112goNew :: GameStyle 112goNew :: GameStyle
113 -> Either StaticModelResource AnimatedModelResource 113 -> Either StaticModelResource AnimatedModelResource
114 -> Collisioner 114 -> Collisioner
115 -> M3.Matrix3
115 -> GameObject 116 -> GameObject
116 117
117goNew style (Left smr) col = 118goNew style (Left smr) col transf =
118 goUpdate' style (Left $ SM.staticModelRenderer smr) col M3.id 0 119 goUpdate' style (Left $ SM.staticModelRenderer smr) col transf 0
119 120
120goNew style (Right amr) col = 121goNew style (Right amr) col transf =
121 goUpdate' style (Right $ AM.animatedModelRenderer amr) col M3.id 0 122 goUpdate' style (Right $ AM.animatedModelRenderer amr) col transf 0
122 123
123 124
124goUpdate' :: GameStyle 125goUpdate' :: GameStyle
diff --git a/Spear/Scene/Loader.hs b/Spear/Scene/Loader.hs
index 6197d12..d53faab 100644
--- a/Spear/Scene/Loader.hs
+++ b/Spear/Scene/Loader.hs
@@ -21,11 +21,12 @@ where
21import Spear.Assets.Model as Model 21import Spear.Assets.Model as Model
22import Spear.Collision.Collisioner 22import Spear.Collision.Collisioner
23import qualified Spear.GLSL as GLSL 23import qualified Spear.GLSL as GLSL
24import qualified Spear.Math.Matrix3 as M3 24import Spear.Math.Matrix3 as M3
25import Spear.Math.Matrix4 as M4 25import Spear.Math.Matrix4 as M4
26import Spear.Math.MatrixUtils (fastNormalMatrix) 26import Spear.Math.MatrixUtils (fastNormalMatrix)
27import Spear.Math.Vector2 as V2
27import Spear.Math.Vector3 as V3 28import Spear.Math.Vector3 as V3
28import Spear.Math.Vector4 29import Spear.Math.Vector4 as V4
29import Spear.Render.AnimatedModel as AM 30import Spear.Render.AnimatedModel as AM
30import Spear.Render.Material 31import Spear.Render.Material
31import Spear.Render.Program 32import Spear.Render.Program
@@ -310,21 +311,25 @@ newLight _ = return ()
310-- Object Loading -- 311-- Object Loading --
311-------------------- 312--------------------
312 313
313loadGO :: GameStyle -> SceneResources -> [Property] -> Matrix4 -> Setup GameObject 314loadGO :: GameStyle -> SceneResources -> [Property] -> Matrix3 -> Setup GameObject
314loadGO style sceneRes props transf = do 315loadGO style sceneRes props transf = do
315 modelName <- asString . mandatory "model" $ props 316 modelName <- asString . mandatory "model" $ props
316 case getAnimatedModel sceneRes modelName of 317 case getAnimatedModel sceneRes modelName of
317 Just model -> return $ goNew style (Right model) (AABBCol $ AM.box 0 model) 318 Just model ->
318 Nothing -> case getStaticModel sceneRes modelName of 319 return $ goNew style (Right model) (AABBCol $ AM.box 0 model) transf
319 Just model -> return $ goNew style (Left model) (AABBCol $ SM.box 0 model) 320 Nothing ->
320 Nothing -> setupError $ "model " ++ modelName ++ " not found" 321 case getStaticModel sceneRes modelName of
322 Just model ->
323 return $ goNew style (Left model) (AABBCol $ SM.box 0 model) transf
324 Nothing ->
325 setupError $ "model " ++ modelName ++ " not found"
321 326
322 327
323type CreateGameObject m a 328type CreateGameObject m a
324 = String -- ^ The object's name. 329 = String -- ^ The object's name.
325 -> SceneResources 330 -> SceneResources
326 -> [Property] 331 -> [Property]
327 -> Matrix4 -- ^ The object's transform. 332 -> Matrix3 -- ^ The object's transform.
328 -> m a 333 -> m a
329 334
330 335
@@ -349,27 +354,22 @@ newObject' :: Monad m => CreateGameObject m a -> SceneResources -> String -> [Pr
349newObject' newGO sceneRes nid props = do 354newObject' newGO sceneRes nid props = do
350 -- Optional properties. 355 -- Optional properties.
351 let goType = (asString $ value "type" props) `unspecified` "unknown" 356 let goType = (asString $ value "type" props) `unspecified` "unknown"
352 position = (asVec3 $ value "position" props) `unspecified` vec3 0 0 0 357 position = (asVec2 $ value "position" props) `unspecified` vec2 0 0
353 rotation = (asVec3 $ value "rotation" props) `unspecified` vec3 0 0 0 358 rotation = (asVec2 $ value "rotation" props) `unspecified` vec2 0 0
354 right' = (asVec3 $ value "right" props) `unspecified` vec3 1 0 0 359 right' = (asVec2 $ value "right" props) `unspecified` vec2 1 0
355 up' = (asVec3 $ value "up" props) `unspecified` vec3 0 1 0 360 up' = asVec2 $ value "up" props
356 forward' = asVec3 $ value "forward" props 361 scale = (asVec2 $ value "scale" props) `unspecified` vec2 1 1
357 scale = (asVec3 $ value "scale" props) `unspecified` vec3 1 1 1
358 362
359 -- Compute the object's vectors if a forward vector has been specified. 363 -- Compute the object's vectors if an up/forward vector has been specified.
360 let (right, up, forward) = vectors forward' 364 let (right, up) = vectors up'
361 365
362 newGO goType sceneRes props (M4.transform right up forward position) 366 newGO goType sceneRes props (M3.transform right up position)
363 367
364 368
365vectors :: Maybe Vector3 -> (Vector3, Vector3, Vector3) 369vectors :: Maybe Vector2 -> (Vector2, Vector2)
366vectors forward = case forward of 370vectors up = case up of
367 Nothing -> (V3.unitx, V3.unity, V3.unitz) 371 Nothing -> (V2.unitx, V2.unity)
368 Just f -> 372 Just u -> (perp u, u)
369 let r = f `cross` V3.unity
370 u = r `cross` f
371 in
372 (r, u, f)
373 373
374 374
375 375
@@ -408,10 +408,10 @@ asFloat :: Functor f => f [String] -> f Float
408asFloat = fmap (read . concat) 408asFloat = fmap (read . concat)
409 409
410 410
411asVec4 :: Functor f => f [String] -> f Vector4 411asVec2 :: Functor f => f [String] -> f Vector2
412asVec4 val = fmap toVec4 val 412asVec2 val = fmap toVec2 val
413 where toVec4 (x:y:z:w:_) = vec4 (read x) (read y) (read z) (read w) 413 where toVec2 (x:y:_) = vec2 (read x) (read y)
414 toVec4 (x:[]) = let x' = read x in vec4 x' x' x' x' 414 toVec2 (x:[]) = let x' = read x in vec2 x' x'
415 415
416 416
417asVec3 :: Functor f => f [String] -> f Vector3 417asVec3 :: Functor f => f [String] -> f Vector3
@@ -420,6 +420,12 @@ asVec3 val = fmap toVec3 val
420 toVec3 (x:[]) = let x' = read x in vec3 x' x' x' 420 toVec3 (x:[]) = let x' = read x in vec3 x' x' x'
421 421
422 422
423asVec4 :: Functor f => f [String] -> f Vector4
424asVec4 val = fmap toVec4 val
425 where toVec4 (x:y:z:w:_) = vec4 (read x) (read y) (read z) (read w)
426 toVec4 (x:[]) = let x' = read x in vec4 x' x' x' x'
427
428
423asRotation :: Functor f => f [String] -> f Rotation 429asRotation :: Functor f => f [String] -> f Rotation
424asRotation val = fmap parseRotation val 430asRotation val = fmap parseRotation val
425 where parseRotation (ax:ay:az:order:_) = Rotation (read ax) (read ay) (read az) (readOrder order) 431 where parseRotation (ax:ay:az:order:_) = Rotation (read ax) (read ay) (read az) (readOrder order)