Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/coll_rect/src/lib/collision_reaction/collision_filter.h @ 9898

Last change on this file since 9898 was 9898, checked in by patrick, 18 years ago

more interface and more structure

File size: 3.1 KB
Line 
1/*!
2 * @file collision_filter.h
3 * @brief Definition of a collision filter: checks if a certain WorldEntity is responsive for another WorldEntity
4 *
5*/
6
7#ifndef _COLLISION_FILTER_H
8#define _COLLISION_FILTER_H
9
10#include "base_object.h"
11#include "cr_engine.h"
12
13#include <vector>
14#include <list>
15
16
17class Collision;
18class WorldEntity;
19
20namespace CoRe
21{
22
23  class CollisionReaction;
24
25
26  /**
27   * A class for defining collision reactions and storing events (functional object)
28   *
29   * This class basically checks if the owner of this filter (a WorldEntity) is responsive for a certain other WorldEntity.
30   * The check is performed via the operator() (therefore it's a functional objects). For each CollisionReaction there is a list
31   * of WorldEntities (their ClassIDs) to which it listens to.
32   */
33  class CollisionFilter : public BaseObject
34  {
35    ObjectListDeclaration(CollisionFilter);
36
37
38    /* Constructor/Deconstructors */
39  public:
40    CollisionFilter(WorldEntity* owner);
41    virtual ~CollisionFilter();
42
43  private:
44    CollisionFilter(const CollisionFilter& collisionFilter) {}
45    WorldEntity*                  _owner;                   //!< the worldenity this reaction will be applied on
46
47
48    /* Defines Operators */
49    bool operator()(const WorldEntity* entity) const;
50    bool operator()(const WorldEntity* entity, const CREngine::ReactionType type) const;
51
52
53    /* Collision Reaction subscription unsubscription Block */
54  public:
55    void subscribeReaction(CREngine::ReactionType type, const ClassID& target1);
56    void subscribeReaction(CREngine::ReactionType type, const ClassID& target1, const ClassID& target2);
57    void subscribeReaction(CREngine::ReactionType type, const ClassID& target1, const ClassID& target2, const ClassID& target3);
58
59    void unsubscribeReaction(CREngine::ReactionType type);
60    void unsubscribeReactions();
61
62  private:
63    std::vector<ClassID>          _filters[CREngine::CR_NUMBER];  //!< an array of filter targets: for each collision type a list of filter objects
64
65
66    /* Misc State Informations */
67  public:
68    /** @returns true if this handle should be pulled also if there are no collisions, can also be set with this function (reference)*/
69    inline bool& bContinousPoll() { return this->_bContinuousPoll; }
70    /** @returns true if this filter should be pulled always */
71    inline bool bContinousPoll() const { return this->_bContinuousPoll; }
72    /** @returns true if this @param type Collision Reaction type is a valid number */
73    inline bool validCRType(const CREngine::ReactionType& type) const {return (type >= 0 && type < CREngine::CR_NUMBER); }
74    /** @returns true if this filter is reactive i.e. at least one filter criterion installed */
75    inline bool bReactive() const { return this->_bReactive; }
76
77  private:
78    bool                          _bContinuousPoll;         //!< if this is true
79    bool                          _bStopOnFirstCollision;   //!< true if the cd of this object should be terminated after one match
80    bool                          _bReactive;               //!< true if this class has at least one filter criterion == one target
81
82  };
83
84}
85#endif /* _COLLISION_FILTER_H */
Note: See TracBrowser for help on using the repository browser.