ModifyMassTest.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2023 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. #include <Tests/Test.h>
  6. #include <Jolt/Physics/Collision/ContactListener.h>
  7. class ModifyMassTest : public Test, public ContactListener
  8. {
  9. public:
  10. JPH_DECLARE_RTTI_VIRTUAL(JPH_NO_EXPORT, ModifyMassTest)
  11. // Description of the test
  12. virtual const char * GetDescription() const override
  13. {
  14. return "Uses a contact listener to modify the mass of bodies per contacting body pair.\n"
  15. "Can be used to e.g. make a dynamic body respond normally to one body and appear to have infinite mass for another.";
  16. }
  17. // See: Test
  18. virtual void Initialize() override;
  19. virtual void PrePhysicsUpdate(const PreUpdateParams &inParams) override;
  20. virtual void SaveState(StateRecorder &inStream) const override;
  21. virtual void RestoreState(StateRecorder &inStream) override;
  22. // If this test implements a contact listener, it should be returned here
  23. virtual ContactListener * GetContactListener() override { return this; }
  24. // See: ContactListener
  25. virtual void OnContactAdded(const Body &inBody1, const Body &inBody2, const ContactManifold &inManifold, ContactSettings &ioSettings) override;
  26. virtual void OnContactPersisted(const Body &inBody1, const Body &inBody2, const ContactManifold &inManifold, ContactSettings &ioSettings) override;
  27. private:
  28. // Get the scale factor for a body based on its user data
  29. static float sGetInvMassScale(const Body &inBody);
  30. // Reset the bodies to their initial states
  31. void ResetBodies(int inCycle);
  32. // Update the labels on the bodies
  33. void UpdateLabels();
  34. float mTime = 0.0f;
  35. BodyID mBodies[2];
  36. };