indexing description: "[ Objects of type EM_3D_SPHERE_COLLIDABLE implement a collision detection based on bounding spheres. This objects can collide with other objects of the same type and also objects of type EM_3D_SKYBOX_COLLIDABLE ]" date: "$Date$" revision: "$Revision$" deferred class EM_3D_SPHERE_COLLIDABLE inherit EM_COLLIDABLE_3D EM_COLLIDE_3D_SPHERE EM_COLLIDE_3D_SKYBOX feature -- Status report does_collide (other: EM_COLLIDABLE_3D): BOOLEAN is -- Does `current' collide with `other'? local sphere_collide: EM_COLLIDE_3D_SPHERE do sphere_collide ?= other if sphere_collide /= void then result := sphere_collide.does_collide_sphere (current) else result := false end end does_collide_sphere (other: EM_3D_SPHERE_COLLIDABLE): BOOLEAN is -- do we collide with another sphere? local diff: EM_3D_VECT do -- we do collide if the distance between the two centers -- is smaller than the sum of the radiuses diff := bounding_sphere_center - other.bounding_sphere_center if diff.length < bounding_sphere_radius + other.bounding_sphere_radius then result := true else result := false end end does_collide_skybox (other: EM_3D_SKYBOX_COLLIDABLE): BOOLEAN is -- Do we collide with the axis aligned skybox? do -- we do collide if the our center + radius is out of the box in one coordinate result := bounding_sphere_center.x + bounding_sphere_radius > other.max_x or bounding_sphere_center.x - bounding_sphere_radius < other.min_x or bounding_sphere_center.y + bounding_sphere_radius > other.max_y or bounding_sphere_center.y - bounding_sphere_radius < other.min_y or bounding_sphere_center.z + bounding_sphere_radius > other.max_z or bounding_sphere_center.z - bounding_sphere_radius < other.min_z end bounding_sphere_center: EM_3D_VECT is -- Center of the bounding sphere deferred end bounding_sphere_radius: DOUBLE is -- Radius of the bounding sphere deferred end end