aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Spear.lkshw4
-rw-r--r--Spear/Collision.hs23
-rw-r--r--Spear/Scene/GameObject.hs8
3 files changed, 24 insertions, 11 deletions
diff --git a/Spear.lkshw b/Spear.lkshw
index 3191249..91f4459 100644
--- a/Spear.lkshw
+++ b/Spear.lkshw
@@ -1,10 +1,10 @@
1Version of workspace file format: 1Version of workspace file format:
2 1 2 1
3Time of storage: 3Time of storage:
4 "Sat Sep 1 16:13:17 CEST 2012" 4 "Sat Sep 1 16:50:37 CEST 2012"
5Name of the workspace: 5Name of the workspace:
6 "Spear" 6 "Spear"
7File paths of contained packages: 7File paths of contained packages:
8 ["demos/simple-scene/simple-scene.cabal","Spear.cabal"] 8 ["demos/simple-scene/simple-scene.cabal","Spear.cabal"]
9Maybe file path of an active package: 9Maybe file path of an active package:
10 Just "demos/simple-scene/simple-scene.cabal" \ No newline at end of file 10 Just "Spear.cabal" \ No newline at end of file
diff --git a/Spear/Collision.hs b/Spear/Collision.hs
index 31187c9..9c538ae 100644
--- a/Spear/Collision.hs
+++ b/Spear/Collision.hs
@@ -33,7 +33,7 @@ data CollisionType = NoCollision | Collision | FullyContains | FullyContainedBy
33class Collisionable a where 33class Collisionable a where
34 collideBox :: AABB -> a -> CollisionType 34 collideBox :: AABB -> a -> CollisionType
35 collideCircle :: Circle -> a -> CollisionType 35 collideCircle :: Circle -> a -> CollisionType
36 getBox :: a -> AABB 36 getAABB :: a -> AABB
37 getCircle :: a -> Circle 37 getCircle :: a -> Circle
38 38
39 39
@@ -59,7 +59,7 @@ instance Collisionable AABB where
59 boxC = min + (max-min)/2 59 boxC = min + (max-min)/2
60 l = norm $ min + (vec2 (x boxC) (y min)) - min 60 l = norm $ min + (vec2 (x boxC) (y min)) - min
61 61
62 getBox = id 62 getAABB = id
63 63
64 getCircle = circleFromAABB 64 getCircle = circleFromAABB
65 65
@@ -80,11 +80,28 @@ instance Collisionable Circle where
80 sum_radii = (r1 + r2)^2 80 sum_radii = (r1 + r2)^2
81 sub_radii = (r1 - r2)^2 81 sub_radii = (r1 - r2)^2
82 82
83 getBox = aabbFromCircle 83 getAABB = aabbFromCircle
84 84
85 getCircle = id 85 getCircle = id
86 86
87 87
88instance Collisionable Collisioner where
89
90 collideBox box (AABBCol self) = collideBox box self
91 collideBox box (CircleCol self) = collideBox box self
92
93 collideCircle circle (AABBCol self) = collideCircle circle self
94 collideCircle circle (CircleCol self) = collideCircle circle self
95
96 getAABB (AABBCol box) = box
97 getAABB (CircleCol c) = aabbFromCircle c
98
99 getCircle (AABBCol box) = circleFromAABB box
100 getCircle (CircleCol c) = c
101
102
103
104
88aabbPoints :: AABB -> [Vector2] 105aabbPoints :: AABB -> [Vector2]
89aabbPoints (AABB min max) = [p1,p2,p3,p4,p5,p6,p7,p8] 106aabbPoints (AABB min max) = [p1,p2,p3,p4,p5,p6,p7,p8]
90 where 107 where
diff --git a/Spear/Scene/GameObject.hs b/Spear/Scene/GameObject.hs
index 30e7d5e..b892b7d 100644
--- a/Spear/Scene/GameObject.hs
+++ b/Spear/Scene/GameObject.hs
@@ -167,16 +167,12 @@ goUpdate dt go =
167 167
168-- | Get the game object's ith bounding box. 168-- | Get the game object's ith bounding box.
169goAABB :: Int -> GameObject -> AABB 169goAABB :: Int -> GameObject -> AABB
170goAABB i go = goAABB' $ (collisioners go) !! i 170goAABB i = getAABB . flip (!!) i . collisioners
171
172goAABB' col = case col of
173 (AABBCol box) -> box
174 (CircleCol circle) -> aabbFromCircle circle
175 171
176 172
177-- | Get the game object's bounding boxes. 173-- | Get the game object's bounding boxes.
178goAABBs :: GameObject -> [AABB] 174goAABBs :: GameObject -> [AABB]
179goAABBs = fmap goAABB' . collisioners 175goAABBs = fmap getAABB . collisioners
180 176
181 177
182-- | Get the game object's 3D transform. 178-- | Get the game object's 3D transform.