From 72b93bbaaa0219f1161448b3e6136b795b0f2041 Mon Sep 17 00:00:00 2001 From: Marc Sunet Date: Sun, 2 Sep 2012 11:14:40 +0200 Subject: Added toClip --- Spear.lkshw | 4 ++-- 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 @@ Version of workspace file format: 1 Time of storage: - "Sun Sep 2 11:06:10 CEST 2012" + "Sun Sep 2 11:14:26 CEST 2012" Name of the workspace: "Spear" File paths of contained packages: ["demos/simple-scene/simple-scene.cabal","Spear.cabal"] Maybe file path of an active package: - Just "Spear.cabal" \ No newline at end of file + 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 , pltTransform , rpgInverse , pltInverse +, toClip ) where +import Spear.Math.Camera as Cam import Spear.Math.Matrix3 as M3 import Spear.Math.Matrix4 as M4 import Spear.Math.Vector2 as V2 @@ -88,3 +90,14 @@ rpgInverse h a rot = M4.inverseTransform . rpgTransform h a rot -- Use this in games like platformers and space invaders style games. pltInverse :: Matrix3 -> Matrix4 pltInverse = M4.inverseTransform . pltTransform + + +-- | Transform an object from object to clip space coordinates. +toClip :: Camera -> Matrix4 -> Vector3 -> Vector2 +toClip cam model p = + let + view = M4.inverseTransform $ Cam.transform cam + proj = Cam.projection cam + p' = (proj * view * model) `M4.mulp` p + in + vec2 (V3.x p') (V3.y p') -- cgit v1.2.3