diff options
author | Marc Sunet <jeannekamikaze@gmail.com> | 2012-09-03 12:42:45 +0200 |
---|---|---|
committer | Marc Sunet <jeannekamikaze@gmail.com> | 2012-09-03 12:42:45 +0200 |
commit | fa3e0779521777b94aa1649b81222693150b5299 (patch) | |
tree | 1731cbf923b3aca029f4c07ed70e9bd06708887e | |
parent | c41c0badf5d4f586d7d49790471f4c5d9ac2b382 (diff) |
2d virtual = view
-rw-r--r-- | Spear.lkshs | 10 | ||||
-rw-r--r-- | Spear.lkshw | 2 | ||||
-rw-r--r-- | Spear/Math/MatrixUtils.hs | 50 | ||||
-rw-r--r-- | Spear/Scene/GameObject.hs | 56 |
4 files changed, 64 insertions, 54 deletions
diff --git a/Spear.lkshs b/Spear.lkshs index 646bfd8..9d57ffa 100644 --- a/Spear.lkshs +++ b/Spear.lkshs | |||
@@ -1,9 +1,9 @@ | |||
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 | "Sun Sep 2 11:03:47 CEST 2012" | 4 | "Mon Sep 3 00:01:24 CEST 2012" |
5 | Layout: VerticalP (TerminalP {paneGroups = fromList [], paneTabs = Just TopP, currentPage = 9, 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}) 310) 222),("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}) 264)], paneTabs = Just BottomP, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 682) 954 | 5 | Layout: VerticalP (TerminalP {paneGroups = fromList [], paneTabs = Just TopP, currentPage = 4, 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}) 346) 184),("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}) 265)], paneTabs = Just BottomP, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 688) 954 |
6 | Population: [(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/AnimatedGO.hs" 451)),[SplitP LeftP]),(Just (BreakpointsSt BreakpointsState),[SplitP RightP,SplitP TopP,GroupP "Debug",SplitP BottomP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Collision.hs" 5042)),[SplitP LeftP]),(Just (ErrorsSt ErrorsState),[SplitP RightP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Factory.hs" 1371)),[SplitP LeftP]),(Just (FilesSt FilesState),[SplitP RightP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Scene/GameObject.hs" 3988)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject.hs" 797)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameState.hs" 891)),[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/MatrixUtils.hs" 0)),[SplitP LeftP]),(Just (ModulesSt (ModulesState 328 (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/demos/simple-scene/Game/GameObject/Player.hs" 741)),[SplitP LeftP]),(Just (SearchSt (SearchState {searchString = "putStrLn", searchScope = PackageScope False, searchMode = Prefix {caseSense = False}})),[SplitP RightP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/StaticGO.hs" 434)),[SplitP LeftP]),(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" 629)),[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]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/main.hs" 4434)),[SplitP LeftP])] | 6 | Population: [(Just (BreakpointsSt BreakpointsState),[SplitP RightP,SplitP TopP,GroupP "Debug",SplitP BottomP]),(Just (ErrorsSt ErrorsState),[SplitP RightP,SplitP TopP]),(Just (FilesSt FilesState),[SplitP RightP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Scene/GameObject.hs" 217)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject.hs" 2615)),[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/MatrixUtils.hs" 1873)),[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" 858)),[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" 471)),[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]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/main.hs" 4657)),[SplitP LeftP])] |
7 | Window size: (1820,944) | 7 | Window size: (1820,944) |
8 | Completion size: | 8 | Completion size: |
9 | (750,399) | 9 | (750,399) |
@@ -11,8 +11,8 @@ Workspace: Just "/home/jeanne/programming/haskell/Spear/Spear.lkshw" | |||
11 | Active pane: Just "Utils.hs" | 11 | Active pane: Just "Utils.hs" |
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 = "asdad", entryHist = ["asdad","m[15]","m[14]","m[1]","m[13]","m[12]","m[11]","m[10]","m[9]","m[8]","m[7]","m[6]"], replaceStr = "a01", replaceHist = [], caseSensitive = True, entireWord = False, wrapAround = False, regex = False, lineNr = 1}) |
15 | Recently opened files: | 15 | Recently opened files: |
16 | ["/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Utils.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/StaticGO.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/AnimatedGO.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Player.hs","/home/jeanne/programming/haskell/Spear/Spear/Math/Matrix4.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameState.hs","/home/jeanne/programming/haskell/Spear/Spear/Math/AABB.hs","/home/jeanne/programming/haskell/Spear/Spear/Collision.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Factory.hs","/home/jeanne/programming/haskell/Spear/Spear/Scene/Scene.hs","/home/jeanne/programming/haskell/Spear/Spear/Math/Entity.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/Program/Box.hs"] | 16 | ["/home/jeanne/programming/haskell/Spear/Spear/Math/Camera.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Factory.hs","/home/jeanne/programming/haskell/Spear/Spear/Math/Matrix3.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/Program/Box.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/Program/Line.hs","/home/jeanne/programming/haskell/Spear/Spear/Math/MatrixUtils.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Utils.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/StaticGO.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/AnimatedGO.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Player.hs","/home/jeanne/programming/haskell/Spear/Spear/Math/Matrix4.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameState.hs"] |
17 | Recently opened workspaces: | 17 | Recently opened workspaces: |
18 | ["/home/jeanne/programming/haskell/hagen/hagen.lkshw","/home/jeanne/programming/haskell/foo/foo.lkshw","/home/jeanne/programming/haskell/Spear/Spear.lkshw","/home/jeanne/programming/haskell/nexus/nexus.lkshw","/home/jeanne/leksah.lkshw"] \ No newline at end of file | 18 | ["/home/jeanne/programming/haskell/hagen/hagen.lkshw","/home/jeanne/programming/haskell/foo/foo.lkshw","/home/jeanne/programming/haskell/Spear/Spear.lkshw","/home/jeanne/programming/haskell/nexus/nexus.lkshw","/home/jeanne/leksah.lkshw"] \ No newline at end of file |
diff --git a/Spear.lkshw b/Spear.lkshw index a54198c..fce08ab 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 | "Sun Sep 2 15:36:42 CEST 2012" | 4 | "Mon Sep 3 11:26:24 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/Math/MatrixUtils.hs b/Spear/Math/MatrixUtils.hs index 44af2c0..87d84e5 100644 --- a/Spear/Math/MatrixUtils.hs +++ b/Spear/Math/MatrixUtils.hs | |||
@@ -5,7 +5,7 @@ module Spear.Math.MatrixUtils | |||
5 | , pltTransform | 5 | , pltTransform |
6 | , rpgInverse | 6 | , rpgInverse |
7 | , pltInverse | 7 | , pltInverse |
8 | , toClip | 8 | , objToClip |
9 | ) | 9 | ) |
10 | where | 10 | where |
11 | 11 | ||
@@ -27,31 +27,28 @@ fastNormalMatrix m = | |||
27 | (M4.m02 m') (M4.m12 m') (M4.m22 m') | 27 | (M4.m02 m') (M4.m12 m') (M4.m22 m') |
28 | 28 | ||
29 | 29 | ||
30 | -- | Maps the given 2D transformation matrix to a 3D transformation matrix. | 30 | -- | Map an object's transform in view space to world space. |
31 | rpgTransform | 31 | rpgTransform |
32 | :: Float -- ^ The height above the ground | 32 | :: Float -- ^ The height above the ground |
33 | -> Float -- ^ Angle of rotation | 33 | -> Float -- ^ Angle of rotation |
34 | -> Vector3 -- ^ Axis of rotation | 34 | -> Vector3 -- ^ Axis of rotation |
35 | -> Vector2 -- ^ Object's position. | 35 | -> Vector2 -- ^ Object's position. |
36 | -> Matrix4 -- ^ Inverse view matrix. | ||
36 | -> Matrix4 | 37 | -> Matrix4 |
37 | rpgTransform h a axis pos = | 38 | rpgTransform h a axis pos viewInverse = |
38 | {-let r = let r' = M3.right mat in vec3 (V2.x r') (V2.y r') 0 | ||
39 | u = V3.unity | ||
40 | f = let f' = M3.forward mat in vec3 (V2.x f') 0 (V2.y f') | ||
41 | t = (vec3 0 h 0) + let t' = M3.position mat in vec3 (V2.x t') 0 (V2.y t')-} | ||
42 | let mat' = axisAngle axis a | 39 | let mat' = axisAngle axis a |
43 | r = M4.right mat' | 40 | r = M4.right mat' |
44 | u = M4.up mat' | 41 | u = M4.up mat' |
45 | f = M4.forward mat' | 42 | f = M4.forward mat' |
46 | t = vec3 0 h 0 + vec3 (V2.x pos) 0 (-V2.y pos) | 43 | t = vec3 0 h 0 + vec3 (V2.x pos) 0 (-V2.y pos) |
47 | in mat4 | 44 | in mat4 |
48 | (V3.x r) (V3.x u) (V3.x f) (V3.x t) | 45 | (V3.x r) (V3.x u) (V3.x f) (V3.x t) |
49 | (V3.y r) (V3.y u) (V3.y f) (V3.y t) | 46 | (V3.y r) (V3.y u) (V3.y f) (V3.y t) |
50 | (V3.z r) (V3.z u) (V3.z f) (V3.z t) | 47 | (V3.z r) (V3.z u) (V3.z f) (V3.z t) |
51 | 0 0 0 1 | 48 | 0 0 0 1 |
52 | 49 | ||
53 | 50 | ||
54 | -- | Maps the given 2D transformation matrix to a 3D transformation matrix. | 51 | -- | Map an object's transform in view space to world space. |
55 | pltTransform :: Matrix3 -> Matrix4 | 52 | pltTransform :: Matrix3 -> Matrix4 |
56 | pltTransform mat = | 53 | pltTransform mat = |
57 | let r = let r' = M3.right mat in vec3 (V2.x r') (V2.y r') 0 | 54 | let r = let r' = M3.right mat in vec3 (V2.x r') (V2.y r') 0 |
@@ -65,23 +62,22 @@ pltTransform mat = | |||
65 | 0 0 0 1 | 62 | 0 0 0 1 |
66 | 63 | ||
67 | 64 | ||
68 | -- | Compute the inverse transform of the given transformation matrix. | 65 | -- | Map an object's transform in world space to view space. |
69 | -- | ||
70 | -- This function maps an object's transform in 2D to the object's inverse in 3D. | ||
71 | -- | 66 | -- |
72 | -- The XY plane in 2D translates to the X(-Z) plane in 3D. | 67 | -- The XY plane in 2D translates to the X(-Z) plane in 3D. |
73 | -- | 68 | -- |
74 | -- Use this in games such as RPGs and RTSs. | 69 | -- Use this in games such as RPGs and RTSs. |
75 | rpgInverse | 70 | rpgInverse |
76 | :: Float -- ^ The height above the ground | 71 | :: Float -- ^ The height above the ground |
77 | -> Float -- ^ Angle of rotation | 72 | -> Float -- ^ Angle of rotation |
78 | -> Vector3 -- ^ Axis of rotation | 73 | -> Vector3 -- ^ Axis of rotation |
79 | -> Vector2 | 74 | -> Vector2 -- ^ Object's position. |
75 | -> Matrix4 -- ^ Inverse view matrix. | ||
80 | -> Matrix4 | 76 | -> Matrix4 |
81 | rpgInverse h a rot pos = M4.inverseTransform $ rpgTransform h a rot pos | 77 | rpgInverse h a rot pos viewInv = M4.inverseTransform $ rpgTransform h a rot pos viewInv |
82 | 78 | ||
83 | 79 | ||
84 | -- | Compute the inverse transform of the given transformation matrix. | 80 | -- | Map an object's transform in world space to view space. |
85 | -- | 81 | -- |
86 | -- This function maps an object's transform in 2D to the object's inverse in 3D. | 82 | -- This function maps an object's transform in 2D to the object's inverse in 3D. |
87 | -- | 83 | -- |
@@ -93,8 +89,8 @@ pltInverse = M4.inverseTransform . pltTransform | |||
93 | 89 | ||
94 | 90 | ||
95 | -- | Transform an object from object to clip space coordinates. | 91 | -- | Transform an object from object to clip space coordinates. |
96 | toClip :: Camera -> Matrix4 -> Vector3 -> Vector2 | 92 | objToClip :: Camera -> Matrix4 -> Vector3 -> Vector2 |
97 | toClip cam model p = | 93 | objToClip cam model p = |
98 | let | 94 | let |
99 | view = M4.inverseTransform $ Cam.transform cam | 95 | view = M4.inverseTransform $ Cam.transform cam |
100 | proj = Cam.projection cam | 96 | proj = Cam.projection cam |
diff --git a/Spear/Scene/GameObject.hs b/Spear/Scene/GameObject.hs index fc35c2b..a109a35 100644 --- a/Spear/Scene/GameObject.hs +++ b/Spear/Scene/GameObject.hs | |||
@@ -9,7 +9,8 @@ module Spear.Scene.GameObject | |||
9 | , currentAnimation | 9 | , currentAnimation |
10 | , goAABB | 10 | , goAABB |
11 | , goAABBs | 11 | , goAABBs |
12 | , go3Dtransform | 12 | , collisioners |
13 | , goRPGtransform | ||
13 | , numCollisioners | 14 | , numCollisioners |
14 | , renderer | 15 | , renderer |
15 | -- * Manipulation | 16 | -- * Manipulation |
@@ -18,6 +19,7 @@ module Spear.Scene.GameObject | |||
18 | , setAnimationSpeed | 19 | , setAnimationSpeed |
19 | , withCollisioners | 20 | , withCollisioners |
20 | , setCollisioners | 21 | , setCollisioners |
22 | , setViewInverse | ||
21 | -- * Rendering | 23 | -- * Rendering |
22 | , goRender | 24 | , goRender |
23 | -- * Collision | 25 | -- * Collision |
@@ -58,6 +60,7 @@ data GameObject = GameObject | |||
58 | , transform :: !M3.Matrix3 | 60 | , transform :: !M3.Matrix3 |
59 | , axis :: Vector3 | 61 | , axis :: Vector3 |
60 | , angle :: Float | 62 | , angle :: Float |
63 | , viewInv :: !M4.Matrix4 | ||
61 | } | 64 | } |
62 | 65 | ||
63 | 66 | ||
@@ -148,10 +151,10 @@ goNew :: GameStyle | |||
148 | -> GameObject | 151 | -> GameObject |
149 | 152 | ||
150 | goNew style (Left smr) cols transf axis = | 153 | goNew style (Left smr) cols transf axis = |
151 | GameObject style (Left $ SM.staticModelRenderer smr) cols transf axis 0 | 154 | GameObject style (Left $ SM.staticModelRenderer smr) cols transf axis 0 M4.id |
152 | 155 | ||
153 | goNew style (Right amr) cols transf axis = | 156 | goNew style (Right amr) cols transf axis = |
154 | GameObject style (Right $ AM.animatedModelRenderer 1 amr) cols transf axis 0 | 157 | GameObject style (Right $ AM.animatedModelRenderer 1 amr) cols transf axis 0 M4.id |
155 | 158 | ||
156 | 159 | ||
157 | goUpdate :: Float -> GameObject -> GameObject | 160 | goUpdate :: Float -> GameObject -> GameObject |
@@ -176,8 +179,8 @@ goAABBs = fmap getAABB . collisioners | |||
176 | 179 | ||
177 | 180 | ||
178 | -- | Get the game object's 3D transform. | 181 | -- | Get the game object's 3D transform. |
179 | go3Dtransform :: GameObject -> M4.Matrix4 | 182 | goRPGtransform :: GameObject -> M4.Matrix4 |
180 | go3Dtransform go = rpgTransform 0 (angle go) (axis go) (S2.pos go) | 183 | goRPGtransform go = rpgTransform 0 (angle go) (axis go) (S2.pos go) (viewInv go) |
181 | 184 | ||
182 | 185 | ||
183 | -- | Get the game object's current animation. | 186 | -- | Get the game object's current animation. |
@@ -211,6 +214,11 @@ setCollisioners :: GameObject -> [Collisioner] -> GameObject | |||
211 | setCollisioners go cols = go { collisioners = cols } | 214 | setCollisioners go cols = go { collisioners = cols } |
212 | 215 | ||
213 | 216 | ||
217 | -- | Set the game object's view inverse matrix. | ||
218 | setViewInverse :: M4.Matrix4 -> GameObject -> GameObject | ||
219 | setViewInverse mat go = go { viewInv = mat } | ||
220 | |||
221 | |||
214 | -- | Manipulate the game object's collisioners. | 222 | -- | Manipulate the game object's collisioners. |
215 | withCollisioners :: GameObject -> ([Collisioner] -> [Collisioner]) -> GameObject | 223 | withCollisioners :: GameObject -> ([Collisioner] -> [Collisioner]) -> GameObject |
216 | withCollisioners go f = go { collisioners = f $ collisioners go } | 224 | withCollisioners go f = go { collisioners = f $ collisioners go } |
@@ -221,15 +229,24 @@ goRender :: StaticProgram -> AnimatedProgram -> Cam.Camera -> GameObject -> IO ( | |||
221 | goRender sprog aprog cam go = | 229 | goRender sprog aprog cam go = |
222 | let spu = staticProgramUniforms sprog | 230 | let spu = staticProgramUniforms sprog |
223 | apu = animatedProgramUniforms aprog | 231 | apu = animatedProgramUniforms aprog |
224 | mat = S2.transform go | 232 | style = gameStyle go |
225 | style = gameStyle go | 233 | axis' = axis go |
226 | axis' = axis go | 234 | a = angle go |
227 | a = angle go | 235 | viewI = viewInv go |
236 | proj = Cam.projection cam | ||
237 | view = M4.inverseTransform $ Cam.transform cam | ||
238 | transf = S2.transform go | ||
239 | normal = fastNormalMatrix modelview | ||
240 | modelview = case style of | ||
241 | RPG -> view * rpgTransform 0 a axis' (M3.position transf) viewI | ||
242 | PLT -> view * pltTransform transf | ||
228 | in case renderer go of | 243 | in case renderer go of |
229 | Left smr -> | 244 | Left smr -> |
230 | goRender' style a axis' sprog spu mat cam (SM.bind spu smr) (SM.render spu smr) | 245 | goRender' style a axis' sprog spu modelview proj normal |
246 | (SM.bind spu smr) (SM.render spu smr) | ||
231 | Right amr -> | 247 | Right amr -> |
232 | goRender' style a axis' aprog apu mat cam (AM.bind apu amr) (AM.render apu amr) | 248 | goRender' style a axis' aprog apu modelview proj normal |
249 | (AM.bind apu amr) (AM.render apu amr) | ||
233 | 250 | ||
234 | 251 | ||
235 | type Bind = IO () | 252 | type Bind = IO () |
@@ -243,22 +260,19 @@ goRender' :: (ProgramUniforms u, Program p) | |||
243 | -> Vector3 | 260 | -> Vector3 |
244 | -> p | 261 | -> p |
245 | -> u | 262 | -> u |
246 | -> M3.Matrix3 | 263 | -> M4.Matrix4 -- Modelview |
247 | -> Cam.Camera | 264 | -> M4.Matrix4 -- Projection |
265 | -> M3.Matrix3 -- Normal matrix | ||
248 | -> Bind | 266 | -> Bind |
249 | -> Render | 267 | -> Render |
250 | -> IO () | 268 | -> IO () |
251 | goRender' style a axis prog uniforms model cam bindRenderer render = | 269 | goRender' style a axis prog uniforms modelview proj normal bindRenderer render = |
252 | let view = M4.inverseTransform $ Cam.transform cam | 270 | let |
253 | modelview = case style of | ||
254 | RPG -> view * rpgTransform 0 a axis (M3.position model) | ||
255 | PLT -> view * pltTransform model | ||
256 | normalmat = fastNormalMatrix modelview | ||
257 | in do | 271 | in do |
258 | useProgram . program $ prog | 272 | useProgram . program $ prog |
259 | uniformMat4 (projLoc uniforms) $ Cam.projection cam | 273 | uniformMat4 (projLoc uniforms) proj |
260 | uniformMat4 (modelviewLoc uniforms) modelview | 274 | uniformMat4 (modelviewLoc uniforms) modelview |
261 | uniformMat3 (normalmatLoc uniforms) normalmat | 275 | uniformMat3 (normalmatLoc uniforms) normal |
262 | bindRenderer | 276 | bindRenderer |
263 | render | 277 | render |
264 | 278 | ||