aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Spear.lkshs10
-rw-r--r--Spear.lkshw2
-rw-r--r--Spear/Assets/Model.hsc62
-rw-r--r--Spear/Assets/Model/Model.c19
-rw-r--r--Spear/Assets/Model/Model.h9
-rw-r--r--Spear/Scene/Loader.hs21
6 files changed, 76 insertions, 47 deletions
diff --git a/Spear.lkshs b/Spear.lkshs
index 26a1ff6..a3f492f 100644
--- a/Spear.lkshs
+++ b/Spear.lkshs
@@ -1,18 +1,18 @@
1Version of session file format: 1Version of session file format:
2 1 2 1
3Time of storage: 3Time of storage:
4 "Tue Aug 7 23:33:12 CEST 2012" 4 "Wed Aug 8 13:25:10 CEST 2012"
5Layout: 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}) 263) 197)], paneTabs = Just BottomP, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 691) 954 5Layout: 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}) 273) 205)], paneTabs = Just BottomP, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 716) 954
6Population: [(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Collision/Collision.hs" 75)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Collision/Collisioner.hs" 551)),[SplitP LeftP]),(Just (ErrorsSt ErrorsState),[SplitP RightP,SplitP TopP]),(Just (FilesSt FilesState),[SplitP RightP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/GameObject.hs" 3124)),[SplitP LeftP]),(Just (InfoSt (InfoState Nothing)),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP BottomP,SplitP BottomP]),(Just (LogSt LogState),[SplitP RightP,SplitP BottomP]),(Just (ModulesSt (ModulesState 286 (SystemScope,False) (Nothing,Nothing) (ExpanderState {packageExp = ([],[]), packageExpNoBlack = ([],[]), 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/Spear/Physics.hs" 207)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Physics/Rigid.hs" 2175)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Math/Spatial.hs" 0)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Physics/Types.hs" 194)),[SplitP LeftP]),(Just (WorkspaceSt WorkspaceState),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Physics/World.hs" 3782)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/main.hs" 1603)),[SplitP LeftP])] 6Population: [(Just (ErrorsSt ErrorsState),[SplitP RightP,SplitP TopP]),(Just (FilesSt FilesState),[SplitP RightP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/GameObject.hs" 3129)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/IDStore.hs" 186)),[SplitP LeftP]),(Just (InfoSt (InfoState Nothing)),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP BottomP,SplitP BottomP]),(Just (LogSt LogState),[SplitP RightP,SplitP BottomP]),(Just (ModulesSt (ModulesState 286 (PackageScope False,False) (Nothing,Nothing) (ExpanderState {packageExp = ([],[]), packageExpNoBlack = ([],[]), packageDExp = ([],[]), packageDExpNoBlack = ([],[]), workspaceExp = ([],[]), workspaceExpNoBlack = ([[5]],[]), workspaceDExp = ([],[]), workspaceDExpNoBlack = ([],[]), systemExp = ([],[]), systemExpNoBlack = ([],[])}))),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP BottomP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Physics.hs" 207)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Physics/Rigid.hs" 2175)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Math/Spatial.hs" 0)),[SplitP LeftP]),(Just (WorkspaceSt WorkspaceState),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Physics/World.hs" 3781)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/main.hs" 1603)),[SplitP LeftP])]
7Window size: (1841,964) 7Window size: (1841,964)
8Completion size: 8Completion size:
9 (750,400) 9 (750,400)
10Workspace: Just "/home/jeanne/programming/haskell/Spear/Spear.lkshw" 10Workspace: Just "/home/jeanne/programming/haskell/Spear/Spear.lkshw"
11Active pane: Just "GameObject.hs" 11Active pane: Just "IDStore.hs"
12Toolbar visible: 12Toolbar visible:
13 True 13 True
14FindbarState: (False,FindState {entryStr = "asd", entryHist = ["gravity","asdad","rotSpeed","azimuth","mandatory","mandao","col","forward","MouseButton"], replaceStr = "mandatory'", replaceHist = [], caseSensitive = False, entireWord = False, wrapAround = False, regex = False, lineNr = 1}) 14FindbarState: (False,FindState {entryStr = "asd", entryHist = ["gravity","asdad","rotSpeed","azimuth","mandatory","mandao","col","forward","MouseButton"], replaceStr = "mandatory'", replaceHist = [], caseSensitive = False, entireWord = False, wrapAround = False, regex = False, lineNr = 1})
15Recently opened files: 15Recently opened files:
16 ["/home/jeanne/programming/haskell/Spear/Spear/App/Input.hs"] 16 ["/home/jeanne/programming/haskell/Spear/demos/simple-scene/Spear/IDStore.hs","/home/jeanne/programming/haskell/Spear/Spear/Physics/Types.hs","/home/jeanne/programming/haskell/Spear/Spear/Collision/Collision.hs","/home/jeanne/programming/haskell/Spear/Spear/Collision/Collisioner.hs","/home/jeanne/programming/haskell/Spear/Spear/App/Input.hs"]
17Recently opened workspaces: 17Recently opened workspaces:
18 ["/home/jeanne/leksah.lkshw"] \ No newline at end of file 18 ["/home/jeanne/leksah.lkshw"] \ No newline at end of file
diff --git a/Spear.lkshw b/Spear.lkshw
index ef77439..cc572e4 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 "Wed Aug 8 12:06:13 CEST 2012" 4 "Wed Aug 8 15:15:08 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/Assets/Model.hsc b/Spear/Assets/Model.hsc
index 5fd2db3..9e718c7 100644
--- a/Spear/Assets/Model.hsc
+++ b/Spear/Assets/Model.hsc
@@ -29,7 +29,8 @@ module Spear.Assets.Model
29, animationByName 29, animationByName
30, numAnimations 30, numAnimations
31 -- * Manipulation 31 -- * Manipulation
32, transform 32, transformVerts
33, transformNormals
33, toGround 34, toGround
34) 35)
35where 36where
@@ -232,72 +233,72 @@ fromCAnimation (CAnimation cname start end) =
232 Animation (B.unpack cname) (fromIntegral start) (fromIntegral end) 233 Animation (B.unpack cname) (fromIntegral start) (fromIntegral end)
233 234
234 235
235-- | Release the given 'Model'. 236-- | Release the model.
236releaseModel :: Model -> Setup () 237releaseModel :: Model -> Setup ()
237releaseModel = release . rkey 238releaseModel = release . rkey
238 239
239 240
240-- | Free the given 'CModel'. 241-- | Free the C model.
241freeModel :: CModel -> IO () 242freeModel :: CModel -> IO ()
242freeModel model = Foreign.with model model_free 243freeModel model = Foreign.with model model_free
243 244
244 245
245-- | Return 'True' if the given 'Model' is animated, 'False' otherwise. 246-- | Return 'True' if the model is animated, 'False' otherwise.
246animated :: Model -> Bool 247animated :: Model -> Bool
247animated = (>1) . numFrames 248animated = (>1) . numFrames
248 249
249 250
250-- | Return the given 'Model's vertices. 251-- | Return the model's vertices.
251vertices :: Model -> Ptr Vec3 252vertices :: Model -> Ptr Vec3
252vertices = cVerts . modelData 253vertices = cVerts . modelData
253 254
254 255
255-- | Return the given 'Model's normals. 256-- | Return the model's normals.
256normals :: Model -> Ptr Vec3 257normals :: Model -> Ptr Vec3
257normals = cNormals . modelData 258normals = cNormals . modelData
258 259
259 260
260-- | Return the given 'Model's texCoords. 261-- | Return the model's texCoords.
261texCoords :: Model -> Ptr TexCoord 262texCoords :: Model -> Ptr TexCoord
262texCoords = cTexCoords . modelData 263texCoords = cTexCoords . modelData
263 264
264 265
265-- | Return the given 'Model's triangles. 266-- | Return the model's triangles.
266triangles :: Model -> Ptr Triangle 267triangles :: Model -> Ptr Triangle
267triangles = cTris . modelData 268triangles = cTris . modelData
268 269
269 270
270-- | Return the given 'Model's skins. 271-- | Return the model's skins.
271skins :: Model -> Ptr Skin 272skins :: Model -> Ptr Skin
272skins = cSkins . modelData 273skins = cSkins . modelData
273 274
274 275
275-- | Return the given 'Model's number of frames. 276-- | Return the model's number of frames.
276numFrames :: Model -> Int 277numFrames :: Model -> Int
277numFrames = fromIntegral . cnFrames . modelData 278numFrames = fromIntegral . cnFrames . modelData
278 279
279 280
280-- | Return the given 'Model's number of vertices. 281-- | Return the model's number of vertices.
281numVertices :: Model -> Int 282numVertices :: Model -> Int
282numVertices = fromIntegral . cnVerts . modelData 283numVertices = fromIntegral . cnVerts . modelData
283 284
284 285
285-- | Return the given 'Model's number of triangles. 286-- | Return the model's number of triangles.
286numTriangles :: Model -> Int 287numTriangles :: Model -> Int
287numTriangles = fromIntegral . cnTris . modelData 288numTriangles = fromIntegral . cnTris . modelData
288 289
289 290
290-- | Return the given 'Model's number of texture coordinates. 291-- | Return the model's number of texture coordinates.
291numTexCoords :: Model -> Int 292numTexCoords :: Model -> Int
292numTexCoords = fromIntegral . cnTexCoords . modelData 293numTexCoords = fromIntegral . cnTexCoords . modelData
293 294
294 295
295-- | Return the given 'Model's number of skins. 296-- | Return the model's number of skins.
296numSkins :: Model -> Int 297numSkins :: Model -> Int
297numSkins = fromIntegral . cnSkins . modelData 298numSkins = fromIntegral . cnSkins . modelData
298 299
299 300
300-- | Return the underlying 'CModel'. 301-- | Return the underlying C model.
301cmodel :: Model -> CModel 302cmodel :: Model -> CModel
302cmodel = modelData 303cmodel = modelData
303 304
@@ -312,27 +313,38 @@ animationByName :: Model -> String -> Maybe Animation
312animationByName model anim = V.find ((==) anim . name) $ mAnimations model 313animationByName model anim = V.find ((==) anim . name) $ mAnimations model
313 314
314 315
315-- | Return the number of animations in the given 'Model'. 316-- | Return the number of animations of the given model.
316numAnimations :: Model -> Int 317numAnimations :: Model -> Int
317numAnimations = V.length . mAnimations 318numAnimations = V.length . mAnimations
318 319
319 320
320-- | Transform the given 'Model's vertices with the given matrix. 321-- | Transform the model's vertices with the given matrix.
321transform :: M4.Matrix4 -> Model -> IO () 322transformVerts :: M4.Matrix4 -> Model -> IO ()
322transform mat (Model model _ _) = 323transformVerts mat (Model model _ _) =
323 allocaBytes (16*sizeFloat) $ \matPtr -> 324 allocaBytes (16*sizeFloat) $ \matPtr ->
324 allocaBytes (9*sizeFloat) $ \normalPtr ->
325 with model $ \modelPtr -> do 325 with model $ \modelPtr -> do
326 poke matPtr mat 326 poke matPtr mat
327 poke normalPtr $ fastNormalMatrix mat 327 model_transform_vertices modelPtr matPtr
328 model_transform modelPtr matPtr normalPtr
329 328
330 329
331foreign import ccall "Model.h model_transform" 330-- | Transform the model's normals with the given matrix.
332 model_transform :: Ptr CModel -> Ptr M4.Matrix4 -> Ptr M3.Matrix3 -> IO () 331transformNormals :: M3.Matrix3 -> Model -> IO ()
332transformNormals mat (Model model _ _) =
333 allocaBytes (9*sizeFloat) $ \normalPtr ->
334 with model $ \modelPtr -> do
335 poke normalPtr mat
336 model_transform_normals modelPtr normalPtr
337
338
339foreign import ccall "Model.h model_transform_vertices"
340 model_transform_vertices :: Ptr CModel -> Ptr M4.Matrix4 -> IO ()
341
342
343foreign import ccall "Model.h model_transform_normals"
344 model_transform_normals :: Ptr CModel -> Ptr M3.Matrix3 -> IO ()
333 345
334 346
335-- | Transform the given 'Model' such that its lowest point has y = 0. 347-- | Transform the model such that its lowest point has y = 0.
336toGround :: Model -> IO () 348toGround :: Model -> IO ()
337toGround (Model model _ _) = with model model_to_ground 349toGround (Model model _ _) = with model model_to_ground
338 350
diff --git a/Spear/Assets/Model/Model.c b/Spear/Assets/Model/Model.c
index 837dd93..f6b2f1f 100644
--- a/Spear/Assets/Model/Model.c
+++ b/Spear/Assets/Model/Model.c
@@ -56,19 +56,28 @@ static void mul_normal (float m[9], vec3* n)
56} 56}
57 57
58 58
59void model_transform (Model* model, float mat[16], float normal[9]) 59void model_transform_vertices (Model* model, float mat[16])
60{ 60{
61 unsigned i = 0; 61 unsigned i = 0;
62 unsigned j = model->numVertices * model->numFrames; 62 unsigned j = model->numVertices * model->numFrames;
63 vec3* v = model->vertices; 63 vec3* v = model->vertices;
64 vec3* n = model->normals;
65 64
66 for (; i < j; ++i) 65 for (; i < j; ++i, ++v)
67 { 66 {
68 mul (mat, v); 67 mul (mat, v);
68 }
69}
70
71
72void model_transform_normals (Model* model, float normal[9])
73{
74 unsigned i = 0;
75 unsigned j = model->numVertices * model->numFrames;
76 vec3* n = model->normals;
77
78 for (; i < j; ++i, ++n)
79 {
69 mul_normal (normal, n); 80 mul_normal (normal, n);
70 v++;
71 n++;
72 } 81 }
73} 82}
74 83
diff --git a/Spear/Assets/Model/Model.h b/Spear/Assets/Model/Model.h
index 34c6444..84be6aa 100644
--- a/Spear/Assets/Model/Model.h
+++ b/Spear/Assets/Model/Model.h
@@ -69,10 +69,13 @@ extern "C" {
69/// The 'model' pointer itself is not freed. 69/// The 'model' pointer itself is not freed.
70void model_free (Model* model); 70void model_free (Model* model);
71 71
72/// Transform the given Model's vertices by the given matrix. 72/// Transform the Model's vertices by the given matrix.
73void model_transform (Model* model, float mat[16], float normal[9]); 73void model_transform_verts (Model* model, float mat[16]);
74 74
75/// Translate the given Model such that its lowest point has y = 0. 75/// Transform the Model's normals by the given matrix.
76void model_transform_normals (Model* model, float normal[9]);
77
78/// Translate the Model such that its lowest point has y = 0.
76void model_to_ground (Model* model); 79void model_to_ground (Model* model);
77 80
78#ifdef __cplusplus 81#ifdef __cplusplus
diff --git a/Spear/Scene/Loader.hs b/Spear/Scene/Loader.hs
index 6001bdb..06e0aa9 100644
--- a/Spear/Scene/Loader.hs
+++ b/Spear/Scene/Loader.hs
@@ -20,6 +20,7 @@ where
20import Spear.Assets.Model as Model 20import Spear.Assets.Model as Model
21import qualified Spear.GLSL as GLSL 21import qualified Spear.GLSL as GLSL
22import Spear.Math.Matrix4 as M4 22import Spear.Math.Matrix4 as M4
23import Spear.Math.MatrixUtils (fastNormalMatrix)
23import Spear.Math.Vector3 as V3 24import Spear.Math.Vector3 as V3
24import Spear.Math.Vector4 25import Spear.Math.Vector4
25import Spear.Render.AnimatedModel 26import Spear.Render.AnimatedModel
@@ -192,20 +193,24 @@ loadModel' file rotation scale = do
192 Just rot -> setupIO $ rotateModel model rot 193 Just rot -> setupIO $ rotateModel model rot
193 Nothing -> return () 194 Nothing -> return ()
194 case scale of 195 case scale of
195 Just s -> setupIO $ Model.transform (scalev s) model 196 Just s -> setupIO $ Model.transformVerts (scalev s) model
196 Nothing -> return () 197 Nothing -> return ()
197 setupIO $ toGround model 198 setupIO $ toGround model
198 return model 199 return model
199 200
200 201
201rotateModel :: Model -> Rotation -> IO () 202rotateModel :: Model -> Rotation -> IO ()
202rotateModel model (Rotation x y z order) = case order of 203rotateModel model (Rotation x y z order) =
203 XYZ -> Model.transform (rotZ z * rotY y * rotX x) model 204 let mat = case order of
204 XZY -> Model.transform (rotY y * rotZ z * rotX x) model 205 XYZ -> rotZ z * rotY y * rotX x
205 YXZ -> Model.transform (rotZ z * rotX x * rotY y) model 206 XZY -> rotY y * rotZ z * rotX x
206 YZX -> Model.transform (rotX x * rotZ z * rotY y) model 207 YXZ -> rotZ z * rotX x * rotY y
207 ZXY -> Model.transform (rotY y * rotX x * rotZ z) model 208 YZX -> rotX x * rotZ z * rotY y
208 ZYX -> Model.transform (rotX x * rotY y * rotZ z) model 209 ZXY -> rotY y * rotX x * rotZ z
210 ZYX -> rotX x * rotY y * rotZ z
211 normalMat = fastNormalMatrix mat
212 in
213 Model.transformVerts mat model >> Model.transformNormals normalMat model
209 214
210 215
211loadTexture :: FilePath -> Loader GLSL.Texture 216loadTexture :: FilePath -> Loader GLSL.Texture