DeformedHeightFieldShapeTest.h 1.5 KB

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