ContactListenerTest.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 <Tests/Test.h>
  6. #include <Jolt/Physics/Collision/ContactListener.h>
  7. // Tests the contact listener callbacks
  8. class ContactListenerTest : public Test, public ContactListener
  9. {
  10. public:
  11. JPH_DECLARE_RTTI_VIRTUAL(JPH_NO_EXPORT, ContactListenerTest)
  12. // See: Test
  13. virtual void Initialize() override;
  14. virtual void PostPhysicsUpdate(float inDeltaTime) override;
  15. // If this test implements a contact listener, it should be returned here
  16. virtual ContactListener *GetContactListener() override { return this; }
  17. // See: ContactListener
  18. virtual ValidateResult OnContactValidate(const Body &inBody1, const Body &inBody2, RVec3Arg inBaseOffset, const CollideShapeResult &inCollisionResult) override;
  19. virtual void OnContactAdded(const Body &inBody1, const Body &inBody2, const ContactManifold &inManifold, ContactSettings &ioSettings) override;
  20. private:
  21. // The 4 bodies that we create
  22. Body * mBody[4];
  23. // Tracks predicted velocities so we can compare them with the actual velocities after time step
  24. struct PredictedVelocity
  25. {
  26. BodyID mBodyID;
  27. Vec3 mLinearVelocity;
  28. Vec3 mAngularVelocity;
  29. };
  30. Mutex mPredictedVelocitiesMutex;
  31. Array<PredictedVelocity> mPredictedVelocities;
  32. };