From 62266b765bd3f3b4c3d669629d5847d929feb1e3 Mon Sep 17 00:00:00 2001 From: Marc Sunet Date: Fri, 31 Aug 2012 18:39:31 +0200 Subject: Added nextFrame; enhanced docs --- Spear.lkshw | 2 +- Spear/Render/AnimatedModel.hs | 58 +++++++++++++++++++++++++++---------------- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/Spear.lkshw b/Spear.lkshw index b9a1550..9220bd8 100644 --- a/Spear.lkshw +++ b/Spear.lkshw @@ -1,7 +1,7 @@ Version of workspace file format: 1 Time of storage: - "Fri Aug 31 12:09:58 CEST 2012" + "Fri Aug 31 18:36:39 CEST 2012" Name of the workspace: "Spear" File paths of contained packages: diff --git a/Spear/Render/AnimatedModel.hs b/Spear/Render/AnimatedModel.hs index 1703141..3fe12fd 100644 --- a/Spear/Render/AnimatedModel.hs +++ b/Spear/Render/AnimatedModel.hs @@ -8,14 +8,18 @@ module Spear.Render.AnimatedModel , animatedModelResource , animatedModelRenderer , Spear.Render.AnimatedModel.release + -- * Accessors +, animationSpeed +, box +, currentAnimation +, currentFrame +, frameProgress +, modelRes +, nextFrame -- * Manipulation , update , setAnimation -, currentAnimation -, animationSpeed , setAnimationSpeed -, box -, modelRes -- * Rendering , bind , render @@ -79,9 +83,9 @@ data AnimatedModelRenderer = AnimatedModelRenderer , currentAnim :: Int , frameStart :: Int , frameEnd :: Int - , currentFrame :: Int - , frameProgress :: Float - , animationSpeed :: Float + , currentFrame :: Int -- ^ Get the renderer's current frame. + , frameProgress :: Float -- ^ Get the renderer's frame progress. + , animationSpeed :: Float -- ^ Get the renderer's animation speed. } @@ -164,6 +168,31 @@ update dt (AnimatedModelRenderer model curAnim startFrame endFrame curFrame fp s else curFrame +-- | Get the model's ith bounding box. +box :: Int -> AnimatedModelResource -> Box +box i model = boxes model V.! i + + +-- | Get the renderer's current animation. +currentAnimation :: Enum a => AnimatedModelRenderer -> a +currentAnimation = toEnum . currentAnim + + +-- | Get the renderer's model resource. +modelRes :: AnimatedModelRenderer -> AnimatedModelResource +modelRes = modelResource + + +-- | Get the renderer's next frame. +nextFrame :: AnimatedModelRenderer -> Int +nextFrame rend = + let curFrame = currentFrame rend + in + if curFrame == frameEnd rend + then frameStart rend + else curFrame + 1 + + -- | Set the active animation to the given one. setAnimation :: Enum a => a -> AnimatedModelRenderer -> AnimatedModelRenderer setAnimation anim modelRend = @@ -173,26 +202,11 @@ setAnimation anim modelRend = modelRend { currentAnim = anim', frameStart = f1, frameEnd = f2, currentFrame = f1 } --- | Get the renderer's current animation. -currentAnimation :: Enum a => AnimatedModelRenderer -> a -currentAnimation = toEnum . currentAnim - - -- | Set the renderer's animation speed. setAnimationSpeed :: AnimationSpeed -> AnimatedModelRenderer -> AnimatedModelRenderer setAnimationSpeed s r = r { animationSpeed = s } --- | Get the model's ith bounding box. -box :: Int -> AnimatedModelResource -> Box -box i model = boxes model V.! i - - --- | Get the renderer's model resource. -modelRes :: AnimatedModelRenderer -> AnimatedModelResource -modelRes = modelResource - - -- | Bind the given 'AnimatedModelRenderer' to prepare it for rendering. bind :: AnimatedProgramUniforms -> AnimatedModelRenderer -> IO () bind (AnimatedProgramUniforms kaLoc kdLoc ksLoc shiLoc texLoc _ _ _ _) modelRend = -- cgit v1.2.3