diff options
-rw-r--r-- | Spear.lkshs | 6 | ||||
-rw-r--r-- | Spear.lkshw | 4 | ||||
-rw-r--r-- | Spear/Math/MatrixUtils.hs | 26 | ||||
-rw-r--r-- | Spear/Scene/GameObject.hs | 81 | ||||
-rw-r--r-- | Spear/Scene/Loader.hs | 17 |
5 files changed, 59 insertions, 75 deletions
diff --git a/Spear.lkshs b/Spear.lkshs index 4b0d469..3e07004 100644 --- a/Spear.lkshs +++ b/Spear.lkshs | |||
@@ -1,14 +1,14 @@ | |||
1 | Version of session file format: | 1 | Version of session file format: |
2 | 1 | 2 | 1 |
3 | Time of storage: | 3 | Time of storage: |
4 | "Fri Aug 31 22:25:44 CEST 2012" | 4 | "Sat Sep 1 10:54:22 CEST 2012" |
5 | 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}) 302) 217),("Debug",HorizontalP (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Just TopP, currentPage = 1, detachedId = Nothing, detachedSize = Nothing}) 256)], paneTabs = Just BottomP, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 663) 954 | 5 | 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}) 327) 235),("Debug",HorizontalP (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Just TopP, currentPage = 1, detachedId = Nothing, detachedSize = Nothing}) 277)], paneTabs = Just BottomP, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 714) 954 |
6 | Population: [(Just (BreakpointsSt BreakpointsState),[SplitP RightP,SplitP TopP,GroupP "Debug",SplitP BottomP]),(Just (ErrorsSt ErrorsState),[SplitP RightP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Factory.hs" 1205)),[SplitP LeftP]),(Just (FilesSt FilesState),[SplitP RightP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Scene/GameObject.hs" 3114)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject.hs" 1432)),[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" 17178)),[SplitP LeftP]),(Just (LogSt LogState),[SplitP RightP,SplitP BottomP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Math/MatrixUtils.hs" 1235)),[SplitP LeftP]),(Just (ModulesSt (ModulesState 328 (PackageScope False,False) (Nothing,Nothing) (ExpanderState {packageExp = ([],[]), packageExpNoBlack = ([[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" 2249)),[SplitP LeftP]),(Just (SearchSt (SearchState {searchString = "putStrLn", searchScope = PackageScope False, searchMode = Prefix {caseSense = False}})),[SplitP RightP,SplitP TopP]),(Just (TraceSt TraceState),[SplitP RightP,SplitP TopP,GroupP "Debug",SplitP BottomP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Utils.hs" 587)),[SplitP LeftP]),(Just (VariablesSt VariablesState),[SplitP RightP,SplitP TopP,GroupP "Debug",SplitP BottomP]),(Just (WorkspaceSt WorkspaceState),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP TopP]),(Just (BufferSt (BufferStateTrans "_Eval.hs" "\n" 0)),[SplitP RightP,SplitP TopP,GroupP "Debug",SplitP TopP])] | 6 | Population: [(Just (BreakpointsSt BreakpointsState),[SplitP RightP,SplitP TopP,GroupP "Debug",SplitP BottomP]),(Just (ErrorsSt ErrorsState),[SplitP RightP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Factory.hs" 1205)),[SplitP LeftP]),(Just (FilesSt FilesState),[SplitP RightP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Scene/GameObject.hs" 3114)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject.hs" 1432)),[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" 17178)),[SplitP LeftP]),(Just (LogSt LogState),[SplitP RightP,SplitP BottomP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Math/MatrixUtils.hs" 1235)),[SplitP LeftP]),(Just (ModulesSt (ModulesState 328 (PackageScope False,False) (Nothing,Nothing) (ExpanderState {packageExp = ([],[]), packageExpNoBlack = ([[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" 2249)),[SplitP LeftP]),(Just (SearchSt (SearchState {searchString = "putStrLn", searchScope = PackageScope False, searchMode = Prefix {caseSense = False}})),[SplitP RightP,SplitP TopP]),(Just (TraceSt TraceState),[SplitP RightP,SplitP TopP,GroupP "Debug",SplitP BottomP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Utils.hs" 587)),[SplitP LeftP]),(Just (VariablesSt VariablesState),[SplitP RightP,SplitP TopP,GroupP "Debug",SplitP BottomP]),(Just (WorkspaceSt WorkspaceState),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP TopP]),(Just (BufferSt (BufferStateTrans "_Eval.hs" "\n" 0)),[SplitP RightP,SplitP TopP,GroupP "Debug",SplitP TopP])] |
7 | Window size: (1820,944) | 7 | Window size: (1820,944) |
8 | Completion size: | 8 | Completion size: |
9 | (750,399) | 9 | (750,399) |
10 | Workspace: Just "/home/jeanne/programming/haskell/Spear/Spear.lkshw" | 10 | Workspace: Just "/home/jeanne/programming/haskell/Spear/Spear.lkshw" |
11 | Active pane: Just "GameObject.hs" | 11 | Active pane: Just "Modules" |
12 | Toolbar visible: | 12 | Toolbar visible: |
13 | True | 13 | True |
14 | FindbarState: (False,FindState {entryStr = "986", entryHist = ["986","drawElements","56","drawArray","drawVA","f","SV","VAO","'VAO'","\170","\\","^"], replaceStr = "V3.", replaceHist = [], caseSensitive = True, entireWord = False, wrapAround = False, regex = False, lineNr = 1}) | 14 | FindbarState: (False,FindState {entryStr = "986", entryHist = ["986","drawElements","56","drawArray","drawVA","f","SV","VAO","'VAO'","\170","\\","^"], replaceStr = "V3.", replaceHist = [], caseSensitive = True, entireWord = False, wrapAround = False, regex = False, lineNr = 1}) |
diff --git a/Spear.lkshw b/Spear.lkshw index 79c18ef..ff27127 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 | "Fri Aug 31 20:53:49 CEST 2012" | 4 | "Sat Sep 1 11:10:35 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 "demos/simple-scene/simple-scene.cabal" \ No newline at end of file | 10 | Just "Spear.cabal" \ No newline at end of file |
diff --git a/Spear/Math/MatrixUtils.hs b/Spear/Math/MatrixUtils.hs index 2c1d083..dcc1965 100644 --- a/Spear/Math/MatrixUtils.hs +++ b/Spear/Math/MatrixUtils.hs | |||
@@ -1,7 +1,6 @@ | |||
1 | module Spear.Math.MatrixUtils | 1 | module Spear.Math.MatrixUtils |
2 | ( | 2 | ( |
3 | Rotation(..) | 3 | fastNormalMatrix |
4 | , fastNormalMatrix | ||
5 | , rpgTransform | 4 | , rpgTransform |
6 | , pltTransform | 5 | , pltTransform |
7 | , rpgInverse | 6 | , rpgInverse |
@@ -16,9 +15,6 @@ import Spear.Math.Vector2 as V2 | |||
16 | import Spear.Math.Vector3 as V3 | 15 | import Spear.Math.Vector3 as V3 |
17 | 16 | ||
18 | 17 | ||
19 | data Rotation = Yaw | Pitch | Roll deriving Eq | ||
20 | |||
21 | |||
22 | -- | Compute the normal matrix of the given matrix. | 18 | -- | Compute the normal matrix of the given matrix. |
23 | fastNormalMatrix :: Matrix4 -> Matrix3 | 19 | fastNormalMatrix :: Matrix4 -> Matrix3 |
24 | fastNormalMatrix m = | 20 | fastNormalMatrix m = |
@@ -31,21 +27,17 @@ fastNormalMatrix m = | |||
31 | 27 | ||
32 | -- | Maps the given 2D transformation matrix to a 3D transformation matrix. | 28 | -- | Maps the given 2D transformation matrix to a 3D transformation matrix. |
33 | rpgTransform | 29 | rpgTransform |
34 | :: Float -- ^ The height above the ground. | 30 | :: Float -- ^ The height above the ground |
35 | -> Float -- ^ Angle of rotation. | 31 | -> Float -- ^ Angle of rotation |
36 | -> Rotation -- ^ How the 2D rotation should be interpreted in 3D. | 32 | -> Vector3 -- ^ Axis of rotation |
37 | -> Matrix3 | 33 | -> Matrix3 |
38 | -> Matrix4 | 34 | -> Matrix4 |
39 | rpgTransform h a rtype mat = | 35 | rpgTransform h a axis mat = |
40 | {-let r = let r' = M3.right mat in vec3 (V2.x r') (V2.y r') 0 | 36 | {-let r = let r' = M3.right mat in vec3 (V2.x r') (V2.y r') 0 |
41 | u = V3.unity | 37 | u = V3.unity |
42 | f = let f' = M3.forward mat in vec3 (V2.x f') 0 (V2.y f') | 38 | f = let f' = M3.forward mat in vec3 (V2.x f') 0 (V2.y f') |
43 | t = (vec3 0 h 0) + let t' = M3.position mat in vec3 (V2.x t') 0 (V2.y t')-} | 39 | t = (vec3 0 h 0) + let t' = M3.position mat in vec3 (V2.x t') 0 (V2.y t')-} |
44 | let rot = case rtype of | 40 | let mat' = axisAngle axis a |
45 | Yaw -> rotY | ||
46 | Pitch -> rotX | ||
47 | Roll -> rotZ | ||
48 | mat' = rot a | ||
49 | r = M4.right mat' | 41 | r = M4.right mat' |
50 | u = M4.up mat' | 42 | u = M4.up mat' |
51 | f = M4.forward mat' | 43 | f = M4.forward mat' |
@@ -79,9 +71,9 @@ pltTransform mat = | |||
79 | -- | 71 | -- |
80 | -- Use this in games such as RPGs and RTSs. | 72 | -- Use this in games such as RPGs and RTSs. |
81 | rpgInverse | 73 | rpgInverse |
82 | :: Float -- ^ The height above the ground. | 74 | :: Float -- ^ The height above the ground |
83 | -> Float -- ^ Angle of rotation. | 75 | -> Float -- ^ Angle of rotation |
84 | -> Rotation -- ^ How the 2D rotation should be interpreted in 3D. | 76 | -> Vector3 -- ^ Axis of rotation |
85 | -> Matrix3 | 77 | -> Matrix3 |
86 | -> Matrix4 | 78 | -> Matrix4 |
87 | rpgInverse h a rot = M4.inverseTransform . rpgTransform h a rot | 79 | rpgInverse h a rot = M4.inverseTransform . rpgTransform h a rot |
diff --git a/Spear/Scene/GameObject.hs b/Spear/Scene/GameObject.hs index f29ee09..d3b4e9e 100644 --- a/Spear/Scene/GameObject.hs +++ b/Spear/Scene/GameObject.hs | |||
@@ -3,7 +3,6 @@ module Spear.Scene.GameObject | |||
3 | GameObject | 3 | GameObject |
4 | , GameStyle(..) | 4 | , GameStyle(..) |
5 | , AM.AnimationSpeed | 5 | , AM.AnimationSpeed |
6 | , Rotation(..) | ||
7 | -- * Construction | 6 | -- * Construction |
8 | , goNew | 7 | , goNew |
9 | -- * Accessors | 8 | -- * Accessors |
@@ -54,10 +53,10 @@ data GameStyle | |||
54 | -- | An object in the game scene. | 53 | -- | An object in the game scene. |
55 | data GameObject = GameObject | 54 | data GameObject = GameObject |
56 | { gameStyle :: !GameStyle | 55 | { gameStyle :: !GameStyle |
57 | , rotation :: !Rotation | ||
58 | , renderer :: !(Either StaticModelRenderer AM.AnimatedModelRenderer) | 56 | , renderer :: !(Either StaticModelRenderer AM.AnimatedModelRenderer) |
59 | , collisioners :: ![Collisioner] | 57 | , collisioners :: ![Collisioner] |
60 | , transform :: !M3.Matrix3 | 58 | , transform :: !M3.Matrix3 |
59 | , axis :: Vector3 | ||
61 | , angle :: Float | 60 | , angle :: Float |
62 | } | 61 | } |
63 | 62 | ||
@@ -136,17 +135,17 @@ instance S2.Spatial2 GameObject where | |||
136 | 135 | ||
137 | -- | Create a new game object. | 136 | -- | Create a new game object. |
138 | goNew :: GameStyle | 137 | goNew :: GameStyle |
139 | -> Rotation | ||
140 | -> Either StaticModelResource AM.AnimatedModelResource | 138 | -> Either StaticModelResource AM.AnimatedModelResource |
141 | -> [Collisioner] | 139 | -> [Collisioner] |
142 | -> M3.Matrix3 | 140 | -> M3.Matrix3 -- ^ Transform |
141 | -> Vector3 -- ^ Axis of rotation | ||
143 | -> GameObject | 142 | -> GameObject |
144 | 143 | ||
145 | goNew style rtype (Left smr) cols transf = | 144 | goNew style (Left smr) cols transf axis = |
146 | GameObject style rtype (Left $ SM.staticModelRenderer smr) cols transf 0 | 145 | GameObject style (Left $ SM.staticModelRenderer smr) cols transf axis 0 |
147 | 146 | ||
148 | goNew style rtype (Right amr) cols transf = | 147 | goNew style (Right amr) cols transf axis = |
149 | GameObject style rtype (Right $ AM.animatedModelRenderer 1 amr) cols transf 0 | 148 | GameObject style (Right $ AM.animatedModelRenderer 1 amr) cols transf axis 0 |
150 | 149 | ||
151 | 150 | ||
152 | goUpdate :: Float -> GameObject -> GameObject | 151 | goUpdate :: Float -> GameObject -> GameObject |
@@ -160,6 +159,25 @@ goUpdate dt go = | |||
160 | } | 159 | } |
161 | 160 | ||
162 | 161 | ||
162 | -- | Get the game object's ith bounding box. | ||
163 | goAABB :: Int -> GameObject -> AABB | ||
164 | goAABB i go = goAABB' $ (collisioners go) !! i | ||
165 | |||
166 | goAABB' col = case col of | ||
167 | (AABBCol box) -> box | ||
168 | (CircleCol circle) -> aabbFromCircle circle | ||
169 | |||
170 | |||
171 | -- | Get the game object's bounding boxes. | ||
172 | goAABBs :: GameObject -> [AABB] | ||
173 | goAABBs = fmap goAABB' . collisioners | ||
174 | |||
175 | |||
176 | -- | Get the game object's 3D transform. | ||
177 | go3Dtransform :: GameObject -> M4.Matrix4 | ||
178 | go3Dtransform go = rpgTransform 0 (angle go) (axis go) . S2.transform $ go | ||
179 | |||
180 | |||
163 | -- | Get the game object's current animation. | 181 | -- | Get the game object's current animation. |
164 | currentAnimation :: Enum a => GameObject -> a | 182 | currentAnimation :: Enum a => GameObject -> a |
165 | currentAnimation go = case renderer go of | 183 | currentAnimation go = case renderer go of |
@@ -167,6 +185,11 @@ currentAnimation go = case renderer go of | |||
167 | Right amr -> AM.currentAnimation amr | 185 | Right amr -> AM.currentAnimation amr |
168 | 186 | ||
169 | 187 | ||
188 | -- | Return the game object's number of collisioners. | ||
189 | numCollisioners :: GameObject -> Int | ||
190 | numCollisioners = length . collisioners | ||
191 | |||
192 | |||
170 | -- | Set the game object's current animation. | 193 | -- | Set the game object's current animation. |
171 | setAnimation :: Enum a => a -> GameObject -> GameObject | 194 | setAnimation :: Enum a => a -> GameObject -> GameObject |
172 | setAnimation a go = case renderer go of | 195 | setAnimation a go = case renderer go of |
@@ -181,38 +204,14 @@ setAnimationSpeed s go = case renderer go of | |||
181 | Right amr -> go { renderer = Right $ AM.setAnimationSpeed s amr } | 204 | Right amr -> go { renderer = Right $ AM.setAnimationSpeed s amr } |
182 | 205 | ||
183 | 206 | ||
184 | -- | Return the game object's number of collisioners. | ||
185 | numCollisioners :: GameObject -> Int | ||
186 | numCollisioners = length . collisioners | ||
187 | |||
188 | |||
189 | -- | Manipulate the game object's collisioners. | ||
190 | withCollisioners :: GameObject -> ([Collisioner] -> [Collisioner]) -> GameObject | ||
191 | withCollisioners go f = go { collisioners = f $ collisioners go } | ||
192 | |||
193 | |||
194 | -- | Set the game object's collisioners. | 207 | -- | Set the game object's collisioners. |
195 | setCollisioners :: GameObject -> [Collisioner] -> GameObject | 208 | setCollisioners :: GameObject -> [Collisioner] -> GameObject |
196 | setCollisioners go cols = go { collisioners = cols } | 209 | setCollisioners go cols = go { collisioners = cols } |
197 | 210 | ||
198 | 211 | ||
199 | -- | Get the game object's ith bounding box. | 212 | -- | Manipulate the game object's collisioners. |
200 | goAABB :: Int -> GameObject -> AABB | 213 | withCollisioners :: GameObject -> ([Collisioner] -> [Collisioner]) -> GameObject |
201 | goAABB i go = goAABB' $ (collisioners go) !! i | 214 | withCollisioners go f = go { collisioners = f $ collisioners go } |
202 | |||
203 | goAABB' col = case col of | ||
204 | (AABBCol box) -> box | ||
205 | (CircleCol circle) -> aabbFromCircle circle | ||
206 | |||
207 | |||
208 | -- | Get the game object's bounding boxes. | ||
209 | goAABBs :: GameObject -> [AABB] | ||
210 | goAABBs = fmap goAABB' . collisioners | ||
211 | |||
212 | |||
213 | -- | Get the game object's 3D transform. | ||
214 | go3Dtransform :: GameObject -> M4.Matrix4 | ||
215 | go3Dtransform go = rpgTransform 0 (angle go) (rotation go) . S2.transform $ go | ||
216 | 215 | ||
217 | 216 | ||
218 | -- | Render the game object. | 217 | -- | Render the game object. |
@@ -222,13 +221,13 @@ goRender sprog aprog cam go = | |||
222 | apu = animatedProgramUniforms aprog | 221 | apu = animatedProgramUniforms aprog |
223 | mat = S2.transform go | 222 | mat = S2.transform go |
224 | style = gameStyle go | 223 | style = gameStyle go |
225 | rtype = rotation go | 224 | axis' = axis go |
226 | a = angle go | 225 | a = angle go |
227 | in case renderer go of | 226 | in case renderer go of |
228 | Left smr -> | 227 | Left smr -> |
229 | goRender' style a rtype sprog spu mat cam (SM.bind spu smr) (SM.render spu smr) | 228 | goRender' style a axis' sprog spu mat cam (SM.bind spu smr) (SM.render spu smr) |
230 | Right amr -> | 229 | Right amr -> |
231 | goRender' style a rtype aprog apu mat cam (AM.bind apu amr) (AM.render apu amr) | 230 | goRender' style a axis' aprog apu mat cam (AM.bind apu amr) (AM.render apu amr) |
232 | 231 | ||
233 | 232 | ||
234 | type Bind = IO () | 233 | type Bind = IO () |
@@ -239,7 +238,7 @@ type Render = IO () | |||
239 | goRender' :: (ProgramUniforms u, Program p) | 238 | goRender' :: (ProgramUniforms u, Program p) |
240 | => GameStyle | 239 | => GameStyle |
241 | -> Float | 240 | -> Float |
242 | -> Rotation | 241 | -> Vector3 |
243 | -> p | 242 | -> p |
244 | -> u | 243 | -> u |
245 | -> M3.Matrix3 | 244 | -> M3.Matrix3 |
@@ -247,10 +246,10 @@ goRender' :: (ProgramUniforms u, Program p) | |||
247 | -> Bind | 246 | -> Bind |
248 | -> Render | 247 | -> Render |
249 | -> IO () | 248 | -> IO () |
250 | goRender' style a rtype prog uniforms model cam bindRenderer render = | 249 | goRender' style a axis prog uniforms model cam bindRenderer render = |
251 | let view = M4.inverseTransform $ Cam.transform cam | 250 | let view = M4.inverseTransform $ Cam.transform cam |
252 | modelview = case style of | 251 | modelview = case style of |
253 | RPG -> view * rpgTransform 0 a rtype model | 252 | RPG -> view * rpgTransform 0 a axis model |
254 | PLT -> view * pltTransform model | 253 | PLT -> view * pltTransform model |
255 | normalmat = fastNormalMatrix modelview | 254 | normalmat = fastNormalMatrix modelview |
256 | in do | 255 | in do |
diff --git a/Spear/Scene/Loader.hs b/Spear/Scene/Loader.hs index ea08385..f5d06a6 100644 --- a/Spear/Scene/Loader.hs +++ b/Spear/Scene/Loader.hs | |||
@@ -31,7 +31,7 @@ import Spear.Render.AnimatedModel as AM | |||
31 | import Spear.Render.Material | 31 | import Spear.Render.Material |
32 | import Spear.Render.Program | 32 | import Spear.Render.Program |
33 | import Spear.Render.StaticModel as SM | 33 | import Spear.Render.StaticModel as SM |
34 | import qualified Spear.Scene.GameObject as GO | 34 | import Spear.Scene.GameObject as GO |
35 | import Spear.Scene.Graph | 35 | import Spear.Scene.Graph |
36 | import Spear.Scene.Light | 36 | import Spear.Scene.Light |
37 | import Spear.Scene.SceneResources | 37 | import Spear.Scene.SceneResources |
@@ -342,18 +342,18 @@ newLight _ = return () | |||
342 | -- Object Loading -- | 342 | -- Object Loading -- |
343 | -------------------- | 343 | -------------------- |
344 | 344 | ||
345 | loadGO :: GO.GameStyle -> SceneResources -> [Property] -> Matrix3 -> Setup GO.GameObject | 345 | loadGO :: GameStyle -> SceneResources -> [Property] -> Matrix3 -> Setup GameObject |
346 | loadGO style sceneRes props transf = do | 346 | loadGO style sceneRes props transf = do |
347 | modelName <- asString . mandatory "model" $ props | 347 | modelName <- asString . mandatory "model" $ props |
348 | rtype <- asGORotation . mandatory "rotation" $ props | 348 | axis <- asVec3 . mandatory "axis" $ props |
349 | let animSpeed = asFloat . value "animation-speed" $ props | 349 | let animSpeed = asFloat . value "animation-speed" $ props |
350 | go <- case getAnimatedModel sceneRes modelName of | 350 | go <- case getAnimatedModel sceneRes modelName of |
351 | Just model -> | 351 | Just model -> |
352 | return $ GO.goNew style rtype (Right model) [] transf | 352 | return $ goNew style (Right model) [] transf axis |
353 | Nothing -> | 353 | Nothing -> |
354 | case getStaticModel sceneRes modelName of | 354 | case getStaticModel sceneRes modelName of |
355 | Just model -> | 355 | Just model -> |
356 | return $ GO.goNew style rtype (Left model) [] transf | 356 | return $ goNew style (Left model) [] transf axis |
357 | Nothing -> | 357 | Nothing -> |
358 | setupError $ "model " ++ modelName ++ " not found" | 358 | setupError $ "model " ++ modelName ++ " not found" |
359 | return $ case animSpeed of | 359 | return $ case animSpeed of |
@@ -467,13 +467,6 @@ asRotation val = fmap parseRotation val | |||
467 | where parseRotation (ax:ay:az:order:_) = Rotation (read ax) (read ay) (read az) (readOrder order) | 467 | where parseRotation (ax:ay:az:order:_) = Rotation (read ax) (read ay) (read az) (readOrder order) |
468 | 468 | ||
469 | 469 | ||
470 | asGORotation :: Functor f => f [String] -> f GO.Rotation | ||
471 | asGORotation val = fmap parseRotation val | ||
472 | where parseRotation ["yaw"] = GO.Yaw | ||
473 | parseRotation ["pitch"] = GO.Pitch | ||
474 | parseRotation ["roll"] = GO.Roll | ||
475 | |||
476 | |||
477 | data Rotation = Rotation | 470 | data Rotation = Rotation |
478 | { ax :: Float | 471 | { ax :: Float |
479 | , ay :: Float | 472 | , ay :: Float |