0.2.0-dev Download ZIP
36 lines ·1.1 KB Raw
| 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/Core/HashCombine.h> |
| 9 | |
| 10 | JPH_NAMESPACE_BEGIN |
| 11 | |
| 12 | /// Structure that holds a body pair |
| 13 | struct alignas(uint64) BodyPair |
| 14 | { |
| 15 | JPH_OVERRIDE_NEW_DELETE |
| 16 | |
| 17 | /// Constructor |
| 18 | BodyPair() = default; |
| 19 | BodyPair(BodyID inA, BodyID inB) : mBodyA(inA), mBodyB(inB) { } |
| 20 | |
| 21 | /// Equals operator |
| 22 | bool operator == (const BodyPair &inRHS) const { return *reinterpret_cast<const uint64 *>(this) == *reinterpret_cast<const uint64 *>(&inRHS); } |
| 23 | |
| 24 | /// Smaller than operator, used for consistently ordering body pairs |
| 25 | bool operator < (const BodyPair &inRHS) const { return *reinterpret_cast<const uint64 *>(this) < *reinterpret_cast<const uint64 *>(&inRHS); } |
| 26 | |
| 27 | /// Get the hash value of this object |
| 28 | uint64 GetHash() const { return Hash64(*reinterpret_cast<const uint64 *>(this)); } |
| 29 | |
| 30 | BodyID mBodyA; |
| 31 | BodyID mBodyB; |
| 32 | }; |
| 33 | |
| 34 | static_assert(sizeof(BodyPair) == sizeof(uint64), "Mismatch in class size"); |
| 35 | |
| 36 | JPH_NAMESPACE_END |