SimCollideBodyVsBodyTest.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2025 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. #include <Tests/Test.h>
  6. // Test that overrides the collide body vs body function on the simulation to reduce the number of contact points generated
  7. // between sensors and other objects in the simulation. This can be useful to improve performance if you don't need to know
  8. // about all contact points and are only interested in an overlap/no-overlap result.
  9. class SimCollideBodyVsBodyTest : public Test, public ContactListener
  10. {
  11. public:
  12. JPH_DECLARE_RTTI_VIRTUAL(JPH_NO_EXPORT, SimCollideBodyVsBodyTest)
  13. // See: Test
  14. virtual void Initialize() override;
  15. virtual void PrePhysicsUpdate(const PreUpdateParams &inParams) override;
  16. // If this test implements a contact listener, it should be returned here
  17. virtual ContactListener *GetContactListener() override { return this; }
  18. // See: ContactListener
  19. virtual void OnContactAdded(const Body &inBody1, const Body &inBody2, const ContactManifold &inManifold, ContactSettings &ioSettings) override;
  20. virtual void OnContactPersisted(const Body &inBody1, const Body &inBody2, const ContactManifold &inManifold, ContactSettings &ioSettings) override;
  21. // Saving / restoring state for replay
  22. virtual void SaveState(StateRecorder &inStream) const override;
  23. virtual void RestoreState(StateRecorder &inStream) override;
  24. private:
  25. int mPrevMode = -1; // Previous mode
  26. float mTime = 0.0f; // Total elapsed time
  27. BodyID mSensorID; // Body ID of the sensor
  28. BodyIDVector mBodyIDs; // List of dynamic bodies
  29. };