BodyPair.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. #include <Jolt/Physics/Body/BodyID.h>
  6. #include <Jolt/Core/HashCombine.h>
  7. JPH_NAMESPACE_BEGIN
  8. /// Structure that holds a body pair
  9. struct alignas(uint64) BodyPair
  10. {
  11. JPH_OVERRIDE_NEW_DELETE
  12. /// Constructor
  13. BodyPair() = default;
  14. BodyPair(BodyID inA, BodyID inB) : mBodyA(inA), mBodyB(inB) { }
  15. /// Equals operator
  16. bool operator == (const BodyPair &inRHS) const { return *reinterpret_cast<const uint64 *>(this) == *reinterpret_cast<const uint64 *>(&inRHS); }
  17. /// Smaller than operator, used for consistently ordering body pairs
  18. bool operator < (const BodyPair &inRHS) const { return *reinterpret_cast<const uint64 *>(this) < *reinterpret_cast<const uint64 *>(&inRHS); }
  19. /// Get the hash value of this object
  20. uint64 GetHash() const { return Hash64(*reinterpret_cast<const uint64 *>(this)); }
  21. BodyID mBodyA;
  22. BodyID mBodyB;
  23. };
  24. static_assert(sizeof(BodyPair) == sizeof(uint64), "Mismatch in class size");
  25. JPH_NAMESPACE_END