DeformedHeightFieldShapeTest.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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/Shape/HeightFieldShape.h>
  7. class DeformedHeightFieldShapeTest : public Test
  8. {
  9. public:
  10. JPH_DECLARE_RTTI_VIRTUAL(JPH_NO_EXPORT, DeformedHeightFieldShapeTest)
  11. // Description of the test
  12. virtual const char * GetDescription() const override
  13. {
  14. return "Shows how to deform a height field shape after it has been created.";
  15. }
  16. // Initialize the test
  17. virtual void Initialize() override;
  18. // Update the test, called before the physics update
  19. virtual void PrePhysicsUpdate(const PreUpdateParams &inParams) override;
  20. // Test will never be deterministic since we're modifying the height field shape and not saving it
  21. virtual bool IsDeterministic() const override { return false; }
  22. private:
  23. // Get the center of the path at time inTime, this follows a path that resembles the Jolt logo
  24. Vec3 GetPathCenter(float inTime) const;
  25. // Size of the terrain
  26. static constexpr int cSampleCount = 128;
  27. // Size of a block in the terrain
  28. static constexpr int cBlockSize = 4;
  29. // Bits to mask out index within a block
  30. static constexpr int cBlockMask = cBlockSize - 1;
  31. // The list of original height samples, we keep this to avoid precision loss of repeatedly decompressing and recompressing height samples
  32. Array<float> mHeightSamples;
  33. // The height field shape
  34. Ref<HeightFieldShape> mHeightField;
  35. // ID of the height field body
  36. BodyID mHeightFieldID;
  37. // Current time
  38. float mTime = 0.0f;
  39. };