DecoratedShape.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 JPH_EXPORT DecoratedShapeSettings : public ShapeSettings
  9. {
  10. JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, DecoratedShapeSettings)
  11. public:
  12. /// Default constructor for deserialization
  13. DecoratedShapeSettings() = default;
  14. /// Constructor that decorates another shape
  15. explicit DecoratedShapeSettings(const ShapeSettings *inShape) : mInnerShape(inShape) { }
  16. explicit DecoratedShapeSettings(const Shape *inShape) : mInnerShapePtr(inShape) { }
  17. RefConst<ShapeSettings> mInnerShape; ///< Sub shape (either this or mShapePtr needs to be filled up)
  18. RefConst<Shape> mInnerShapePtr; ///< Sub shape (either this or mShape needs to be filled up)
  19. };
  20. /// Base class for shapes that decorate another shape with extra functionality (e.g. scale, translation etc.)
  21. class JPH_EXPORT DecoratedShape : public Shape
  22. {
  23. public:
  24. JPH_OVERRIDE_NEW_DELETE
  25. /// Constructor
  26. explicit DecoratedShape(EShapeSubType inSubType) : Shape(EShapeType::Decorated, inSubType) { }
  27. DecoratedShape(EShapeSubType inSubType, const Shape *inInnerShape) : Shape(EShapeType::Decorated, inSubType), mInnerShape(inInnerShape) { }
  28. DecoratedShape(EShapeSubType inSubType, const DecoratedShapeSettings &inSettings, ShapeResult &outResult);
  29. /// Access to the decorated inner shape
  30. const Shape * GetInnerShape() const { return mInnerShape; }
  31. // See Shape::MustBeStatic
  32. virtual bool MustBeStatic() const override { return mInnerShape->MustBeStatic(); }
  33. // See Shape::GetCenterOfMass
  34. virtual Vec3 GetCenterOfMass() const override { return mInnerShape->GetCenterOfMass(); }
  35. // See Shape::GetSubShapeIDBitsRecursive
  36. virtual uint GetSubShapeIDBitsRecursive() const override { return mInnerShape->GetSubShapeIDBitsRecursive(); }
  37. // See Shape::GetLeafShape
  38. virtual const Shape * GetLeafShape(const SubShapeID &inSubShapeID, SubShapeID &outRemainder) const override { return mInnerShape->GetLeafShape(inSubShapeID, outRemainder); }
  39. // See Shape::GetMaterial
  40. virtual const PhysicsMaterial * GetMaterial(const SubShapeID &inSubShapeID) const override;
  41. // See Shape::GetSupportingFace
  42. virtual void GetSupportingFace(const SubShapeID &inSubShapeID, Vec3Arg inDirection, Vec3Arg inScale, Mat44Arg inCenterOfMassTransform, SupportingFace &outVertices) const override;
  43. // See Shape::GetSubShapeUserData
  44. virtual uint64 GetSubShapeUserData(const SubShapeID &inSubShapeID) const override;
  45. // See Shape
  46. virtual void SaveSubShapeState(ShapeList &outSubShapes) const override;
  47. virtual void RestoreSubShapeState(const ShapeRefC *inSubShapes, uint inNumShapes) override;
  48. // See Shape::GetStatsRecursive
  49. virtual Stats GetStatsRecursive(VisitedShapes &ioVisitedShapes) const override;
  50. // See Shape::IsValidScale
  51. virtual bool IsValidScale(Vec3Arg inScale) const override { return mInnerShape->IsValidScale(inScale); }
  52. // See Shape::MakeScaleValid
  53. virtual Vec3 MakeScaleValid(Vec3Arg inScale) const override { return mInnerShape->MakeScaleValid(inScale); }
  54. protected:
  55. RefConst<Shape> mInnerShape;
  56. };
  57. JPH_NAMESPACE_END