DecoratedShape.h 2.8 KB

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