aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Sunet <jeannekamikaze@gmail.com>2012-09-02 11:14:40 +0200
committerMarc Sunet <jeannekamikaze@gmail.com>2012-09-02 11:14:40 +0200
commit72b93bbaaa0219f1161448b3e6136b795b0f2041 (patch)
tree14e927a429d47de4b2b014d8434f41dc94674813
parentc1f51f44b39b6044ed3bf19acffdb9ae1884dcc6 (diff)
Added toClip
-rw-r--r--Spear.lkshw4
-rw-r--r--Spear/Math/MatrixUtils.hs13
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 @@
1Version of workspace file format: 1Version of workspace file format:
2 1 2 1
3Time of storage: 3Time of storage:
4 "Sun Sep 2 11:06:10 CEST 2012" 4 "Sun Sep 2 11:14:26 CEST 2012"
5Name of the workspace: 5Name of the workspace:
6 "Spear" 6 "Spear"
7File paths of contained packages: 7File paths of contained packages:
8 ["demos/simple-scene/simple-scene.cabal","Spear.cabal"] 8 ["demos/simple-scene/simple-scene.cabal","Spear.cabal"]
9Maybe file path of an active package: 9Maybe 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)
9where 10where
10 11
11 12
13import Spear.Math.Camera as Cam
12import Spear.Math.Matrix3 as M3 14import Spear.Math.Matrix3 as M3
13import Spear.Math.Matrix4 as M4 15import Spear.Math.Matrix4 as M4
14import Spear.Math.Vector2 as V2 16import 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.
89pltInverse :: Matrix3 -> Matrix4 91pltInverse :: Matrix3 -> Matrix4
90pltInverse = M4.inverseTransform . pltTransform 92pltInverse = M4.inverseTransform . pltTransform
93
94
95-- | Transform an object from object to clip space coordinates.
96toClip :: Camera -> Matrix4 -> Vector3 -> Vector2
97toClip 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')