aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Sunet <jeannekamikaze@gmail.com>2012-09-01 13:15:47 +0200
committerMarc Sunet <jeannekamikaze@gmail.com>2012-09-01 13:15:47 +0200
commitdecd9cb7d633e2d31afbeea1c784821b26f0bed6 (patch)
treedbd36db1bbe7696ae550313386190f2961da24ab
parent48bcc15a9971368c232bd800493cbf688958bb08 (diff)
Added setRotation to Spatial2
-rw-r--r--Spear.lkshw2
-rw-r--r--Spear/Math/Entity.hs3
-rw-r--r--Spear/Math/Spatial2.hs3
-rw-r--r--Spear/Physics/Rigid.hs2
-rw-r--r--Spear/Scene/GameObject.hs6
5 files changed, 15 insertions, 1 deletions
diff --git a/Spear.lkshw b/Spear.lkshw
index ff27127..0705660 100644
--- a/Spear.lkshw
+++ b/Spear.lkshw
@@ -1,7 +1,7 @@
1Version of workspace file format: 1Version of workspace file format:
2 1 2 1
3Time of storage: 3Time of storage:
4 "Sat Sep 1 11:10:35 CEST 2012" 4 "Sat Sep 1 12:38:49 CEST 2012"
5Name of the workspace: 5Name of the workspace:
6 "Spear" 6 "Spear"
7File paths of contained packages: 7File 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
21 strafeLeft f ent = ent { transform = M.translv (V.scale (-f) $ S.right ent) * transform ent } 21 strafeLeft f ent = ent { transform = M.translv (V.scale (-f) $ S.right ent) * transform ent }
22 strafeRight f ent = ent { transform = M.translv (V.scale f $ S.right ent) * transform ent } 22 strafeRight f ent = ent { transform = M.translv (V.scale f $ S.right ent) * transform ent }
23 rotate a ent = ent { transform = transform ent * M.rot a } 23 rotate a ent = ent { transform = transform ent * M.rot a }
24 setRotation a ent =
25 let t = transform ent
26 in ent { transform = M.translation t * M.rot a }
24 pos = M.position . transform 27 pos = M.position . transform
25 fwd = M.forward . transform 28 fwd = M.forward . transform
26 up = M.up . transform 29 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
27 -- | Rotate the spatial. 27 -- | Rotate the spatial.
28 rotate :: Float -> s -> s 28 rotate :: Float -> s -> s
29 29
30 -- | Set the spatial's rotation.
31 setRotation :: Float -> s -> s
32
30 -- | Get the spatial position. 33 -- | Get the spatial position.
31 pos :: s -> Vector2 34 pos :: s -> Vector2
32 35
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
41 41
42 rotate angle = id 42 rotate angle = id
43 43
44 setRotation angle = id
45
44 pos = position 46 pos = position
45 47
46 fwd _ = unity 48 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
106 , angle = (angle go + a) `mod'` 360 106 , angle = (angle go + a) `mod'` 360
107 } 107 }
108 108
109 setRotation a go =
110 go
111 { transform = M3.translation (transform go) * M3.rot a
112 , angle = a
113 }
114
109 pos go = M3.position . transform $ go 115 pos go = M3.position . transform $ go
110 116
111 fwd go = M3.forward . transform $ go 117 fwd go = M3.forward . transform $ go