From 74f1b41d45994eadb90b0f227b3a5682f43cb8c8 Mon Sep 17 00:00:00 2001 From: Marc Sunet Date: Sat, 1 Sep 2012 18:18:19 +0200 Subject: Added mulp and muld to Matrix3 --- Spear.lkshw | 2 +- Spear/Math/Matrix3.hs | 21 +++++++++++++++++++++ Spear/Scene/Loader.hs | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Spear.lkshw b/Spear.lkshw index 91f4459..ec17604 100644 --- a/Spear.lkshw +++ b/Spear.lkshw @@ -1,7 +1,7 @@ Version of workspace file format: 1 Time of storage: - "Sat Sep 1 16:50:37 CEST 2012" + "Sat Sep 1 18:14:28 CEST 2012" Name of the workspace: "Spear" File paths of contained packages: diff --git a/Spear/Math/Matrix3.hs b/Spear/Math/Matrix3.hs index b295cbd..adc4449 100644 --- a/Spear/Math/Matrix3.hs +++ b/Spear/Math/Matrix3.hs @@ -30,6 +30,8 @@ module Spear.Math.Matrix3 , reflectZ -- * Operations , transpose +, mulp +, muld , mul , inverseTransform , Spear.Math.Matrix3.zipWith @@ -271,6 +273,25 @@ transpose m = mat3 (m00 m) (m01 m) (m02 m) (m10 m) (m11 m) (m12 m) (m20 m) (m21 m) (m22 m) + + +-- | Transform the given point vector in 2D space with the given matrix. +mulp :: Matrix3 -> Vector2 -> Vector2 +mulp m v = vec2 x' y' + where + v' = vec3 (V2.x v) (V2.y v) 1 + x' = row0 m `V3.dot` v' + y' = row1 m `V3.dot` v' + + + +-- | Transform the given directional vector in 2D space with the given matrix. +muld :: Matrix3 -> Vector2 -> Vector2 +muld m v = vec2 x' y' + where + v' = vec3 (V2.x v) (V2.y v) 0 + x' = row0 m `V3.dot` v' + y' = row1 m `V3.dot` v' -- | Transform the given vector in 3D space with the given matrix. diff --git a/Spear/Scene/Loader.hs b/Spear/Scene/Loader.hs index f5d06a6..3bc29fa 100644 --- a/Spear/Scene/Loader.hs +++ b/Spear/Scene/Loader.hs @@ -221,7 +221,7 @@ rotateModel (Rotation x y z order) model = normalMat = fastNormalMatrix mat vTransform (Vec3 x' y' z') = - let v = mat `mulp` (vec3 x' y' z') in Vec3 (V3.x v) (V3.y v) (V3.z v) + let v = mat `M4.mulp` (vec3 x' y' z') in Vec3 (V3.x v) (V3.y v) (V3.z v) nTransform (Vec3 x' y' z') = let v = normalMat `M3.mul` (vec3 x' y' z') in Vec3 (V3.x v) (V3.y v) (V3.z v) -- cgit v1.2.3