From ada455ccc1898826d55cbe275da895d80b792cd5 Mon Sep 17 00:00:00 2001 From: Marc Sunet Date: Wed, 1 Aug 2012 13:20:17 +0200 Subject: fixed inverse transform, added orbit and lookAt functions --- Spear.lkshs | 12 ++++++------ Spear.lkshw | 4 ++-- Spear/Assets/Model/MD2/MD2_load.c | 6 +++--- Spear/Math/Matrix4.hs | 31 ++++++++++++++++--------------- Spear/Math/Vector3.hs | 6 +++--- 5 files changed, 30 insertions(+), 29 deletions(-) diff --git a/Spear.lkshs b/Spear.lkshs index a5674ae..541f4ef 100644 --- a/Spear.lkshs +++ b/Spear.lkshs @@ -1,18 +1,18 @@ Version of session file format: 1 Time of storage: - "Tue Jul 31 01:00:21 CEST 2012" -Layout: VerticalP (TerminalP {paneGroups = fromList [], paneTabs = Just TopP, currentPage = 0, 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}) 290) 199)], paneTabs = Just BottomP, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 701) 953 -Population: [(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/GameMessage.hs" 295)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/GameObject.hs" 5019)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/GameState.hs" 265)),[SplitP LeftP]),(Just (InfoSt (InfoState Nothing)),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP BottomP,SplitP BottomP]),(Just (LogSt LogState),[SplitP RightP,SplitP BottomP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Math/Matrix4.hs" 8726)),[SplitP LeftP]),(Just (ModulesSt (ModulesState 286 (PackageScope False,False) (Just (ModuleName ["Spear","Math","Camera"]),Nothing) (ExpanderState {packageExp = ([],[]), packageExpNoBlack = ([[0,4],[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/Spear/Math/Vector3.hs" 3534)),[SplitP LeftP]),(Just (WorkspaceSt WorkspaceState),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/main.hs" 3944)),[SplitP LeftP])] + "Wed Aug 1 13:16:07 CEST 2012" +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}) 315) 217)], paneTabs = Just BottomP, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 759) 953 +Population: [(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Collision/Collision.hs" 61)),[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" 3739)),[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" 12935)),[SplitP LeftP]),(Just (LogSt LogState),[SplitP RightP,SplitP BottomP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Math/Matrix4.hs" 14139)),[SplitP LeftP]),(Just (ModulesSt (ModulesState 286 (PackageScope False,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/Math/Vector3.hs" 3515)),[SplitP LeftP]),(Just (WorkspaceSt WorkspaceState),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/main.hs" 789)),[SplitP LeftP])] Window size: (1796,979) Completion size: (750,400) Workspace: Just "/home/jeanne/programming/haskell/Spear/Spear.lkshw" -Active pane: Just "GameMessage.hs" +Active pane: Just "GameObject.hs" Toolbar visible: True -FindbarState: (False,FindState {entryStr = "", entryHist = ["asd","MouseButton"], replaceStr = "MouseProperty", replaceHist = [], caseSensitive = False, entireWord = False, wrapAround = False, regex = False, lineNr = 1}) +FindbarState: (False,FindState {entryStr = "asd", entryHist = ["col","forward","asd","MouseButton"], replaceStr = "row", replaceHist = [], caseSensitive = False, entireWord = False, wrapAround = False, regex = False, lineNr = 1}) Recently opened files: - ["/home/jeanne/programming/haskell/Spear/Spear/Collision/Collision.hs","/home/jeanne/programming/haskell/Spear/Spear/Math/Camera.hs","/home/jeanne/programming/haskell/Spear/Spear/Math/Entity.hs","/home/jeanne/programming/haskell/Spear/Spear/Scene/Scene.hs","/home/jeanne/programming/haskell/Spear/Spear/Math/Spatial.hs","/home/jeanne/programming/haskell/Spear/Spear/Assets/Image/BMP/BMP_load.c","/home/jeanne/programming/haskell/Spear/Spear/Assets/Model/OBJ/OBJ_load.cc","/home/jeanne/programming/haskell/Spear/Spear/Assets/Model.hsc","/home/jeanne/programming/haskell/Spear/Spear/Assets/Model/MD2/MD2_load.c","/home/jeanne/programming/haskell/Spear/Spear/Assets/Model/Model.h","/home/jeanne/programming/haskell/Spear/demos/simple-scene/OgroAnimation.hs","/home/jeanne/programming/haskell/Spear/Spear/App/Input.hs"] + ["/home/jeanne/programming/haskell/Spear/demos/simple-scene/simple.scene","/home/jeanne/programming/haskell/Spear/Spear/Assets/Model/Model.c","/home/jeanne/programming/haskell/Spear/demos/simple-scene/GameMessage.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/GameState.hs","/home/jeanne/programming/haskell/Spear/Spear/Collision/Collision.hs","/home/jeanne/programming/haskell/Spear/Spear/Math/Camera.hs","/home/jeanne/programming/haskell/Spear/Spear/Math/Entity.hs","/home/jeanne/programming/haskell/Spear/Spear/Scene/Scene.hs","/home/jeanne/programming/haskell/Spear/Spear/Math/Spatial.hs","/home/jeanne/programming/haskell/Spear/Spear/Assets/Image/BMP/BMP_load.c","/home/jeanne/programming/haskell/Spear/Spear/Assets/Model/OBJ/OBJ_load.cc","/home/jeanne/programming/haskell/Spear/Spear/Assets/Model.hsc"] Recently opened workspaces: ["/home/jeanne/programming/haskell/Spear/Spear.lkshw","/home/jeanne/leksah.lkshw"] \ No newline at end of file diff --git a/Spear.lkshw b/Spear.lkshw index 47ee51d..aed85a0 100644 --- a/Spear.lkshw +++ b/Spear.lkshw @@ -1,10 +1,10 @@ Version of workspace file format: 1 Time of storage: - "Tue Jul 31 00:59:07 CEST 2012" + "Tue Jul 31 20:32:45 CEST 2012" Name of the workspace: "Spear" File paths of contained packages: ["demos/simple-scene/simple-scene.cabal","Spear.cabal"] Maybe file path of an active package: - Just "Spear.cabal" \ No newline at end of file + Just "demos/simple-scene/simple-scene.cabal" \ No newline at end of file diff --git a/Spear/Assets/Model/MD2/MD2_load.c b/Spear/Assets/Model/MD2/MD2_load.c index 238bc9a..c25cda8 100644 --- a/Spear/Assets/Model/MD2/MD2_load.c +++ b/Spear/Assets/Model/MD2/MD2_load.c @@ -451,7 +451,7 @@ Model_error_code MD2_load (const char* filename, char clockwise, char left_hande currentAnimation->start = start; currentAnimation->end = header->numFrames-1; - printf ("finished loading model %s\n", filename); + /*printf ("finished loading model %s\n", filename); printf ("numAnimations: %u\n", numAnimations); printf ("animations: %p\n", animations); @@ -461,8 +461,8 @@ Model_error_code MD2_load (const char* filename, char clockwise, char left_hande printf ("Animation %d, name: %s, start: %d, end %d\n", i, currentAnimation->name, currentAnimation->start, currentAnimation->end); currentAnimation++; - } - + }*/ + model->vertices = vertices; model->normals = normals; model->texCoords = texCoords; diff --git a/Spear/Math/Matrix4.hs b/Spear/Math/Matrix4.hs index a86dc84..2176e99 100644 --- a/Spear/Math/Matrix4.hs +++ b/Spear/Math/Matrix4.hs @@ -195,18 +195,16 @@ transform right up fwd pos = mat4 -- | Build a transformation 'Matrix4' defined by the given position and target. --- --- This function is essentially like gluLookAt. lookAt :: Vector3 -- ^ Eye position. -> Vector3 -- ^ Target point. - -> Vector3 -- ^ Up vector. -> Matrix4 -lookAt pos target up = +lookAt pos target = let fwd = Vector3.normalise $ target - pos - r = fwd `cross` up + r = fwd `cross` Vector3.unitY + u = r `cross` fwd in - transform r up (-fwd) pos + transform r u (-fwd) pos -- | Zip two matrices together with the specified function. @@ -412,15 +410,18 @@ transpose m = mat4 -- | Invert the given transformation matrix. inverseTransform :: Matrix4 -> Matrix4 -inverseTransform mat = mat4fromVec u v w p where - u = vec4 (Vector4.x $ col0 mat) (Vector4.y $ col0 mat) (Vector4.z $ col0 mat) 0 - v = vec4 (Vector4.x $ col1 mat) (Vector4.y $ col1 mat) (Vector4.z $ col1 mat) 0 - w = vec4 (Vector4.x $ col2 mat) (Vector4.y $ col2 mat) (Vector4.z $ col2 mat) 0 - p = vec4 tdotu tdotv tdotw 1 - t = -(col3 mat) - tdotu = t `Vector4.dot` u - tdotv = t `Vector4.dot` v - tdotw = t `Vector4.dot` w +inverseTransform mat = mat4fromVec u v w p where + v0 = row0 mat + v1 = row1 mat + v2 = row2 mat + u = vec4 (Vector4.x v0) (Vector4.y v0) (Vector4.z v0) 0 + v = vec4 (Vector4.x v1) (Vector4.y v1) (Vector4.z v1) 0 + w = vec4 (Vector4.x v2) (Vector4.y v2) (Vector4.z v2) 0 + p = vec4 tdotu tdotv tdotw 1 + t = -(col3 mat) + tdotu = t `Vector4.dot` col0 mat + tdotv = t `Vector4.dot` col1 mat + tdotw = t `Vector4.dot` col2 mat -- | Invert the given matrix. diff --git a/Spear/Math/Vector3.hs b/Spear/Math/Vector3.hs index fad6e01..b10fd16 100644 --- a/Spear/Math/Vector3.hs +++ b/Spear/Math/Vector3.hs @@ -140,9 +140,9 @@ orbit center radius anglex angley = sy = sin ay cx = cos ax cy = cos ay - px = (x center) + radius*cy*sx - py = (y center) + radius*sy - pz = (z center) + radius*cx*cy + px = x center + radius*cy*sx + py = y center + radius*sy + pz = z center + radius*cx*cy in vec3 px py pz -- cgit v1.2.3