diff options
author | Marc Sunet <jeannekamikaze@gmail.com> | 2012-09-08 12:39:14 +0200 |
---|---|---|
committer | Marc Sunet <jeannekamikaze@gmail.com> | 2012-09-08 12:39:14 +0200 |
commit | 56540ac3ca48cc77da0e86389fe550ede1c1081e (patch) | |
tree | f0653ec6cc8fc879957eb67cabd9126f8d8c6c5e | |
parent | 87dc898eb8c93e402738fcc13bb2a234c3e5c351 (diff) |
Fixed 3d rotation; added rpgUnproject
-rw-r--r-- | Spear.lkshs | 12 | ||||
-rw-r--r-- | Spear.lkshw | 4 | ||||
-rw-r--r-- | Spear/Math/MatrixUtils.hs | 48 | ||||
-rw-r--r-- | Spear/Scene/GameObject.hs | 70 |
4 files changed, 104 insertions, 30 deletions
diff --git a/Spear.lkshs b/Spear.lkshs index 3af403b..2c83290 100644 --- a/Spear.lkshs +++ b/Spear.lkshs | |||
@@ -1,18 +1,18 @@ | |||
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 Sep 7 14:26:09 CEST 2012" | 4 | "Sat Sep 8 12:03:07 CEST 2012" |
5 | Layout: VerticalP (TerminalP {paneGroups = fromList [], paneTabs = Just TopP, currentPage = 6, 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}) 350) 153),("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}) 239)], paneTabs = Just BottomP, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 640) 954 | 5 | 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}) 335) 148),("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}) 234)], paneTabs = Just BottomP, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 621) 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" 0)),[SplitP LeftP]),(Just (FilesSt FilesState),[SplitP RightP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Scene/GameObject.hs" 46)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject.hs" 39)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameState.hs" 1011)),[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" 616)),[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" 611)),[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 (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" 4966)),[SplitP LeftP])] | 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" 1138)),[SplitP LeftP]),(Just (FilesSt FilesState),[SplitP RightP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Scene/GameObject.hs" 3926)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject.hs" 39)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameState.hs" 1011)),[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" 2151)),[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" 2818)),[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 (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" 4399)),[SplitP LeftP])] |
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 "main.hs" | 11 | Active pane: Just "Factory.hs" |
12 | Toolbar visible: | 12 | Toolbar visible: |
13 | True | 13 | True |
14 | FindbarState: (False,FindState {entryStr = "Sphere", entryHist = ["Sphere","boxFrom","sphere","asdad","m[15]","m[14]","m[1]","m[13]","m[12]","m[11]","m[10]","m[9]"], replaceStr = "a01", replaceHist = [], caseSensitive = True, entireWord = False, wrapAround = False, regex = False, lineNr = 1}) | 14 | FindbarState: (False,FindState {entryStr = "asdads", entryHist = ["asdads","let scene","scene","Sphere","boxFrom","sphere","m[15]","m[14]","m[1]","m[13]","m[12]","m[11]"], 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/AnimatedGO.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/StaticGO.hs","/home/jeanne/programming/haskell/Spear/Spear/Math/Vector2.hs","/home/jeanne/programming/haskell/Spear/Spear/Render/StaticModel.hs","/home/jeanne/programming/haskell/Spear/Spear/Render/AnimatedModel.hs","/home/jeanne/programming/haskell/Spear/Spear/Collision.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/main.hs","/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"] | 16 | ["/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject.hs","/home/jeanne/programming/haskell/Spear/Spear/Math/Matrix4.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/AnimatedGO.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/StaticGO.hs","/home/jeanne/programming/haskell/Spear/Spear/Math/Vector2.hs","/home/jeanne/programming/haskell/Spear/Spear/Render/StaticModel.hs","/home/jeanne/programming/haskell/Spear/Spear/Render/AnimatedModel.hs","/home/jeanne/programming/haskell/Spear/Spear/Collision.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/main.hs","/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"] |
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 cc2deed..b2416a3 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 Sep 7 17:11:58 CEST 2012" | 4 | "Sat Sep 8 12:34:51 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 354c840..629b73c 100644 --- a/Spear/Math/MatrixUtils.hs +++ b/Spear/Math/MatrixUtils.hs | |||
@@ -1,6 +1,8 @@ | |||
1 | module Spear.Math.MatrixUtils | 1 | module Spear.Math.MatrixUtils |
2 | ( | 2 | ( |
3 | fastNormalMatrix | 3 | fastNormalMatrix |
4 | , unproject | ||
5 | , rpgUnproject | ||
4 | , rpgTransform | 6 | , rpgTransform |
5 | , pltTransform | 7 | , pltTransform |
6 | , rpgInverse | 8 | , rpgInverse |
@@ -27,6 +29,50 @@ fastNormalMatrix m = | |||
27 | (M4.m02 m') (M4.m12 m') (M4.m22 m') | 29 | (M4.m02 m') (M4.m12 m') (M4.m22 m') |
28 | 30 | ||
29 | 31 | ||
32 | -- | Transform the given point in window coordinates to object coordinates. | ||
33 | unproject :: Matrix4 -- ^ Inverse projection matrix | ||
34 | -> Matrix4 -- ^ Inverse modelview matrix. | ||
35 | -> Float -- ^ Viewport x | ||
36 | -> Float -- ^ Viewport y | ||
37 | -> Float -- ^ Viewport width | ||
38 | -> Float -- ^ Viewport height | ||
39 | -> Float -- ^ Window x | ||
40 | -> Float -- ^ Window y | ||
41 | -> Float -- ^ Window z | ||
42 | -> V3.Vector3 | ||
43 | unproject projI modelviewI vpx vpy w h x y z = | ||
44 | let | ||
45 | xmouse = 2*(x-vpx)/w - 1 | ||
46 | ymouse = 2*(y-vpy)/h - 1 | ||
47 | zmouse = 2*z - 1 | ||
48 | in | ||
49 | (modelviewI * projI) `M4.mulp` V3.vec3 xmouse ymouse zmouse | ||
50 | |||
51 | |||
52 | -- | Transform the given point in window coordinates to 2d coordinates. | ||
53 | -- | ||
54 | -- The line defined by the given point in window space is intersected with | ||
55 | -- the XZ plane in world space to yield the resulting 2d point. | ||
56 | rpgUnproject | ||
57 | :: Matrix4 -- ^ Inverse projection matrix | ||
58 | -> Matrix4 -- ^ Inverse viewI matrix. | ||
59 | -> Float -- ^ Viewport x | ||
60 | -> Float -- ^ Viewport y | ||
61 | -> Float -- ^ Viewport width | ||
62 | -> Float -- ^ Viewport height | ||
63 | -> Float -- ^ Window x | ||
64 | -> Float -- ^ Window y | ||
65 | -> Vector2 | ||
66 | rpgUnproject projI viewI vpx vpy w h x y = | ||
67 | let | ||
68 | p1 = unproject projI viewI vpx vpy w h x y 0 | ||
69 | p2 = unproject projI viewI vpx vpy w h x y (-1) | ||
70 | lambda = (V3.y p1 / (V3.y p1 - V3.y p2)) | ||
71 | p' = p1 + V3.scale lambda (p2 - p1) | ||
72 | in | ||
73 | vec2 (V3.x p') (-V3.z p') | ||
74 | |||
75 | |||
30 | -- | Map an object's transform in view space to world space. | 76 | -- | Map an object's transform in view space to world space. |
31 | rpgTransform | 77 | rpgTransform |
32 | :: Float -- ^ The height above the ground | 78 | :: Float -- ^ The height above the ground |
@@ -37,7 +83,7 @@ rpgTransform | |||
37 | -> Matrix4 | 83 | -> Matrix4 |
38 | rpgTransform h a axis pos viewI = | 84 | rpgTransform h a axis pos viewI = |
39 | let p1 = viewI `M4.mulp` (vec3 (V2.x pos) (V2.y pos) 0) | 85 | let p1 = viewI `M4.mulp` (vec3 (V2.x pos) (V2.y pos) 0) |
40 | p2 = viewI `M4.mulp` (vec3 (V2.x pos) (V2.y pos) (-100)) | 86 | p2 = viewI `M4.mulp` (vec3 (V2.x pos) (V2.y pos) (-1)) |
41 | lambda = (V3.y p1 / (V3.y p1 - V3.y p2)) | 87 | lambda = (V3.y p1 / (V3.y p1 - V3.y p2)) |
42 | p = p1 + V3.scale lambda (p2 - p1) | 88 | p = p1 + V3.scale lambda (p2 - p1) |
43 | mat' = axisAngle axis a | 89 | mat' = axisAngle axis a |
diff --git a/Spear/Scene/GameObject.hs b/Spear/Scene/GameObject.hs index 53a03b5..a43a2a4 100644 --- a/Spear/Scene/GameObject.hs +++ b/Spear/Scene/GameObject.hs | |||
@@ -2,6 +2,7 @@ module Spear.Scene.GameObject | |||
2 | ( | 2 | ( |
3 | GameObject | 3 | GameObject |
4 | , GameStyle(..) | 4 | , GameStyle(..) |
5 | , Window(..) | ||
5 | , AM.AnimationSpeed | 6 | , AM.AnimationSpeed |
6 | -- * Construction | 7 | -- * Construction |
7 | , goNew | 8 | , goNew |
@@ -13,6 +14,7 @@ module Spear.Scene.GameObject | |||
13 | , goRPGtransform | 14 | , goRPGtransform |
14 | , numCollisioners | 15 | , numCollisioners |
15 | , renderer | 16 | , renderer |
17 | , window | ||
16 | -- * Manipulation | 18 | -- * Manipulation |
17 | , goUpdate | 19 | , goUpdate |
18 | , setAnimation | 20 | , setAnimation |
@@ -20,7 +22,7 @@ module Spear.Scene.GameObject | |||
20 | , setAxis | 22 | , setAxis |
21 | , withCollisioners | 23 | , withCollisioners |
22 | , setCollisioners | 24 | , setCollisioners |
23 | , setViewInverse | 25 | , setWindow |
24 | -- * Rendering | 26 | -- * Rendering |
25 | , goRender | 27 | , goRender |
26 | -- * Collision | 28 | -- * Collision |
@@ -53,15 +55,28 @@ data GameStyle | |||
53 | | PLT -- ^ Platformer or space invaders style game. | 55 | | PLT -- ^ Platformer or space invaders style game. |
54 | 56 | ||
55 | 57 | ||
58 | data Window = Window | ||
59 | { projInv :: !M4.Matrix4 | ||
60 | , viewInv :: !M4.Matrix4 | ||
61 | , vpx :: !Float | ||
62 | , vpy :: !Float | ||
63 | , width :: !Float | ||
64 | , height :: !Float | ||
65 | } | ||
66 | |||
67 | |||
68 | dummyWindow = Window M4.id M4.id 0 0 640 480 | ||
69 | |||
70 | |||
56 | -- | An object in the game scene. | 71 | -- | An object in the game scene. |
57 | data GameObject = GameObject | 72 | data GameObject = GameObject |
58 | { gameStyle :: !GameStyle | 73 | { gameStyle :: !GameStyle |
59 | , renderer :: !(Either StaticModelRenderer AM.AnimatedModelRenderer) | 74 | , renderer :: !(Either StaticModelRenderer AM.AnimatedModelRenderer) |
60 | , collisioners :: ![Collisioner] | 75 | , collisioners :: ![Collisioner] |
61 | , transform :: !M3.Matrix3 | 76 | , transform :: !M3.Matrix3 |
62 | , axis :: Vector3 | 77 | , axis :: !Vector3 |
63 | , angle :: Float | 78 | , angle :: !Float |
64 | , viewInv :: !M4.Matrix4 | 79 | , window :: !Window -- ^ Get the game object's window. |
65 | } | 80 | } |
66 | 81 | ||
67 | 82 | ||
@@ -133,17 +148,28 @@ instance S2.Spatial2 GameObject where | |||
133 | in go { transform = M3.transform (M3.right m) (M3.forward m) pos } | 148 | in go { transform = M3.transform (M3.right m) (M3.forward m) pos } |
134 | 149 | ||
135 | lookAt p go = | 150 | lookAt p go = |
136 | let position = S2.pos go | 151 | let position = S2.pos go |
137 | fwd = V2.normalise $ p - position | 152 | fwd = V2.normalise $ p - position |
138 | r = perp fwd | 153 | r = perp fwd |
139 | toDeg = (*(180/pi)) | 154 | toDeg = (*(180/pi)) |
155 | wnd = window go | ||
156 | viewI = viewInv wnd | ||
157 | vpx' = vpx wnd | ||
158 | vpy' = vpy wnd | ||
159 | w = width wnd | ||
160 | h = height wnd | ||
161 | p1' = position | ||
162 | p2' = position + fwd | ||
163 | p1 = rpgUnproject M4.id viewI vpx' vpy' w h (V2.x p1') (V2.y p1') | ||
164 | p2 = rpgUnproject M4.id viewI vpx' vpy' w h (V2.x p2') (V2.y p2') | ||
165 | f = V2.normalise $ p2 - p1 | ||
140 | in | 166 | in |
141 | go | 167 | go |
142 | { transform = M3.transform r fwd position | 168 | { transform = M3.transform r fwd position |
143 | , angle = (-180) + | 169 | , angle = 180 - |
144 | if V2.y r > 0 | 170 | if V2.x f > 0 |
145 | then toDeg . acos $ r `V2.dot` V2.unitx | 171 | then toDeg . acos $ f `V2.dot` V2.unity |
146 | else (+180) . toDeg . acos $ r `V2.dot` (-V2.unitx) | 172 | else (+180) . toDeg . acos $ f `V2.dot` (-V2.unity) |
147 | } | 173 | } |
148 | 174 | ||
149 | 175 | ||
@@ -155,11 +181,11 @@ goNew :: GameStyle | |||
155 | -> Vector3 -- ^ Axis of rotation | 181 | -> Vector3 -- ^ Axis of rotation |
156 | -> GameObject | 182 | -> GameObject |
157 | 183 | ||
158 | goNew style (Left smr) cols transf axis = | 184 | goNew style (Left smr) cols transf axis = GameObject |
159 | GameObject style (Left $ SM.staticModelRenderer smr) cols transf axis 0 M4.id | 185 | style (Left $ SM.staticModelRenderer smr) cols transf axis 0 dummyWindow |
160 | 186 | ||
161 | goNew style (Right amr) cols transf axis = | 187 | goNew style (Right amr) cols transf axis = GameObject |
162 | GameObject style (Right $ AM.animatedModelRenderer 1 amr) cols transf axis 0 M4.id | 188 | style (Right $ AM.animatedModelRenderer 1 amr) cols transf axis 0 dummyWindow |
163 | 189 | ||
164 | 190 | ||
165 | goUpdate :: Float -> GameObject -> GameObject | 191 | goUpdate :: Float -> GameObject -> GameObject |
@@ -185,7 +211,9 @@ goAABBs = fmap getAABB . collisioners | |||
185 | 211 | ||
186 | -- | Get the game object's 3D transform. | 212 | -- | Get the game object's 3D transform. |
187 | goRPGtransform :: GameObject -> M4.Matrix4 | 213 | goRPGtransform :: GameObject -> M4.Matrix4 |
188 | goRPGtransform go = rpgTransform 0 (angle go) (axis go) (S2.pos go) (viewInv go) | 214 | goRPGtransform go = |
215 | let viewI = viewInv . window $ go | ||
216 | in rpgTransform 0 (angle go) (axis go) (S2.pos go) viewI | ||
189 | 217 | ||
190 | 218 | ||
191 | -- | Get the game object's current animation. | 219 | -- | Get the game object's current animation. |
@@ -224,9 +252,9 @@ setCollisioners :: GameObject -> [Collisioner] -> GameObject | |||
224 | setCollisioners go cols = go { collisioners = cols } | 252 | setCollisioners go cols = go { collisioners = cols } |
225 | 253 | ||
226 | 254 | ||
227 | -- | Set the game object's view inverse matrix. | 255 | -- | Set the game object's window. |
228 | setViewInverse :: M4.Matrix4 -> GameObject -> GameObject | 256 | setWindow :: Window -> GameObject -> GameObject |
229 | setViewInverse mat go = go { viewInv = mat } | 257 | setWindow wnd go = go { window = wnd } |
230 | 258 | ||
231 | 259 | ||
232 | -- | Manipulate the game object's collisioners. | 260 | -- | Manipulate the game object's collisioners. |
@@ -242,7 +270,7 @@ goRender sprog aprog cam go = | |||
242 | style = gameStyle go | 270 | style = gameStyle go |
243 | axis' = axis go | 271 | axis' = axis go |
244 | a = angle go | 272 | a = angle go |
245 | viewI = viewInv go | 273 | viewI = viewInv . window $ go |
246 | proj = Cam.projection cam | 274 | proj = Cam.projection cam |
247 | view = M4.inverseTransform $ Cam.transform cam | 275 | view = M4.inverseTransform $ Cam.transform cam |
248 | transf = S2.transform go | 276 | transf = S2.transform go |