diff options
-rw-r--r-- | Spear.lkshw | 4 | ||||
-rw-r--r-- | Spear/Math/MatrixUtils.hs | 13 |
2 files changed, 15 insertions, 2 deletions
diff --git a/Spear.lkshw b/Spear.lkshw index 6587fba..8c102af 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 | "Sun Sep 2 11:06:10 CEST 2012" | 4 | "Sun Sep 2 11:14:26 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 "Spear.cabal" \ No newline at end of file | 10 | Just "demos/simple-scene/simple-scene.cabal" \ No newline at end of file |
diff --git a/Spear/Math/MatrixUtils.hs b/Spear/Math/MatrixUtils.hs index dcc1965..7502234 100644 --- a/Spear/Math/MatrixUtils.hs +++ b/Spear/Math/MatrixUtils.hs | |||
@@ -5,10 +5,12 @@ module Spear.Math.MatrixUtils | |||
5 | , pltTransform | 5 | , pltTransform |
6 | , rpgInverse | 6 | , rpgInverse |
7 | , pltInverse | 7 | , pltInverse |
8 | , toClip | ||
8 | ) | 9 | ) |
9 | where | 10 | where |
10 | 11 | ||
11 | 12 | ||
13 | import Spear.Math.Camera as Cam | ||
12 | import Spear.Math.Matrix3 as M3 | 14 | import Spear.Math.Matrix3 as M3 |
13 | import Spear.Math.Matrix4 as M4 | 15 | import Spear.Math.Matrix4 as M4 |
14 | import Spear.Math.Vector2 as V2 | 16 | import Spear.Math.Vector2 as V2 |
@@ -88,3 +90,14 @@ rpgInverse h a rot = M4.inverseTransform . rpgTransform h a rot | |||
88 | -- Use this in games like platformers and space invaders style games. | 90 | -- Use this in games like platformers and space invaders style games. |
89 | pltInverse :: Matrix3 -> Matrix4 | 91 | pltInverse :: Matrix3 -> Matrix4 |
90 | pltInverse = M4.inverseTransform . pltTransform | 92 | pltInverse = M4.inverseTransform . pltTransform |
93 | |||
94 | |||
95 | -- | Transform an object from object to clip space coordinates. | ||
96 | toClip :: Camera -> Matrix4 -> Vector3 -> Vector2 | ||
97 | toClip cam model p = | ||
98 | let | ||
99 | view = M4.inverseTransform $ Cam.transform cam | ||
100 | proj = Cam.projection cam | ||
101 | p' = (proj * view * model) `M4.mulp` p | ||
102 | in | ||
103 | vec2 (V3.x p') (V3.y p') | ||