DecoratedShape.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. #include <Physics/Collision/Shape/Shape.h>
  5. namespace JPH {
  6. /// Class that constructs a DecoratedShape
  7. class DecoratedShapeSettings : public ShapeSettings
  8. {
  9. JPH_DECLARE_SERIALIZABLE_VIRTUAL(DecoratedShapeSettings)
  10. /// Default constructor for deserialization
  11. DecoratedShapeSettings() = default;
  12. /// Constructor that decorates another shape
  13. explicit DecoratedShapeSettings(const ShapeSettings *inShape) : mInnerShape(inShape) { }
  14. explicit DecoratedShapeSettings(const Shape *inShape) : mInnerShapePtr(inShape) { }
  15. RefConst<ShapeSettings> mInnerShape; ///< Sub shape (either this or mShapePtr needs to be filled up)
  16. RefConst<Shape> mInnerShapePtr; ///< Sub shape (either this or mShape needs to be filled up)
  17. };
  18. /// Base class for shapes that decorate another shape with extra functionality (e.g. scale, translation etc.)
  19. class DecoratedShape : public Shape
  20. {
  21. public:
  22. /// Constructor
  23. explicit DecoratedShape(EShapeSubType inSubType) : Shape(EShapeType::Decorated, inSubType) { }
  24. DecoratedShape(EShapeSubType inSubType, const Shape *inInnerShape) : Shape(EShapeType::Decorated, inSubType), mInnerShape(inInnerShape) { }
  25. DecoratedShape(EShapeSubType inSubType, const DecoratedShapeSettings &inSettings, ShapeResult &outResult);
  26. /// Access to the decorated inner shape
  27. const Shape * GetInnerShape() const { return mInnerShape; }
  28. // See Shape::MustBeStatic
  29. virtual bool MustBeStatic() const override { return mInnerShape->MustBeStatic(); }
  30. // See Shape::GetSubShapeIDBitsRecursive
  31. virtual uint GetSubShapeIDBitsRecursive() const override { return mInnerShape->GetSubShapeIDBitsRecursive(); }
  32. // See Shape::GetMaterial
  33. virtual const PhysicsMaterial * GetMaterial(const SubShapeID &inSubShapeID) const override;
  34. // See Shape::GetSubShapeUserData
  35. virtual uint32 GetSubShapeUserData(const SubShapeID &inSubShapeID) const override;
  36. // See Shape
  37. virtual void SaveSubShapeState(ShapeList &outSubShapes) const override;
  38. virtual void RestoreSubShapeState(const ShapeRefC *inSubShapes, uint inNumShapes) override;
  39. // See Shape::GetStatsRecursive
  40. virtual Stats GetStatsRecursive(VisitedShapes &ioVisitedShapes) const override;
  41. protected:
  42. RefConst<Shape> mInnerShape;
  43. };
  44. } // JPH