= Collision Reaction = [[ArchivePage]] Module Pwner: Patrick Boenzli (patrick [at] orxonox [dot] net) == Overview == You can find the whole source in [https://dev.orxonox.net/browser/trunk/src/lib/collision_reaction this directory], the main modules are: * [https://dev.orxonox.net/browser/trunk/src/lib/collision_reaction/collision_tube.h Collision Tube] - collects all collision information and stores them * [https://dev.orxonox.net/browser/trunk/src/lib/collision_reaction/collision_event.h Collision Event] - each obb intersecting with an other obb fires such an event, contained in an Collision object * [https://dev.orxonox.net/browser/trunk/src/lib/collision_reaction/collision.h Collision] - defined as the event of two objects intersecting, contain !CollisionEvents * [https://dev.orxonox.net/browser/trunk/src/lib/collision_reaction/collision_filter.h Collision Filter] - looks if two objects are listening for collisions between them * [https://dev.orxonox.net/browser/trunk/src/lib/collision_reaction/cr_engine.h Collision Reaction Engine] - controlling the collision reactions and checking out the Collisions == Coding Examples == === Subscribing to a !CollisionReaction === All !WorldEntities are able to subscribe to !CollisionReactions. These object will only react to objects specified in this subscription and will only react with an action choosen in this subscription. Example: {{{ this->subscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE, Projectile::staticClassID()); }}} You can find this function prototype [https://dev.orxonox.net/browser/trunk/src/world_entities/world_entity.h#L83 here]. This registers the object to a damage reaction to all Projectile classes (and subclassses) (BTW: this is the default subscriptoin of all !WorldEntities). === Object Damage === Object damage is evaluated with the [https://dev.orxonox.net/browser/trunk/src/lib/collision_reaction/cr_object_damage.h CRObjectDamage] !CollisionReaction object. Each [wiki:archive/WorldEntity WorldEntity] has got a {{{float damage}}} that can be accessed via {{{void setDamage(float damage)}}} and {{{float getDamage()}}}. The damage to another object is evaluated with this {{{damage}}} variable. Here is a short example: {{{ this->setDamage(100.0f); this->subscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE, Playable::staticClassID()); }}} This sets the damage caused by this object to all other objects to 100.0f (units). All Playables will recieve this damage by collision but '''only if they are subscribed''' for this collision reaction. If the Playable itself has not subscribed for this collision reaction it won't be harmed. '''This subscription specifies which other objects may damage this object'''