BodyPair.h 1.1 KB

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