diff options
Diffstat (limited to 'Spear/Math/MatrixUtils.hs')
-rw-r--r-- | Spear/Math/MatrixUtils.hs | 13 |
1 files changed, 13 insertions, 0 deletions
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') | ||