Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/Collision/Shape/SubShapeIDPair.h
9913 views
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)1// SPDX-FileCopyrightText: 2021 Jorrit Rouwe2// SPDX-License-Identifier: MIT34#pragma once56#include <Jolt/Physics/Body/BodyID.h>7#include <Jolt/Physics/Collision/Shape/SubShapeID.h>8#include <Jolt/Core/HashCombine.h>910JPH_NAMESPACE_BEGIN1112/// A pair of bodies and their sub shape ID's. Can be used as a key in a map to find a contact point.13class SubShapeIDPair14{15public:16JPH_OVERRIDE_NEW_DELETE1718/// Constructor19SubShapeIDPair() = default;20SubShapeIDPair(const BodyID &inBody1ID, const SubShapeID &inSubShapeID1, const BodyID &inBody2ID, const SubShapeID &inSubShapeID2) : mBody1ID(inBody1ID), mSubShapeID1(inSubShapeID1), mBody2ID(inBody2ID), mSubShapeID2(inSubShapeID2) { }21SubShapeIDPair & operator = (const SubShapeIDPair &) = default;22SubShapeIDPair(const SubShapeIDPair &) = default;2324/// Equality operator25inline bool operator == (const SubShapeIDPair &inRHS) const26{27return UVec4::sLoadInt4(reinterpret_cast<const uint32 *>(this)) == UVec4::sLoadInt4(reinterpret_cast<const uint32 *>(&inRHS));28}2930/// Less than operator, used to consistently order contact points for a deterministic simulation31inline bool operator < (const SubShapeIDPair &inRHS) const32{33if (mBody1ID != inRHS.mBody1ID)34return mBody1ID < inRHS.mBody1ID;3536if (mSubShapeID1.GetValue() != inRHS.mSubShapeID1.GetValue())37return mSubShapeID1.GetValue() < inRHS.mSubShapeID1.GetValue();3839if (mBody2ID != inRHS.mBody2ID)40return mBody2ID < inRHS.mBody2ID;4142return mSubShapeID2.GetValue() < inRHS.mSubShapeID2.GetValue();43}4445const BodyID & GetBody1ID() const { return mBody1ID; }46const SubShapeID & GetSubShapeID1() const { return mSubShapeID1; }47const BodyID & GetBody2ID() const { return mBody2ID; }48const SubShapeID & GetSubShapeID2() const { return mSubShapeID2; }4950uint64 GetHash() const { return HashBytes(this, sizeof(SubShapeIDPair)); }5152private:53BodyID mBody1ID;54SubShapeID mSubShapeID1;55BodyID mBody2ID;56SubShapeID mSubShapeID2;57};5859static_assert(sizeof(SubShapeIDPair) == 16, "Unexpected size");60static_assert(alignof(SubShapeIDPair) == 4, "Assuming 4 byte aligned");6162JPH_NAMESPACE_END6364JPH_MAKE_STD_HASH(JPH::SubShapeIDPair)656667