Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9988 was 9988, checked in by patrick, 17 years ago

removed most of the compiler bugs. more to come

File size: 3.2 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    typedef std::vector<ClassID>::iterator    TargetIterator;
39
40    /* Constructor/Deconstructors */
41  public:
42    CollisionFilter(WorldEntity* owner);
43    virtual ~CollisionFilter();
44
45  private:
46    CollisionFilter(const CollisionFilter& collisionFilter) {}
47    WorldEntity*                  _owner;                   //!< the worldenity this reaction will be applied on
48
49
50  public:
51    /* Defines Operators */
52    bool operator()(const WorldEntity& entity) const;
53    bool operator()(const WorldEntity& entity, const CREngine::ReactionType type) const;
54
55
56    /* Collision Reaction subscription unsubscription Block */
57  public:
58    void subscribeReaction(CREngine::ReactionType type, const ClassID& target1);
59    void subscribeReaction(CREngine::ReactionType type, const ClassID& target1, const ClassID& target2);
60    void subscribeReaction(CREngine::ReactionType type, const ClassID& target1, const ClassID& target2, const ClassID& target3);
61
62    void unsubscribeReaction(CREngine::ReactionType type);
63    void unsubscribeReactions();
64
65  private:
66    std::vector<ClassID>          _filters[CREngine::CR_NUMBER];  //!< an array of filter targets: for each collision type a list of filter objects
67
68
69    /* Misc State Informations */
70  public:
71    /** @returns true if this handle should be pulled also if there are no collisions, can also be set with this function (reference)*/
72    inline bool isContinousPoll() { return this->_bContinuousPoll; }
73    /** @returns true if this filter should be pulled always */
74    inline bool isContinousPoll() const { return this->_bContinuousPoll; }
75    /** @returns true if this filter is reactive i.e. at least one filter criterion installed */
76    inline bool isReactive() const { return this->_bReactive; }
77
78
79  private:
80    /** @returns true if this @param type Collision Reaction type is a valid number */
81    inline bool validCRType(const CREngine::ReactionType& type) const {return (type >= 0 && type < CREngine::CR_NUMBER); }
82
83
84  private:
85    bool                          _bContinuousPoll;         //!< if this is true
86    bool                          _bStopOnFirstCollision;   //!< true if the cd of this object should be terminated after one match
87    bool                          _bReactive;               //!< true if this class has at least one filter criterion == one target
88
89  };
90
91}
92#endif /* _COLLISION_FILTER_H */
Note: See TracBrowser for help on using the repository browser.