diff options
Diffstat (limited to 'Spear/Math/MatrixUtils.hs')
-rw-r--r-- | Spear/Math/MatrixUtils.hs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/Spear/Math/MatrixUtils.hs b/Spear/Math/MatrixUtils.hs index 79bd049..e4273a1 100644 --- a/Spear/Math/MatrixUtils.hs +++ b/Spear/Math/MatrixUtils.hs | |||
@@ -15,6 +15,7 @@ where | |||
15 | import Spear.Math.Camera as Cam | 15 | import Spear.Math.Camera as Cam |
16 | import Spear.Math.Matrix3 as M3 | 16 | import Spear.Math.Matrix3 as M3 |
17 | import Spear.Math.Matrix4 as M4 | 17 | import Spear.Math.Matrix4 as M4 |
18 | import Spear.Math.Spatial3 as S | ||
18 | import Spear.Math.Vector as V | 19 | import Spear.Math.Vector as V |
19 | 20 | ||
20 | 21 | ||
@@ -112,7 +113,7 @@ pltTransform mat = | |||
112 | 113 | ||
113 | 114 | ||
114 | -- | Map an object's transform in world space to view space. | 115 | -- | Map an object's transform in world space to view space. |
115 | -- | 116 | -- |
116 | -- The XY plane in 2D translates to the X(-Z) plane in 3D. | 117 | -- The XY plane in 2D translates to the X(-Z) plane in 3D. |
117 | -- | 118 | -- |
118 | -- Use this in games such as RPGs and RTSs. | 119 | -- Use this in games such as RPGs and RTSs. |
@@ -130,9 +131,9 @@ rpgInverse h a axis pos viewI = | |||
130 | -- | Map an object's transform in world space to view space. | 131 | -- | Map an object's transform in world space to view space. |
131 | -- | 132 | -- |
132 | -- This function maps an object's transform in 2D to the object's inverse in 3D. | 133 | -- This function maps an object's transform in 2D to the object's inverse in 3D. |
133 | -- | 134 | -- |
134 | -- The XY plane in 2D translates to the XY plane in 3D. | 135 | -- The XY plane in 2D translates to the XY plane in 3D. |
135 | -- | 136 | -- |
136 | -- Use this in games like platformers and space invaders style games. | 137 | -- Use this in games like platformers and space invaders style games. |
137 | pltInverse :: Matrix3 -> Matrix4 | 138 | pltInverse :: Matrix3 -> Matrix4 |
138 | pltInverse = M4.inverseTransform . pltTransform | 139 | pltInverse = M4.inverseTransform . pltTransform |
@@ -142,7 +143,7 @@ pltInverse = M4.inverseTransform . pltTransform | |||
142 | objToClip :: Camera -> Matrix4 -> Vector3 -> Vector2 | 143 | objToClip :: Camera -> Matrix4 -> Vector3 -> Vector2 |
143 | objToClip cam model p = | 144 | objToClip cam model p = |
144 | let | 145 | let |
145 | view = M4.inverseTransform $ Cam.transform cam | 146 | view = M4.inverseTransform $ S.transform cam |
146 | proj = Cam.projection cam | 147 | proj = Cam.projection cam |
147 | p' = (proj * view * model) `M4.mulp` p | 148 | p' = (proj * view * model) `M4.mulp` p |
148 | in | 149 | in |