Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
CollisionGroup.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
9
11
12class StreamIn;
13class StreamOut;
14
20{
22
23public:
24 using GroupID = uint32;
26
27 static const GroupID cInvalidGroup = ~GroupID(0);
28 static const SubGroupID cInvalidSubGroup = ~SubGroupID(0);
29
31 CollisionGroup() = default;
32
34 CollisionGroup(const GroupFilter *inFilter, GroupID inGroupID, SubGroupID inSubGroupID) : mGroupFilter(inFilter), mGroupID(inGroupID), mSubGroupID(inSubGroupID) { }
35
37 inline void SetGroupFilter(const GroupFilter *inFilter)
38 {
39 mGroupFilter = inFilter;
40 }
41
43 inline const GroupFilter *GetGroupFilter() const
44 {
45 return mGroupFilter;
46 }
47
49 inline void SetGroupID(GroupID inID)
50 {
51 mGroupID = inID;
52 }
53
54 inline GroupID GetGroupID() const
55 {
56 return mGroupID;
57 }
58
60 inline void SetSubGroupID(SubGroupID inID)
61 {
62 mSubGroupID = inID;
63 }
64
66 {
67 return mSubGroupID;
68 }
69
71 bool CanCollide(const CollisionGroup &inOther) const
72 {
73 // Call the CanCollide function of the first group filter that's not null
74 if (mGroupFilter != nullptr)
75 return mGroupFilter->CanCollide(*this, inOther);
76 else if (inOther.mGroupFilter != nullptr)
77 return inOther.mGroupFilter->CanCollide(inOther, *this);
78 else
79 return true;
80 }
81
83 void SaveBinaryState(StreamOut &inStream) const;
84
86 void RestoreBinaryState(StreamIn &inStream);
87
88private:
89 RefConst<GroupFilter> mGroupFilter;
90 GroupID mGroupID = cInvalidGroup;
91 SubGroupID mSubGroupID = cInvalidSubGroup;
92};
93
#define JPH_EXPORT
Definition: Core.h:236
#define JPH_NAMESPACE_END
Definition: Core.h:378
std::uint32_t uint32
Definition: Core.h:455
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:372
#define JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(linkage, class_name)
Definition: SerializableObject.h:80
Definition: CollisionGroup.h:20
GroupID GetGroupID() const
Definition: CollisionGroup.h:54
SubGroupID GetSubGroupID() const
Definition: CollisionGroup.h:65
void SetGroupFilter(const GroupFilter *inFilter)
Set the collision group filter.
Definition: CollisionGroup.h:37
CollisionGroup(const GroupFilter *inFilter, GroupID inGroupID, SubGroupID inSubGroupID)
Construct with all properties.
Definition: CollisionGroup.h:34
void SetSubGroupID(SubGroupID inID)
Add this object to a sub group.
Definition: CollisionGroup.h:60
bool CanCollide(const CollisionGroup &inOther) const
Check if this object collides with another object.
Definition: CollisionGroup.h:71
uint32 GroupID
Definition: CollisionGroup.h:24
void SetGroupID(GroupID inID)
Set the main group id for this object.
Definition: CollisionGroup.h:49
const GroupFilter * GetGroupFilter() const
Get the collision group filter.
Definition: CollisionGroup.h:43
CollisionGroup()=default
Default constructor.
uint32 SubGroupID
Definition: CollisionGroup.h:25
Abstract class that checks if two CollisionGroups collide.
Definition: GroupFilter.h:18
virtual bool CanCollide(const CollisionGroup &inGroup1, const CollisionGroup &inGroup2) const =0
Check if two groups collide.
Definition: Reference.h:157
Simple binary input stream.
Definition: StreamIn.h:13
Simple binary output stream.
Definition: StreamOut.h:13