AGX Dynamics 2.41.2.0
Loading...
Searching...
No Matches
CollisionGroupFilter.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#ifndef AGXSDK_COLLISIONGROUPFILTER_H
18#define AGXSDK_COLLISIONGROUPFILTER_H
19
21#include <agxSDK/agxSDK.h>
22#include <agxCollide/Geometry.h>
24#include <agx/TimeStamp.h>
25#include <agxCollide/Contacts.h>
26
27#include <agx/Vector.h>
28
29
30namespace agxSDK
31{
32
35
42 {
43 public:
44
47
55
60
64 agxCollide::Geometry* getGeometry();
65 const agxCollide::Geometry* getGeometry() const;
66
71 void addGroup(const agx::Name& group);
72 void addGroup(agx::UInt32 group);
73
77 void removeGroup(const agx::Name& group);
79
84
88 bool hasGroup(const agx::Name& group);
89 bool hasGroup(agx::UInt32 group);
90
94 agx::Vector<agx::Name> getNamedGroups();
95 const agx::Vector<agx::Name> getNamedGroups() const;
96
100 agx::Vector<agx::UInt32> getUIntGroups();
101 const agx::Vector<agx::UInt32> getUIntGroups() const;
102
103 bool match(const agxCollide::Geometry* geo0, const agxCollide::Geometry* geo1) const override;
104 using ExecuteFilter::match;
105
106 protected:
107
108 // Check if a geometry has one of the collision groups of this filter
109 bool hasMemberGroup( const agxCollide::Geometry* geom ) const;
110
113
114
115 protected:
119 };
120
121 // Implementation
122
123 // Had to switch to regular inline since compiler complains about AGX_FORCE_INLINE
125 {
126
127 if (m_geometry == nullptr || (geo0 == m_geometry || geo1 == m_geometry))
128 {
129 // Match all collisions if no collision groups are set
131 return true;
132
133 if (m_geometry == nullptr)
134 {
135 if (hasMemberGroup( geo0 )) return true;
136 if (hasMemberGroup( geo1 )) return true;
137 }
138 else // geo0 == m_geometry || geo1 == m_geometry
139 {
140 const agxCollide::Geometry* collider = (m_geometry == geo0) ? geo1 : geo0;
141 if (hasMemberGroup( collider )) return true;
142 }
143 }
144 return false;
145 }
146
148 {
149 // Named collision groups
150 for (size_t i = 0; i < m_namedCollisionGroups.size(); i++)
151 {
152 if (geom->hasGroup( m_namedCollisionGroups[i] ))
153 return true;
154 }
155
156 // UInt collision groups
157 for (size_t i = 0; i < m_uintCollisiontGroups.size(); i++)
158 {
159 if (geom->hasGroup( m_uintCollisiontGroups[i] ))
160 return true;
161 }
162 return false;
163 }
164
167
170
173}
174
175#endif /*AGXMODEL_COLLISIONGROUPFILTER_H*/
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGXPHYSICS_EXPORT
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: agx/Vector.h:34
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
bool hasGroup(agx::UInt32 id) const
This is performing a linear search among the collision group id for this Geometry.
Definition: Geometry.h:831
An ExecuteFilter that is used to filter out contacts matching a specified criteria based on Collision...
agxCollide::Geometry * getGeometry()
Gets the geometry of the filter.
agx::Vector< agx::UInt32 > m_uintCollisiontGroups
bool hasGroup(agx::UInt32 group)
void removeGroup(const agx::Name &group)
Removes the specified group form the filter.
void removeAllGroups()
Removes all the groups the filter listens too.
agx::Vector< agx::UInt32 > getUIntGroups()
Returns the uint groups that the filter listens to.
void removeGroup(agx::UInt32 group)
agxCollide::Geometry * m_geometry
bool hasMemberGroup(const agxCollide::Geometry *geom) const
void addGroup(agx::UInt32 group)
CollisionGroupFilter(agxCollide::Geometry *geometry)
This filter will select contacts that contain Geometry geometry 0 can be considered a wild card and m...
virtual ~CollisionGroupFilter()
Destructor.
agx::Vector< agx::Name > getNamedGroups()
Returns the named groups that the filter listens to.
agx::Vector< agx::Name > m_namedCollisionGroups
void setGeometry(agxCollide::Geometry *geometry)
Sets the geometry of the filter.
CollisionGroupFilter()
Default constructor.
void addGroup(const agx::Name &group)
Adds a collision group to the filter.
bool hasGroup(const agx::Name &group)
Returns true if the filter contains and listens to group.
bool match(const agxCollide::Geometry *geo0, const agxCollide::Geometry *geo1) const override
Called by the other two match functions if they are not overridden.
Abstract base class that implements a filter that selects which events should trigger a Listener.
Definition: ExecuteFilter.h:34
size_t size() const
Definition: Container.h:134
Representation of a name string.
Definition: Name.h:33
Templated vector class.
Definition: agx/Vector.h:53
#define AGX_FORCE_INLINE
Definition: macros.h:58
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:31
uint32_t UInt32
Definition: Integer.h:32