Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/Collision/Shape/SubShapeIDPair.h
9913 views
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
7
#include <Jolt/Physics/Body/BodyID.h>
8
#include <Jolt/Physics/Collision/Shape/SubShapeID.h>
9
#include <Jolt/Core/HashCombine.h>
10
11
JPH_NAMESPACE_BEGIN
12
13
/// A pair of bodies and their sub shape ID's. Can be used as a key in a map to find a contact point.
14
class SubShapeIDPair
15
{
16
public:
17
JPH_OVERRIDE_NEW_DELETE
18
19
/// Constructor
20
SubShapeIDPair() = default;
21
SubShapeIDPair(const BodyID &inBody1ID, const SubShapeID &inSubShapeID1, const BodyID &inBody2ID, const SubShapeID &inSubShapeID2) : mBody1ID(inBody1ID), mSubShapeID1(inSubShapeID1), mBody2ID(inBody2ID), mSubShapeID2(inSubShapeID2) { }
22
SubShapeIDPair & operator = (const SubShapeIDPair &) = default;
23
SubShapeIDPair(const SubShapeIDPair &) = default;
24
25
/// Equality operator
26
inline bool operator == (const SubShapeIDPair &inRHS) const
27
{
28
return UVec4::sLoadInt4(reinterpret_cast<const uint32 *>(this)) == UVec4::sLoadInt4(reinterpret_cast<const uint32 *>(&inRHS));
29
}
30
31
/// Less than operator, used to consistently order contact points for a deterministic simulation
32
inline bool operator < (const SubShapeIDPair &inRHS) const
33
{
34
if (mBody1ID != inRHS.mBody1ID)
35
return mBody1ID < inRHS.mBody1ID;
36
37
if (mSubShapeID1.GetValue() != inRHS.mSubShapeID1.GetValue())
38
return mSubShapeID1.GetValue() < inRHS.mSubShapeID1.GetValue();
39
40
if (mBody2ID != inRHS.mBody2ID)
41
return mBody2ID < inRHS.mBody2ID;
42
43
return mSubShapeID2.GetValue() < inRHS.mSubShapeID2.GetValue();
44
}
45
46
const BodyID & GetBody1ID() const { return mBody1ID; }
47
const SubShapeID & GetSubShapeID1() const { return mSubShapeID1; }
48
const BodyID & GetBody2ID() const { return mBody2ID; }
49
const SubShapeID & GetSubShapeID2() const { return mSubShapeID2; }
50
51
uint64 GetHash() const { return HashBytes(this, sizeof(SubShapeIDPair)); }
52
53
private:
54
BodyID mBody1ID;
55
SubShapeID mSubShapeID1;
56
BodyID mBody2ID;
57
SubShapeID mSubShapeID2;
58
};
59
60
static_assert(sizeof(SubShapeIDPair) == 16, "Unexpected size");
61
static_assert(alignof(SubShapeIDPair) == 4, "Assuming 4 byte aligned");
62
63
JPH_NAMESPACE_END
64
65
JPH_MAKE_STD_HASH(JPH::SubShapeIDPair)
66
67