Eiffel Media API
Overview Cluster Class Classes Index      Previous Next      Top Features

em.video.collision_detection

Class EM_COLLISION



Creation

Features

Invariants

indexing

description

Two collided objects, giving information about collision points and direction

date

$Date: 2005/10/23 10:49:44 $

revision

$Revision: 1.7 $

class

EM_COLLISION [G->EM_COLLIDABLE]

create

make (a_collidable, b_collidable: G; a_position: EM_VECTOR_2D; a_direction: EM_DIRECTION_2D; a_time: DOUBLE)

-- creates a collision and takes the following arguments
-- 2 collidables
-- the center position of both (only 2 are looked for, since in most cases there are only 2) intersections
-- the tangential direction of the collision
-- a_time is between 0 and 1, and gives the time of the collision, if a search in depth was done

require
a_collidable_not_void: a_collidable /= void
b_collidable_not_void: b_collidable /= void
time_valid: a_time >= 0 and a_time <= 1
ensure
time_set: time = a_time
collidable_set: collidables.first = a_collidable
collidable_set: collidables.second = b_collidable
collision_point_set: collision_point = a_position
collision_direction_set: collision_direction = a_direction

feature -- Initialization

make (a_collidable, b_collidable: G; a_position: EM_VECTOR_2D; a_direction: EM_DIRECTION_2D; a_time: DOUBLE)

-- creates a collision and takes the following arguments
-- 2 collidables
-- the center position of both (only 2 are looked for, since in most cases there are only 2) intersections
-- the tangential direction of the collision
-- a_time is between 0 and 1, and gives the time of the collision, if a search in depth was done

require
a_collidable_not_void: a_collidable /= void
b_collidable_not_void: b_collidable /= void
time_valid: a_time >= 0 and a_time <= 1
ensure
time_set: time = a_time
collidable_set: collidables.first = a_collidable
collidable_set: collidables.second = b_collidable
collision_point_set: collision_point = a_position
collision_direction_set: collision_direction = a_direction

feature -- Access

collidables: EM_PAIR[G, G]

-- both collidables

collision_direction: EM_DIRECTION_2D

-- the tangential direction of the collision

collision_point: EM_VECTOR_2D

-- the collision point (average of both intersections)

contains (a_collidable: G): BOOLEAN

-- checks if a collidable is contained in this collision

require
a_collidable_not_void: a_collidable /= void
time: DOUBLE

-- the time at which the 2 collidables intersect the first time in a frame.
-- default is 1 (the end position), if no search in depth was done.

feature -- Element Change

set_collidables (a_collidable, b_collidable: G)

-- sets collidables

require
a_collidable_not_void: a_collidable /= void
b_collidable_not_void: b_collidable /= void
ensure
collidable_set: collidables.first = a_collidable
collidable_set: collidables.second = b_collidable
set_collision_point (a_position: EM_VECTOR_2D; a_direction: EM_DIRECTION_2D)

-- takes the following arguments
-- the center position of both (only 2 are looked for, since in most cases there are only 2) intersections
-- the tangential direction of the collision

require
a_position_not_void: a_position /= void
a_direction_not_void: a_direction /= void
ensure
collision_point_set: collision_point = a_position
collision_direction_set: collision_direction = a_direction

invariant

invariant_clause: True

-- From ANY
reflexive_equality: standard_is_equal (Current)
reflexive_conformance: conforms_to (Current)

end