indexing description: "[ An EM_GOOF_FORCE that pulls towards (or from) a fixed 'center' with a 'srength'. ]" date: "$Date$" revision: "$Revision$" deferred class EM_GOOF_CENTRAL_FORCE inherit EM_GOOF_GENERAL_FORCE feature {EM_GOOF_FORCE, EM_GOOF_PHYSICS} -- Properties center: EM_VECTOR_2D -- Center to witch the force leads set_center(a_center: EM_VECTOR_2D) is -- Set center require a_center_not_void: a_center /= void do center := a_center ensure center_set: center = a_center end strength: DOUBLE -- Strength of force set_strength(a_strength: DOUBLE) is -- Set strength do strength := a_strength ensure strength_set: strength = a_strength end feature {EM_GOOF_FORCE, EM_GOOF_PHYSICS} -- Processing process_object(object: EM_GOOF_PHYSICABLE) is -- Apply force to this object local force_vector: EM_VECTOR_2D force_strength: DOUBLE do force_vector := object.position - center if force_vector.length > 0 then force_vector.normalize if force_vector.length < 1 then force_strength := -strength * object_dependant_factor(object) else force_strength := -strength / force_vector.length^2 * object_dependant_factor(object) end force_vector.stretch(force_strength, force_strength) end object.force.add(force_vector) end object_dependant_factor(object: EM_GOOF_PHYSICABLE): DOUBLE is -- the object dependant factor in the force equasion (mass in case of gravity) require object_not_void: object /= void deferred end invariant center_not_void: center /= void end