indexing description: "[ The class EM_COLLISION_DETECTOR_3D is used to check whether two EM_COLLIDABLE_3D are collided or not. It is a container. You can add an EM_COLLIDABLE_3D with the command add and remove one with the command remove. If you call check_for_collision the command checks if there is a collision and calls on_collide command of either both of the collided objects if call_both is true or one of the commands otherwise. Make sure, that ALL of the EM_COLLIDABLE_3D objects added to the container are of the same type, because CAT calls are used. ]" date: "$Date$" revision: "$Revision$" class EM_COLLISION_DETECTOR_3D create make feature {NONE} -- Initialization make is -- Create a ESDL_COLLISION_DETECTOR do create collidable_list.make call_both := true ensure call_both_true: call_both = true end feature -- Status call_both: BOOLEAN -- Are both on_collide routines called if two elements collide or only one of them? set_call_both (b: BOOLEAN) is -- Sets `call_both' to `b' do call_both := b ensure set: call_both = b end feature -- Commands add (a_collidable: EM_COLLIDABLE_3D) is -- Adds `a_collidable' to test it for collision with the all other elements require a_collidable_not_void: a_collidable /= void do collidable_list.put_last (a_collidable) end remove (a_collidable: EM_COLLIDABLE_3D ) is -- Removes `a_collidable' require a_collidable_not_void: a_collidable /= void do collidable_list.delete (a_collidable) end check_for_collision is -- Checks if any element collides with any other element O(n*(n-1)*(n-2)*...*1) -- If so calls both on_collide if `call_both' is true or any of them if not. local cursor1, cursor2: DS_LINKED_LIST_CURSOR [EM_COLLIDABLE_3D] do create cursor1.make (collidable_list) create cursor2.make (collidable_list) from cursor1.start until cursor1.off loop from cursor2.go_to (cursor1) cursor2.forth until cursor2.off loop if cursor1.item.does_collide (cursor2.item) then cursor1.item.on_collide (cursor2.item) if call_both then cursor2.item.on_collide (cursor1.item) end end cursor2.forth end cursor1.forth end end feature {NONE} -- Implementation collidable_list: DS_LINKED_LIST [EM_COLLIDABLE_3D] -- The list containing all the ESDL_COLLIDABLE tested for collision end