diff options
| -rw-r--r-- | Spear.lkshw | 4 | ||||
| -rw-r--r-- | Spear/Scene/GameObject.hs | 9 | ||||
| -rw-r--r-- | Spear/Scene/Loader.hs | 64 |
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 @@ | |||
| 1 | Version of workspace file format: | 1 | Version of workspace file format: |
| 2 | 1 | 2 | 1 |
| 3 | Time of storage: | 3 | Time of storage: |
| 4 | "Wed Aug 29 16:58:18 CEST 2012" | 4 | "Wed Aug 29 17:13:01 CEST 2012" |
| 5 | Name of the workspace: | 5 | Name of the workspace: |
| 6 | "Spear" | 6 | "Spear" |
| 7 | File paths of contained packages: | 7 | File paths of contained packages: |
| 8 | ["demos/simple-scene/simple-scene.cabal","Spear.cabal"] | 8 | ["demos/simple-scene/simple-scene.cabal","Spear.cabal"] |
| 9 | Maybe file path of an active package: | 9 | Maybe 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 | |||
| 112 | goNew :: GameStyle | 112 | goNew :: GameStyle |
| 113 | -> Either StaticModelResource AnimatedModelResource | 113 | -> Either StaticModelResource AnimatedModelResource |
| 114 | -> Collisioner | 114 | -> Collisioner |
| 115 | -> M3.Matrix3 | ||
| 115 | -> GameObject | 116 | -> GameObject |
| 116 | 117 | ||
| 117 | goNew style (Left smr) col = | 118 | goNew 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 | ||
| 120 | goNew style (Right amr) col = | 121 | goNew 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 | ||
| 124 | goUpdate' :: GameStyle | 125 | goUpdate' :: 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 | |||
| 21 | import Spear.Assets.Model as Model | 21 | import Spear.Assets.Model as Model |
| 22 | import Spear.Collision.Collisioner | 22 | import Spear.Collision.Collisioner |
| 23 | import qualified Spear.GLSL as GLSL | 23 | import qualified Spear.GLSL as GLSL |
| 24 | import qualified Spear.Math.Matrix3 as M3 | 24 | import Spear.Math.Matrix3 as M3 |
| 25 | import Spear.Math.Matrix4 as M4 | 25 | import Spear.Math.Matrix4 as M4 |
| 26 | import Spear.Math.MatrixUtils (fastNormalMatrix) | 26 | import Spear.Math.MatrixUtils (fastNormalMatrix) |
| 27 | import Spear.Math.Vector2 as V2 | ||
| 27 | import Spear.Math.Vector3 as V3 | 28 | import Spear.Math.Vector3 as V3 |
| 28 | import Spear.Math.Vector4 | 29 | import Spear.Math.Vector4 as V4 |
| 29 | import Spear.Render.AnimatedModel as AM | 30 | import Spear.Render.AnimatedModel as AM |
| 30 | import Spear.Render.Material | 31 | import Spear.Render.Material |
| 31 | import Spear.Render.Program | 32 | import Spear.Render.Program |
| @@ -310,21 +311,25 @@ newLight _ = return () | |||
| 310 | -- Object Loading -- | 311 | -- Object Loading -- |
| 311 | -------------------- | 312 | -------------------- |
| 312 | 313 | ||
| 313 | loadGO :: GameStyle -> SceneResources -> [Property] -> Matrix4 -> Setup GameObject | 314 | loadGO :: GameStyle -> SceneResources -> [Property] -> Matrix3 -> Setup GameObject |
| 314 | loadGO style sceneRes props transf = do | 315 | loadGO 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 | ||
| 323 | type CreateGameObject m a | 328 | type 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 | |||
| 349 | newObject' newGO sceneRes nid props = do | 354 | newObject' 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 | ||
| 365 | vectors :: Maybe Vector3 -> (Vector3, Vector3, Vector3) | 369 | vectors :: Maybe Vector2 -> (Vector2, Vector2) |
| 366 | vectors forward = case forward of | 370 | vectors 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 | |||
| 408 | asFloat = fmap (read . concat) | 408 | asFloat = fmap (read . concat) |
| 409 | 409 | ||
| 410 | 410 | ||
| 411 | asVec4 :: Functor f => f [String] -> f Vector4 | 411 | asVec2 :: Functor f => f [String] -> f Vector2 |
| 412 | asVec4 val = fmap toVec4 val | 412 | asVec2 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 | ||
| 417 | asVec3 :: Functor f => f [String] -> f Vector3 | 417 | asVec3 :: 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 | ||
| 423 | asVec4 :: Functor f => f [String] -> f Vector4 | ||
| 424 | asVec4 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 | |||
| 423 | asRotation :: Functor f => f [String] -> f Rotation | 429 | asRotation :: Functor f => f [String] -> f Rotation |
| 424 | asRotation val = fmap parseRotation val | 430 | asRotation 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) |
