From a2946c79640a9e811db2b976ba6401da9fe1b88e Mon Sep 17 00:00:00 2001 From: Marc Sunet Date: Wed, 29 Aug 2012 13:08:26 +0200 Subject: Changed Octree to QuadTree --- Spear.lkshw | 4 ++-- Spear/Scene/Scene.hs | 29 +++++++++-------------------- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/Spear.lkshw b/Spear.lkshw index a945bab..3c4b807 100644 --- a/Spear.lkshw +++ b/Spear.lkshw @@ -1,10 +1,10 @@ Version of workspace file format: 1 Time of storage: - "Wed Aug 29 12:27:48 CEST 2012" + "Wed Aug 29 13:08:08 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 "Spear.cabal" \ No newline at end of file + Just "demos/simple-scene/simple-scene.cabal" \ No newline at end of file diff --git a/Spear/Scene/Scene.hs b/Spear/Scene/Scene.hs index 4658ddb..0dfa459 100644 --- a/Spear/Scene/Scene.hs +++ b/Spear/Scene/Scene.hs @@ -1,7 +1,4 @@ module Spear.Scene.Scene -where - -{-module Spear.Scene.Scene ( -- * Data types Scene @@ -9,7 +6,6 @@ where , listScene -- * Insertion and deletion , add -, addl , remove , Spear.Scene.Scene.filter -- * Queries @@ -27,7 +23,7 @@ where import Spear.Collision.Types import Spear.Game (Game) import Spear.Math.AABB -import Spear.Math.Octree as Octree +import Spear.Math.QuadTree as QT import Control.Applicative ((<*>)) import Control.Monad (foldM) @@ -41,9 +37,9 @@ data Scene obj = { objects :: ![obj] } | - OctreeScene + QuadTreeScene { collideAABB :: obj -> AABB -> CollisionType - , world :: !(Octree obj) + , world :: !(QuadTree obj) } @@ -57,16 +53,10 @@ listScene = ListScene --octreeScene collide getAABB objs = OctreeScene [] collide $ makeOctree --- | Add a game object to the given 'Scene'. -add :: Scene obj -> obj -> Scene obj -add (scene@ListScene {}) o = scene { objects = o : objects scene } -add (scene@OctreeScene {}) o = scene { world = insert (collideAABB scene) (world scene) o } - - -- | Add a list of game objects to the given 'Scene'. -addl :: Scene obj -> [obj] -> Scene obj -addl (scene@ListScene {}) l = scene { objects = l ++ objects scene } -addl (scene@OctreeScene {}) l = scene { world = insertl (collideAABB scene) (world scene) l } +add :: Scene obj -> [obj] -> Scene obj +add (scene@ListScene {}) l = scene { objects = l ++ objects scene } +add (scene@QuadTreeScene {}) l = scene { world = QT.insert (collideAABB scene) (world scene) l } -- | Remove a game object from the given 'Scene'. @@ -91,7 +81,7 @@ type Update obj = obj -> obj -- | Update the given scene. update :: (obj -> obj) -> Scene obj -> Scene obj update updt (scene@ListScene {}) = scene { objects = fmap updt $ objects scene } -update updt (scene@OctreeScene {}) = scene { world = Octree.map (collideAABB scene) updt $ world scene } +update updt (scene@QuadTreeScene {}) = scene { world = QT.map (collideAABB scene) updt $ world scene } -- | Update the given scene. @@ -116,7 +106,7 @@ collide col scene@ListScene {} = in scene { objects = objs' } -collide col scene@OctreeScene {} = +collide col scene@QuadTreeScene {} = scene { world = gmap (collideAABB scene) col $ world scene } @@ -152,5 +142,4 @@ collide' col scene@ListScene {} = -- | Render the given 'Scene'. render :: (obj -> Game s ()) -> Scene obj -> Game s () render rend (scene@ListScene {}) = Prelude.mapM_ rend $ objects scene -render rend (scene@OctreeScene {}) = F.mapM_ rend $ world scene --} \ No newline at end of file +render rend (scene@QuadTreeScene {}) = F.mapM_ rend $ world scene -- cgit v1.2.3