diff options
| author | Marc Sunet <jeannekamikaze@gmail.com> | 2012-08-31 18:39:31 +0200 | 
|---|---|---|
| committer | Marc Sunet <jeannekamikaze@gmail.com> | 2012-08-31 18:39:31 +0200 | 
| commit | 62266b765bd3f3b4c3d669629d5847d929feb1e3 (patch) | |
| tree | da3eb2eaf5eed270450da5136e059a0c247db6ae | |
| parent | 234d9ecad6ae2dd75af2f6954627f2547d4fe6bd (diff) | |
Added nextFrame; enhanced docs
| -rw-r--r-- | Spear.lkshw | 2 | ||||
| -rw-r--r-- | 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 @@ | |||
| 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 | "Fri Aug 31 12:09:58 CEST 2012" | 4 | "Fri Aug 31 18:36:39 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: | 
| 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 | |||
| 8 | , animatedModelResource | 8 | , animatedModelResource | 
| 9 | , animatedModelRenderer | 9 | , animatedModelRenderer | 
| 10 | , Spear.Render.AnimatedModel.release | 10 | , Spear.Render.AnimatedModel.release | 
| 11 | -- * Accessors | ||
| 12 | , animationSpeed | ||
| 13 | , box | ||
| 14 | , currentAnimation | ||
| 15 | , currentFrame | ||
| 16 | , frameProgress | ||
| 17 | , modelRes | ||
| 18 | , nextFrame | ||
| 11 | -- * Manipulation | 19 | -- * Manipulation | 
| 12 | , update | 20 | , update | 
| 13 | , setAnimation | 21 | , setAnimation | 
| 14 | , currentAnimation | ||
| 15 | , animationSpeed | ||
| 16 | , setAnimationSpeed | 22 | , setAnimationSpeed | 
| 17 | , box | ||
| 18 | , modelRes | ||
| 19 | -- * Rendering | 23 | -- * Rendering | 
| 20 | , bind | 24 | , bind | 
| 21 | , render | 25 | , render | 
| @@ -79,9 +83,9 @@ data AnimatedModelRenderer = AnimatedModelRenderer | |||
| 79 | , currentAnim :: Int | 83 | , currentAnim :: Int | 
| 80 | , frameStart :: Int | 84 | , frameStart :: Int | 
| 81 | , frameEnd :: Int | 85 | , frameEnd :: Int | 
| 82 | , currentFrame :: Int | 86 | , currentFrame :: Int -- ^ Get the renderer's current frame. | 
| 83 | , frameProgress :: Float | 87 | , frameProgress :: Float -- ^ Get the renderer's frame progress. | 
| 84 | , animationSpeed :: Float | 88 | , animationSpeed :: Float -- ^ Get the renderer's animation speed. | 
| 85 | } | 89 | } | 
| 86 | 90 | ||
| 87 | 91 | ||
| @@ -164,6 +168,31 @@ update dt (AnimatedModelRenderer model curAnim startFrame endFrame curFrame fp s | |||
| 164 | else curFrame | 168 | else curFrame | 
| 165 | 169 | ||
| 166 | 170 | ||
| 171 | -- | Get the model's ith bounding box. | ||
| 172 | box :: Int -> AnimatedModelResource -> Box | ||
| 173 | box i model = boxes model V.! i | ||
| 174 | |||
| 175 | |||
| 176 | -- | Get the renderer's current animation. | ||
| 177 | currentAnimation :: Enum a => AnimatedModelRenderer -> a | ||
| 178 | currentAnimation = toEnum . currentAnim | ||
| 179 | |||
| 180 | |||
| 181 | -- | Get the renderer's model resource. | ||
| 182 | modelRes :: AnimatedModelRenderer -> AnimatedModelResource | ||
| 183 | modelRes = modelResource | ||
| 184 | |||
| 185 | |||
| 186 | -- | Get the renderer's next frame. | ||
| 187 | nextFrame :: AnimatedModelRenderer -> Int | ||
| 188 | nextFrame rend = | ||
| 189 | let curFrame = currentFrame rend | ||
| 190 | in | ||
| 191 | if curFrame == frameEnd rend | ||
| 192 | then frameStart rend | ||
| 193 | else curFrame + 1 | ||
| 194 | |||
| 195 | |||
| 167 | -- | Set the active animation to the given one. | 196 | -- | Set the active animation to the given one. | 
| 168 | setAnimation :: Enum a => a -> AnimatedModelRenderer -> AnimatedModelRenderer | 197 | setAnimation :: Enum a => a -> AnimatedModelRenderer -> AnimatedModelRenderer | 
| 169 | setAnimation anim modelRend = | 198 | setAnimation anim modelRend = | 
| @@ -173,26 +202,11 @@ setAnimation anim modelRend = | |||
| 173 | modelRend { currentAnim = anim', frameStart = f1, frameEnd = f2, currentFrame = f1 } | 202 | modelRend { currentAnim = anim', frameStart = f1, frameEnd = f2, currentFrame = f1 } | 
| 174 | 203 | ||
| 175 | 204 | ||
| 176 | -- | Get the renderer's current animation. | ||
| 177 | currentAnimation :: Enum a => AnimatedModelRenderer -> a | ||
| 178 | currentAnimation = toEnum . currentAnim | ||
| 179 | |||
| 180 | |||
| 181 | -- | Set the renderer's animation speed. | 205 | -- | Set the renderer's animation speed. | 
| 182 | setAnimationSpeed :: AnimationSpeed -> AnimatedModelRenderer -> AnimatedModelRenderer | 206 | setAnimationSpeed :: AnimationSpeed -> AnimatedModelRenderer -> AnimatedModelRenderer | 
| 183 | setAnimationSpeed s r = r { animationSpeed = s } | 207 | setAnimationSpeed s r = r { animationSpeed = s } | 
| 184 | 208 | ||
| 185 | 209 | ||
| 186 | -- | Get the model's ith bounding box. | ||
| 187 | box :: Int -> AnimatedModelResource -> Box | ||
| 188 | box i model = boxes model V.! i | ||
| 189 | |||
| 190 | |||
| 191 | -- | Get the renderer's model resource. | ||
| 192 | modelRes :: AnimatedModelRenderer -> AnimatedModelResource | ||
| 193 | modelRes = modelResource | ||
| 194 | |||
| 195 | |||
| 196 | -- | Bind the given 'AnimatedModelRenderer' to prepare it for rendering. | 210 | -- | Bind the given 'AnimatedModelRenderer' to prepare it for rendering. | 
| 197 | bind :: AnimatedProgramUniforms -> AnimatedModelRenderer -> IO () | 211 | bind :: AnimatedProgramUniforms -> AnimatedModelRenderer -> IO () | 
| 198 | bind (AnimatedProgramUniforms kaLoc kdLoc ksLoc shiLoc texLoc _ _ _ _) modelRend = | 212 | bind (AnimatedProgramUniforms kaLoc kdLoc ksLoc shiLoc texLoc _ _ _ _) modelRend = | 
