indexing description: "[ Collision Detection ]" date: "$Date$" revision: "$Revision$" class COLLISION_DETECTOR create make feature -- Creation make is -- creation procedure do create collision_detector.make (2) end feature -- Access objects_intersecting_rectangle (rect: EM_RECTANGLE_COLLIDABLE): DS_LINKED_LIST [OBJECT] is -- returns a list of objects intersecting with a rectangle local list: DS_LINKED_LIST [OBJECT] cursor1: DS_LINKED_LIST_CURSOR [EM_COLLISION_COMPOSITION [EM_COLLIDABLE]] cursor2: DS_LINKED_LIST_CURSOR [EM_COLLISION [EM_COLLIDABLE]] do collision_detector.empty_set (2) collision_detector.add (rect, 2) collision_detector.check_for_collision create list.make create cursor1.make (collision_detector.last_collisions) from cursor1.start until cursor1.off loop create cursor2.make (cursor1.item) from cursor2.start until cursor2.off loop add_holder_to_list (cursor2.item.collidables.first, list) cursor2.forth end cursor1.forth end Result := list end objects_intersecting_point (pos: EM_VECTOR_2D): DS_LINKED_LIST [OBJECT] is -- returns a list of objects intersecting with a rectangle local c: EM_CIRCLE_COLLIDABLE list: DS_LINKED_LIST [OBJECT] cursor1: DS_LINKED_LIST_CURSOR [EM_COLLISION_COMPOSITION [EM_COLLIDABLE]] cursor2: DS_LINKED_LIST_CURSOR [EM_COLLISION [EM_COLLIDABLE]] do create c.make (pos, 0) collision_detector.empty_set (2) collision_detector.add (c, 2) collision_detector.check_for_collision create list.make create cursor1.make (collision_detector.last_collisions) from cursor1.start until cursor1.off loop create cursor2.make (cursor1.item) from cursor2.start until cursor2.off loop add_holder_to_list (cursor2.item.collidables.first, list) cursor2.forth end cursor1.forth end Result := list end count: INTEGER is -- returns number of elements in the first collision group do Result := collision_detector.sets_of_collidables.item (1).count end feature -- Element Change add (an_object: OBJECT) is -- adds a collidable. require an_object_not_void: an_object /= Void do collision_detector.add (an_object.collidable, 1) end remove (an_object: OBJECT) is -- removes a collidable. require an_object_not_void: an_object /= Void do collision_detector.remove_from_set (an_object.collidable, 1) end feature {NONE} -- Implementation collision_detector: EM_COLLISION_DETECTOR [EM_COLLIDABLE] -- the EM collision detector collidable: EM_COLLIDABLE -- the collidable, whith which collisions are checked add_holder_to_list (a_collidable: EM_COLLIDABLE; list: DS_LINKED_LIST [OBJECT]) is -- adds the holder of a collidable to `list' local obj: OBJECT do obj ?= a_collidable.holder if obj /= Void then list.force_last (obj) end end invariant collision_detector_not_void: collision_detector /= Void end