17 #ifndef AGXCOLLIDE_COLLISIONGROUPHANDLER_H 18 #define AGXCOLLIDE_COLLISIONGROUPHANDLER_H 112 const CollisionHash& getDisabledGroupCollisions()
const;
113 const CollisionHash& getDisabledSetCollisions()
const;
117 bool hasGroup(
const agx::Name& groupName)
const;
128 SymmetricCollisionGroupVector getDisabledCollisionGroupPairs()
const;
144 bool internal_canCollide(
const GroupIdHash& groups1,
const GroupIdHash& groups2);
145 void removeInactiveSets();
176 {
return state >= ACTIVE; }
181 return state == VALID;
185 friend class GroupSetCache;
212 agxAssert(
set &&
set.groups().size() + 1 < 1024);
214 size_t numGroups = 0;
217 const GroupVector& groups =
set.groups();
219 for (; i < groups.
size() && groups[i].id() < group.
id(); ++i)
220 localGroups[numGroups++] = groups[i];
222 localGroups[numGroups++] = group;
224 for (; i < groups.
size(); ++i)
225 localGroups[numGroups++] = groups[i];
228 agx::UInt32 bucketIndex = findBucket(localGroups, numGroups);
234 agxAssert(
set &&
set.groups().size() - 1 < 1024);
236 size_t numGroups = 0;
239 const GroupVector& groups =
set.groups();
240 for (
size_t i = 0; i < groups.
size(); ++i)
242 if (groups[i].
id() == group.
id())
245 localGroups[numGroups++] = groups[i];
248 agx::UInt32 bucketIndex = findBucket(localGroups, numGroups);
257 const GroupVector& groups =
set.groups();
266 const GroupVector& groups =
set.groups();
283 bucket = &m_buckets[(hashValue + offset * offset) %
m_capacity];
286 if (bucket->isValid() && compareGroups(groups.
begin(), groups.
size(), bucket->groupSet))
288 targetBucket = bucket;
293 if (!bucket->isValid() && !targetBucket)
294 targetBucket = bucket;
297 if (targetBucket && offset >= m_maxProbeLength)
307 return this->insert(
set);
313 if (offset > m_maxProbeLength)
322 targetBucket->state = Bucket::VALID;
328 return find(
set).isValid();
335 const GroupVector& groups =
set.groups();
340 Bucket *bucket = &m_buckets[bucketIndex];
346 bucket->state = Bucket::ACTIVE;
356 agx::UInt32 hashValue = calculateHash(localGroups, numGroups);
359 const Bucket *bucket = &m_buckets[index];
362 if (bucket->
isValid() && compareGroups(localGroups, numGroups, bucket->
groupSet))
366 for (
size_t offset = 1; bucket->
isActive() && offset <= m_maxProbeLength; offset++)
368 index = (hashValue + offset * offset) %
m_capacity;
369 bucket = &m_buckets[index];
371 if (bucket->
isValid() && compareGroups(localGroups, numGroups, bucket->
groupSet))
384 for (
size_t i = 0; i < numGroups; ++i)
394 const GroupVector& groups =
set.groups();
396 if (groups.
size() != numGroups)
399 for (
size_t i = 0; i < groups.
size(); ++i)
401 if (groups[i].
id() != localGroups[i].
id())
408 void rebuild(
size_t size)
414 Bucket *oldBuckets = m_buckets;
419 ::
new (&m_buckets[i])
Bucket();
422 m_maxProbeLength = 0;
424 for (
size_t i = 0; i < oldNumBuckets; i++)
426 Bucket& bucket = oldBuckets[i];
432 m_allocator.deallocateBytes((
void *)oldBuckets, oldNumBuckets *
sizeof(
Bucket));
449 GroupSetCache m_groupSetCache;
452 CollisionHash m_disabledSetCollisions;
453 CollisionHash m_disabledGroupCollisions;
460 CollisionGroupTable m_collisionGroupTable;
463 CollisionGroupNameTable m_collisionGroupNameTable;
bool canSetsCollide(agx::UInt32 set1, agx::UInt32 set2) const
agx::HashSet< agx::UInt32 > GroupIdHash
AGXCORE_EXPORT UInt32 hash(const T &key)
Vec3T< T > max(const Vec3T< T > &lhs, const Vec3T< T > &rhs)
A component is an object containing other objects, enabling hierarchical structuring.
agxCollide namespace consists of a set of classes for handling geometric intersection tests including...
Pointer to a entity instance of type Physics.CollisionGroup.
const CollisionHash & getDisabledGroupCollisions() const
std::pair< agx::Name, agx::Real > Bucket
#define AGXPHYSICS_EXPORT
AGXCORE_EXPORT const InvalidIndexStruct InvalidIndex
Representation of a name string.
Pointer to a entity instance of type Physics.CollisionGroupSet.
std::ostream & operator<<(std::ostream &output, const BoundingAABB &bound)
#define AGX_HASH_SET_GROW_THRESHOLD
#define AGX_HASH_SET_GROW_FACTOR
AGXCORE_EXPORT agx::UInt64 buildHashKey(agx::UInt32 id1, agx::UInt32 id2)
This class contains all Geometries and performs Broad Phase and Narrow Phase collision detection to c...
agx::HashSet< agx::UInt64 > CollisionHash
agx::HashSet< agx::Physics::CollisionGroupPtr > GroupHash
agx::Vector< agx::Physics::CollisionGroupSetPtr > GroupSetVector
Bucket & operator=(const Bucket &b)
agx::Vector< agx::Physics::CollisionGroupPtr > GroupVector
#define AGX_HASH_SET_MAX_PROBE_LENGTH
bool canGroupsCollide(agx::UInt32 group1, agx::UInt32 group2) const
agx::Vector< agx::SymmetricPair< agx::Physics::CollisionGroupPtr > > SymmetricCollisionGroupVector
AGXCORE_EXPORT int nextPrime(int n)
AGXPHYSICS_EXPORT bool setEnableCollisions(agx::RigidBody *rb1, agx::RigidBody *rb2, bool enable)
Enable or disable the collision between all geometries in RigidBody rb1 and RigidBody rb2...
#define AGX_HASH_SET_MIN_SIZE
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
const CollisionHash & getDisabledSetCollisions() const
agx::HashSet< agx::Physics::CollisionGroupSetPtr > GroupSetHash
Inheritance with partial specialization due to bug with ref_ptr containers.
agxData::EntityStorage * getStorage() const
AGXPHYSICS_EXPORT agx::UInt32 & id()
agx::Physics::CollisionGroupSetPtr groupSet
AGX_DECLARE_POINTER_TYPES(SpaceListener)