From 894ada84c5bec9181026817be25eb383b352924f Mon Sep 17 00:00:00 2001 From: Marc Sunet Date: Sat, 1 Sep 2012 16:58:49 +0200 Subject: Made Collisioner an instance of Collisionable --- Spear.lkshw | 4 ++-- Spear/Collision.hs | 23 ++++++++++++++++++++--- Spear/Scene/GameObject.hs | 8 ++------ 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 @@ Version of workspace file format: 1 Time of storage: - "Sat Sep 1 16:13:17 CEST 2012" + "Sat Sep 1 16:50:37 CEST 2012" Name of the workspace: "Spear" File paths of contained packages: ["demos/simple-scene/simple-scene.cabal","Spear.cabal"] Maybe file path of an active package: - Just "demos/simple-scene/simple-scene.cabal" \ No newline at end of file + 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 class Collisionable a where collideBox :: AABB -> a -> CollisionType collideCircle :: Circle -> a -> CollisionType - getBox :: a -> AABB + getAABB :: a -> AABB getCircle :: a -> Circle @@ -59,7 +59,7 @@ instance Collisionable AABB where boxC = min + (max-min)/2 l = norm $ min + (vec2 (x boxC) (y min)) - min - getBox = id + getAABB = id getCircle = circleFromAABB @@ -80,11 +80,28 @@ instance Collisionable Circle where sum_radii = (r1 + r2)^2 sub_radii = (r1 - r2)^2 - getBox = aabbFromCircle + getAABB = aabbFromCircle getCircle = id +instance Collisionable Collisioner where + + collideBox box (AABBCol self) = collideBox box self + collideBox box (CircleCol self) = collideBox box self + + collideCircle circle (AABBCol self) = collideCircle circle self + collideCircle circle (CircleCol self) = collideCircle circle self + + getAABB (AABBCol box) = box + getAABB (CircleCol c) = aabbFromCircle c + + getCircle (AABBCol box) = circleFromAABB box + getCircle (CircleCol c) = c + + + + aabbPoints :: AABB -> [Vector2] aabbPoints (AABB min max) = [p1,p2,p3,p4,p5,p6,p7,p8] 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 = -- | Get the game object's ith bounding box. goAABB :: Int -> GameObject -> AABB -goAABB i go = goAABB' $ (collisioners go) !! i - -goAABB' col = case col of - (AABBCol box) -> box - (CircleCol circle) -> aabbFromCircle circle +goAABB i = getAABB . flip (!!) i . collisioners -- | Get the game object's bounding boxes. goAABBs :: GameObject -> [AABB] -goAABBs = fmap goAABB' . collisioners +goAABBs = fmap getAABB . collisioners -- | Get the game object's 3D transform. -- cgit v1.2.3