indexing description: "[ exports to eiffel collision detection code. ]" date: "$Date$" revision: "$Revision$" class EXPORT_TO_EIFFEL_COLLISION_DETECTION inherit EXPORTER create make feature -- Access name: STRING is "Eiffel code for Collision Detection" -- name of the exporter feature -- Computation scene_to_string: STRING is -- returns a string of the scenes information. -- used to save scenes. local i: INTEGER c: CIRCLE r: RECTANGLE po: POLYGON co: EM_COLLIDABLE_COMPOSITION po_co: EM_POLYGON_CONVEX_COLLIDABLE first_run: BOOLEAN do Result := "-- Collision Detection source file for EiffelMedia%N%N" Result.append ("local%N") from scene.circles.start i := 1 until scene.circles.off loop Result.append ("circle"+i.out+", ") scene.circles.forth i := i + 1 end if i > 1 then Result.remove_tail (2) Result.append (": EM_CIRCLE_COLLIDABLE%N") end from scene.rectangles.start i := 1 until scene.rectangles.off loop Result.append ("rectangle"+i.out+", ") scene.rectangles.forth i := i + 1 end if i > 1 then Result.remove_tail (2) Result.append (": EM_RECTANGLE_COLLIDABLE%N") end if scene.polygons.count > 0 then Result.append ("vector_list: DS_LINKED_LIST [EM_VECTOR_2D]%N") end from scene.polygons.start i := 1 until scene.polygons.off loop if scene.polygons.item_for_iteration.is_collidable_valid and then scene.polygons.item_for_iteration.collidable.count = 1 then Result.append ("polygon"+i.out+", ") i := i + 1 end scene.polygons.forth end if i > 1 then Result.remove_tail (2) Result.append (": EM_POLYGON_CONVEX_COLLIDABLE%N") end from scene.polygons.start i := 1 until scene.polygons.off loop if scene.polygons.item_for_iteration.is_collidable_valid and then scene.polygons.item_for_iteration.collidable.count > 1 then Result.append ("composition"+i.out+", ") i := i + 1 end scene.polygons.forth end if i > 1 then Result.remove_tail (2) Result.append (": EM_COLLIDABLE_COMPOSITION%N") Result.append ("composition_element: EM_POLYGON_CONVEX_COLLIDABLE%N") end Result.append ("do%N") Result.append ("%N-- creating collidable circles%N") from scene.circles.start i := 1 until scene.circles.off loop c := scene.circles.item_for_iteration Result.append ("create circle"+i.out+".make (create {EM_VECTOR_2D}.make ("+c.center.x.out+", "+c.center.y.out+"), "+c.radius.out+")%N") scene.circles.forth i := i + 1 end Result.append ("%N-- creating collidable rectangles%N") from scene.rectangles.start i := 1 until scene.rectangles.off loop r := scene.rectangles.item_for_iteration Result.append ("create rectangle"+i.out+".make (create {EM_VECTOR_2D}.make ("+r.point_a.x.out+", "+r.point_a.y.out+"), create {EM_VECTOR_2D}.make ("+r.point_b.x.out+", "+r.point_b.y.out+"))%N") scene.rectangles.forth i := i + 1 end Result.append ("%N-- creating collidable polygons (convex)%N") from scene.polygons.start i := 1 until scene.polygons.off loop if scene.polygons.item_for_iteration.is_collidable_valid and then scene.polygons.item_for_iteration.collidable.count = 1 then po := scene.polygons.item_for_iteration Result.append ("create vector_list.make%N") from po.start until po.off loop Result.append ("vector_list.force_last (create {EM_VECTOR_2D}.make ("+po.item_for_iteration.x.out+", "+po.item_for_iteration.y.out+"))%N") po.forth end Result.append ("create polygon"+i.out+".make_from_absolute_list (create {EM_VECTOR_2D}.make ("+po.collidable.center.x.out+", "+po.collidable.center.y.out+"), vector_list)%N") i := i + 1 end scene.polygons.forth end Result.append ("%N-- creating collidable compositions (concave polygons)%N") from scene.polygons.start i := 1 until scene.polygons.off loop if scene.polygons.item_for_iteration.is_collidable_valid and then scene.polygons.item_for_iteration.collidable.count > 1 then co := scene.polygons.item_for_iteration.collidable first_run := True from co.collidables.start until co.collidables.off loop po_co ?= co.collidables.item_for_iteration if po_co /= Void then Result.append ("create vector_list.make%N") from po_co.vertex_list_absolute.start until po_co.vertex_list_absolute.off loop Result.append ("vector_list.force_last (create {EM_VECTOR_2D}.make ("+po_co.vertex_list_absolute.item_for_iteration.x.out+", "+po_co.vertex_list_absolute.item_for_iteration.y.out+"))%N") po_co.vertex_list_absolute.forth end Result.append ("create composition_element.make_from_absolute_list (create {EM_VECTOR_2D}.make ("+po_co.center.x.out+", "+po_co.center.y.out+"), vector_list)%N") if first_run then first_run := False Result.append ("create composition"+i.out+".make (composition_element, create {EM_VECTOR_2D}.make ("+co.center.x.out+", "+co.center.y.out+"))%N") else Result.append ("composition"+i.out+".add (composition_element)%N") end end co.collidables.forth end i := i + 1 end scene.polygons.forth end Result.append ("end%N") end end