aboutsummaryrefslogtreecommitdiff
path: root/Spear/Math/MatrixUtils.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Spear/Math/MatrixUtils.hs')
-rw-r--r--Spear/Math/MatrixUtils.hs21
1 files changed, 13 insertions, 8 deletions
diff --git a/Spear/Math/MatrixUtils.hs b/Spear/Math/MatrixUtils.hs
index 87d84e5..354c840 100644
--- a/Spear/Math/MatrixUtils.hs
+++ b/Spear/Math/MatrixUtils.hs
@@ -32,15 +32,19 @@ rpgTransform
32 :: Float -- ^ The height above the ground 32 :: Float -- ^ The height above the ground
33 -> Float -- ^ Angle of rotation 33 -> Float -- ^ Angle of rotation
34 -> Vector3 -- ^ Axis of rotation 34 -> Vector3 -- ^ Axis of rotation
35 -> Vector2 -- ^ Object's position. 35 -> Vector2 -- ^ Object's position
36 -> Matrix4 -- ^ Inverse view matrix. 36 -> Matrix4 -- ^ Inverse view matrix
37 -> Matrix4 37 -> Matrix4
38rpgTransform h a axis pos viewInverse = 38rpgTransform h a axis pos viewI =
39 let mat' = axisAngle axis a 39 let p1 = viewI `M4.mulp` (vec3 (V2.x pos) (V2.y pos) 0)
40 p2 = viewI `M4.mulp` (vec3 (V2.x pos) (V2.y pos) (-100))
41 lambda = (V3.y p1 / (V3.y p1 - V3.y p2))
42 p = p1 + V3.scale lambda (p2 - p1)
43 mat' = axisAngle axis a
40 r = M4.right mat' 44 r = M4.right mat'
41 u = M4.up mat' 45 u = M4.up mat'
42 f = M4.forward mat' 46 f = M4.forward mat'
43 t = vec3 0 h 0 + vec3 (V2.x pos) 0 (-V2.y pos) 47 t = p + vec3 0 h 0
44 in mat4 48 in mat4
45 (V3.x r) (V3.x u) (V3.x f) (V3.x t) 49 (V3.x r) (V3.x u) (V3.x f) (V3.x t)
46 (V3.y r) (V3.y u) (V3.y f) (V3.y t) 50 (V3.y r) (V3.y u) (V3.y f) (V3.y t)
@@ -71,10 +75,11 @@ rpgInverse
71 :: Float -- ^ The height above the ground 75 :: Float -- ^ The height above the ground
72 -> Float -- ^ Angle of rotation 76 -> Float -- ^ Angle of rotation
73 -> Vector3 -- ^ Axis of rotation 77 -> Vector3 -- ^ Axis of rotation
74 -> Vector2 -- ^ Object's position. 78 -> Vector2 -- ^ Object's position
75 -> Matrix4 -- ^ Inverse view matrix. 79 -> Matrix4 -- ^ Inverse view matrix
76 -> Matrix4 80 -> Matrix4
77rpgInverse h a rot pos viewInv = M4.inverseTransform $ rpgTransform h a rot pos viewInv 81rpgInverse h a axis pos viewI =
82 M4.inverseTransform $ rpgTransform h a axis pos viewI
78 83
79 84
80-- | Map an object's transform in world space to view space. 85-- | Map an object's transform in world space to view space.