From 6458d34bcbf2efc0cc2b8dac8a1b70f31148f646 Mon Sep 17 00:00:00 2001 From: Marc Sunet Date: Wed, 29 Aug 2012 18:04:31 +0200 Subject: Added animation speed to AnimatedModelRenderer --- Spear.lkshs | 10 +++++----- Spear.lkshw | 4 ++-- Spear/Render/AnimatedModel.hs | 35 ++++++++++++++++++++++++----------- Spear/Scene/GameObject.hs | 2 +- 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/Spear.lkshs b/Spear.lkshs index 946985e..f2dd70a 100644 --- a/Spear.lkshs +++ b/Spear.lkshs @@ -1,18 +1,18 @@ Version of session file format: 1 Time of storage: - "Wed Aug 29 15:21:06 CEST 2012" -Layout: 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}) 312) 201)], paneTabs = Just BottomP, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 704) 954 -Population: [(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/AnimatedGO.hs" 605)),[SplitP LeftP]),(Just (ErrorsSt ErrorsState),[SplitP RightP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Factory.hs" 1165)),[SplitP LeftP]),(Just (FilesSt FilesState),[SplitP RightP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Scene/GameObject.hs" 86)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject.hs" 61)),[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/App/Input.hs" 5198)),[SplitP LeftP]),(Just (LogSt LogState),[SplitP RightP,SplitP BottomP]),(Just (ModulesSt (ModulesState 328 (PackageScope False,False) (Just (ModuleName ["Spear","App","Input"]),Nothing) (ExpanderState {packageExp = ([],[]), packageExpNoBlack = ([[0,0],[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" 210)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/StaticGO.hs" 496)),[SplitP LeftP]),(Just (WorkspaceSt WorkspaceState),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP TopP])] + "Wed Aug 29 17:33:27 CEST 2012" +Layout: VerticalP (TerminalP {paneGroups = fromList [], paneTabs = Just TopP, currentPage = 2, 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}) 286) 184)], paneTabs = Just BottomP, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 653) 954 +Population: [(Just (ErrorsSt ErrorsState),[SplitP RightP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Factory.hs" 359)),[SplitP LeftP]),(Just (FilesSt FilesState),[SplitP RightP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Scene/GameObject.hs" 3133)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject.hs" 846)),[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" 11796)),[SplitP LeftP]),(Just (LogSt LogState),[SplitP RightP,SplitP BottomP]),(Just (ModulesSt (ModulesState 328 (PackageScope False,False) (Just (ModuleName ["Game","GameObject","Player"]),Nothing) (ExpanderState {packageExp = ([],[]), packageExpNoBlack = ([[0,1],[0,0],[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" 0)),[SplitP LeftP]),(Just (WorkspaceSt WorkspaceState),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/main.hs" 886)),[SplitP LeftP])] Window size: (1820,939) Completion size: (750,399) Workspace: Just "/home/jeanne/programming/haskell/Spear/Spear.lkshw" -Active pane: Just "Factory.hs" +Active pane: Just "GameObject.hs(1)" Toolbar visible: True FindbarState: (False,FindState {entryStr = "asdad", entryHist = ["asdad","translv","Vector3.","Vector.","copy_tr","asad","Octree","idxs","elemIndexa","elemtIn","splitAt","allocaBytes"], replaceStr = "V3.", replaceHist = [], caseSensitive = True, entireWord = False, wrapAround = False, regex = False, lineNr = 1}) Recently opened files: - ["/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Player.hs","/home/jeanne/programming/haskell/Spear/Spear/Scene/Scene.hs","/home/jeanne/programming/haskell/Spear/Spear/Render/AnimatedModel.hs","/home/jeanne/programming/haskell/Spear/Spear/Render/StaticModel.hs","/home/jeanne/programming/haskell/Spear/Spear/Collision/Collisioner.hs","/home/jeanne/programming/haskell/Spear/Spear/Math/Circle.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameState.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Render.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/main.hs","/home/jeanne/programming/haskell/Spear/Spear/Math/MatrixUtils.hs","/home/jeanne/programming/haskell/Spear/Spear/Scene/Loader.hs","/home/jeanne/programming/haskell/Spear/Spear/Math/Matrix3.hs"] + ["/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Factory.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameState.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/main.hs","/home/jeanne/programming/haskell/Spear/Spear/Assets/Model/Model.c","/home/jeanne/programming/haskell/Spear/Spear/Assets/Model/Model.h","/home/jeanne/programming/haskell/Spear/Spear/Assets/Model.hsc","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/AnimatedGO.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/StaticGO.hs","/home/jeanne/programming/haskell/Spear/Spear/App/Input.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Player.hs","/home/jeanne/programming/haskell/Spear/Spear/Scene/Scene.hs"] Recently opened workspaces: ["/home/jeanne/programming/haskell/hagen/hagen.lkshw","/home/jeanne/programming/haskell/foo/foo.lkshw","/home/jeanne/programming/haskell/Spear/Spear.lkshw","/home/jeanne/programming/haskell/nexus/nexus.lkshw","/home/jeanne/leksah.lkshw"] \ No newline at end of file diff --git a/Spear.lkshw b/Spear.lkshw index 128fcfd..b7737af 100644 --- a/Spear.lkshw +++ b/Spear.lkshw @@ -1,10 +1,10 @@ Version of workspace file format: 1 Time of storage: - "Wed Aug 29 17:13:01 CEST 2012" + "Wed Aug 29 17:58:31 CEST 2012" Name of the workspace: "Spear" File paths of contained packages: ["demos/simple-scene/simple-scene.cabal","Spear.cabal"] Maybe file path of an active package: - Just "demos/simple-scene/simple-scene.cabal" \ No newline at end of file + Just "Spear.cabal" \ No newline at end of file diff --git a/Spear/Render/AnimatedModel.hs b/Spear/Render/AnimatedModel.hs index bdeb916..6e3c535 100644 --- a/Spear/Render/AnimatedModel.hs +++ b/Spear/Render/AnimatedModel.hs @@ -2,11 +2,14 @@ module Spear.Render.AnimatedModel ( AnimatedModelResource , AnimatedModelRenderer +, AnimationSpeed , animatedModelResource , animatedModelRenderer , Spear.Render.AnimatedModel.release , setAnimation , currentAnimation +, animationSpeed +, setAnimationSpeed , bind , render , update @@ -30,6 +33,9 @@ import Graphics.Rendering.OpenGL.Raw.Core31 import Unsafe.Coerce (unsafeCoerce) +type AnimationSpeed = Float + + -- | An animated model resource. -- -- Contains model data necessary to render an animated model. @@ -64,12 +70,13 @@ instance Ord AnimatedModelResource where -- state changes by sorting 'AnimatedModelRenderer's by their underlying -- 'AnimatedModelResource' when rendering the scene. data AnimatedModelRenderer = AnimatedModelRenderer - { modelResource :: AnimatedModelResource - , currentAnim :: Int - , frameStart :: Int - , frameEnd :: Int - , currentFrame :: Int - , frameProgress :: Float + { modelResource :: AnimatedModelResource + , currentAnim :: Int + , frameStart :: Int + , frameEnd :: Int + , currentFrame :: Int + , frameProgress :: Float + , animationSpeed :: Float } @@ -135,13 +142,14 @@ release = Setup.release . rkey -- | Create an 'AnimatedModelRenderer' from the given 'AnimatedModelResource'. -animatedModelRenderer :: AnimatedModelResource -> AnimatedModelRenderer -animatedModelRenderer modelResource = AnimatedModelRenderer modelResource 0 0 0 0 0 +animatedModelRenderer :: AnimationSpeed -> AnimatedModelResource -> AnimatedModelRenderer +animatedModelRenderer animSpeed modelResource = + AnimatedModelRenderer modelResource 0 0 0 0 0 animSpeed -- | Update the 'AnimatedModelRenderer'. -update dt (AnimatedModelRenderer model curAnim startFrame endFrame curFrame fp) = - AnimatedModelRenderer model curAnim startFrame endFrame curFrame' fp' +update dt (AnimatedModelRenderer model curAnim startFrame endFrame curFrame fp s) = + AnimatedModelRenderer model curAnim startFrame endFrame curFrame' fp' s where f = fp + dt nextFrame = f >= 1.0 fp' = if nextFrame then f - 1.0 else f @@ -166,6 +174,11 @@ currentAnimation :: Enum a => AnimatedModelRenderer -> a currentAnimation = toEnum . currentAnim +-- | Set the renderer's animation speed. +setAnimationSpeed :: AnimationSpeed -> AnimatedModelRenderer -> AnimatedModelRenderer +setAnimationSpeed s r = r { animationSpeed = s } + + -- | Bind the given 'AnimatedModelRenderer' to prepare it for rendering. bind :: AnimatedProgramUniforms -> AnimatedModelRenderer -> IO () bind (AnimatedProgramUniforms kaLoc kdLoc ksLoc shiLoc texLoc _ _ _ _) modelRend = @@ -179,7 +192,7 @@ bind (AnimatedProgramUniforms kaLoc kdLoc ksLoc shiLoc texLoc _ _ _ _) modelRend -- | Render the model described by the given 'AnimatedModelRenderer'. render :: AnimatedProgramUniforms -> AnimatedModelRenderer -> IO () -render uniforms (AnimatedModelRenderer model _ _ _ curFrame fp) = +render uniforms (AnimatedModelRenderer model _ _ _ curFrame fp _) = let n = nVertices model (Material _ ka kd ks shi) = material model in do diff --git a/Spear/Scene/GameObject.hs b/Spear/Scene/GameObject.hs index 9f4d950..2efadf0 100644 --- a/Spear/Scene/GameObject.hs +++ b/Spear/Scene/GameObject.hs @@ -119,7 +119,7 @@ goNew style (Left smr) col transf = goUpdate' style (Left $ SM.staticModelRenderer smr) col transf 0 goNew style (Right amr) col transf = - goUpdate' style (Right $ AM.animatedModelRenderer amr) col transf 0 + goUpdate' style (Right $ AM.animatedModelRenderer 1 amr) col transf 0 goUpdate' :: GameStyle -- cgit v1.2.3