aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Sunet <jeannekamikaze@gmail.com>2012-08-31 18:39:31 +0200
committerMarc Sunet <jeannekamikaze@gmail.com>2012-08-31 18:39:31 +0200
commit62266b765bd3f3b4c3d669629d5847d929feb1e3 (patch)
treeda3eb2eaf5eed270450da5136e059a0c247db6ae
parent234d9ecad6ae2dd75af2f6954627f2547d4fe6bd (diff)
Added nextFrame; enhanced docs
-rw-r--r--Spear.lkshw2
-rw-r--r--Spear/Render/AnimatedModel.hs58
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 @@
1Version of workspace file format: 1Version of workspace file format:
2 1 2 1
3Time of storage: 3Time of storage:
4 "Fri Aug 31 12:09:58 CEST 2012" 4 "Fri Aug 31 18:36:39 CEST 2012"
5Name of the workspace: 5Name of the workspace:
6 "Spear" 6 "Spear"
7File paths of contained packages: 7File 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.
172box :: Int -> AnimatedModelResource -> Box
173box i model = boxes model V.! i
174
175
176-- | Get the renderer's current animation.
177currentAnimation :: Enum a => AnimatedModelRenderer -> a
178currentAnimation = toEnum . currentAnim
179
180
181-- | Get the renderer's model resource.
182modelRes :: AnimatedModelRenderer -> AnimatedModelResource
183modelRes = modelResource
184
185
186-- | Get the renderer's next frame.
187nextFrame :: AnimatedModelRenderer -> Int
188nextFrame 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.
168setAnimation :: Enum a => a -> AnimatedModelRenderer -> AnimatedModelRenderer 197setAnimation :: Enum a => a -> AnimatedModelRenderer -> AnimatedModelRenderer
169setAnimation anim modelRend = 198setAnimation 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.
177currentAnimation :: Enum a => AnimatedModelRenderer -> a
178currentAnimation = toEnum . currentAnim
179
180
181-- | Set the renderer's animation speed. 205-- | Set the renderer's animation speed.
182setAnimationSpeed :: AnimationSpeed -> AnimatedModelRenderer -> AnimatedModelRenderer 206setAnimationSpeed :: AnimationSpeed -> AnimatedModelRenderer -> AnimatedModelRenderer
183setAnimationSpeed s r = r { animationSpeed = s } 207setAnimationSpeed s r = r { animationSpeed = s }
184 208
185 209
186-- | Get the model's ith bounding box.
187box :: Int -> AnimatedModelResource -> Box
188box i model = boxes model V.! i
189
190
191-- | Get the renderer's model resource.
192modelRes :: AnimatedModelRenderer -> AnimatedModelResource
193modelRes = modelResource
194
195
196-- | Bind the given 'AnimatedModelRenderer' to prepare it for rendering. 210-- | Bind the given 'AnimatedModelRenderer' to prepare it for rendering.
197bind :: AnimatedProgramUniforms -> AnimatedModelRenderer -> IO () 211bind :: AnimatedProgramUniforms -> AnimatedModelRenderer -> IO ()
198bind (AnimatedProgramUniforms kaLoc kdLoc ksLoc shiLoc texLoc _ _ _ _) modelRend = 212bind (AnimatedProgramUniforms kaLoc kdLoc ksLoc shiLoc texLoc _ _ _ _) modelRend =