DecoratedShape.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. #include <Jolt/Physics/Collision/Shape/Shape.h>
  5. JPH_NAMESPACE_BEGIN
  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. JPH_OVERRIDE_NEW_DELETE
  23. /// Constructor
  24. explicit DecoratedShape(EShapeSubType inSubType) : Shape(EShapeType::Decorated, inSubType) { }
  25. DecoratedShape(EShapeSubType inSubType, const Shape *inInnerShape) : Shape(EShapeType::Decorated, inSubType), mInnerShape(inInnerShape) { }
  26. DecoratedShape(EShapeSubType inSubType, const DecoratedShapeSettings &inSettings, ShapeResult &outResult);
  27. /// Access to the decorated inner shape
  28. const Shape * GetInnerShape() const { return mInnerShape; }
  29. // See Shape::MustBeStatic
  30. virtual bool MustBeStatic() const override { return mInnerShape->MustBeStatic(); }
  31. // See Shape::GetCenterOfMass
  32. virtual Vec3 GetCenterOfMass() const override { return mInnerShape->GetCenterOfMass(); }
  33. // See Shape::GetSubShapeIDBitsRecursive
  34. virtual uint GetSubShapeIDBitsRecursive() const override { return mInnerShape->GetSubShapeIDBitsRecursive(); }
  35. // See Shape::GetMaterial
  36. virtual const PhysicsMaterial * GetMaterial(const SubShapeID &inSubShapeID) const override;
  37. // See Shape::GetSupportingFace
  38. virtual void GetSupportingFace(const SubShapeID &inSubShapeID, Vec3Arg inDirection, Vec3Arg inScale, Mat44Arg inCenterOfMassTransform, SupportingFace &outVertices) const override;
  39. // See Shape::GetSubShapeUserData
  40. virtual uint64 GetSubShapeUserData(const SubShapeID &inSubShapeID) const override;
  41. // See Shape
  42. virtual void SaveSubShapeState(ShapeList &outSubShapes) const override;
  43. virtual void RestoreSubShapeState(const ShapeRefC *inSubShapes, uint inNumShapes) override;
  44. // See Shape::GetStatsRecursive
  45. virtual Stats GetStatsRecursive(VisitedShapes &ioVisitedShapes) const override;
  46. protected:
  47. RefConst<Shape> mInnerShape;
  48. };
  49. JPH_NAMESPACE_END