From decd9cb7d633e2d31afbeea1c784821b26f0bed6 Mon Sep 17 00:00:00 2001 From: Marc Sunet Date: Sat, 1 Sep 2012 13:15:47 +0200 Subject: Added setRotation to Spatial2 --- Spear.lkshw | 2 +- Spear/Math/Entity.hs | 3 +++ Spear/Math/Spatial2.hs | 3 +++ Spear/Physics/Rigid.hs | 2 ++ Spear/Scene/GameObject.hs | 6 ++++++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Spear.lkshw b/Spear.lkshw index ff27127..0705660 100644 --- a/Spear.lkshw +++ b/Spear.lkshw @@ -1,7 +1,7 @@ Version of workspace file format: 1 Time of storage: - "Sat Sep 1 11:10:35 CEST 2012" + "Sat Sep 1 12:38:49 CEST 2012" Name of the workspace: "Spear" File paths of contained packages: diff --git a/Spear/Math/Entity.hs b/Spear/Math/Entity.hs index f4e6515..2dc6965 100644 --- a/Spear/Math/Entity.hs +++ b/Spear/Math/Entity.hs @@ -21,6 +21,9 @@ instance S.Spatial2 Entity where strafeLeft f ent = ent { transform = M.translv (V.scale (-f) $ S.right ent) * transform ent } strafeRight f ent = ent { transform = M.translv (V.scale f $ S.right ent) * transform ent } rotate a ent = ent { transform = transform ent * M.rot a } + setRotation a ent = + let t = transform ent + in ent { transform = M.translation t * M.rot a } pos = M.position . transform fwd = M.forward . transform up = M.up . transform diff --git a/Spear/Math/Spatial2.hs b/Spear/Math/Spatial2.hs index 51fa050..49ff3b7 100644 --- a/Spear/Math/Spatial2.hs +++ b/Spear/Math/Spatial2.hs @@ -27,6 +27,9 @@ class Spatial2 s where -- | Rotate the spatial. rotate :: Float -> s -> s + -- | Set the spatial's rotation. + setRotation :: Float -> s -> s + -- | Get the spatial position. pos :: s -> Vector2 diff --git a/Spear/Physics/Rigid.hs b/Spear/Physics/Rigid.hs index cc153ec..9147553 100644 --- a/Spear/Physics/Rigid.hs +++ b/Spear/Physics/Rigid.hs @@ -41,6 +41,8 @@ instance Spatial2 RigidBody where rotate angle = id + setRotation angle = id + pos = position fwd _ = unity diff --git a/Spear/Scene/GameObject.hs b/Spear/Scene/GameObject.hs index d3b4e9e..2567e52 100644 --- a/Spear/Scene/GameObject.hs +++ b/Spear/Scene/GameObject.hs @@ -106,6 +106,12 @@ instance S2.Spatial2 GameObject where , angle = (angle go + a) `mod'` 360 } + setRotation a go = + go + { transform = M3.translation (transform go) * M3.rot a + , angle = a + } + pos go = M3.position . transform $ go fwd go = M3.forward . transform $ go -- cgit v1.2.3