Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/Collision/Shape/ScaledShape.h
9913 views
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)1// SPDX-FileCopyrightText: 2021 Jorrit Rouwe2// SPDX-License-Identifier: MIT34#pragma once56#include <Jolt/Physics/Collision/Shape/DecoratedShape.h>7#include <Jolt/Physics/Collision/Shape/ScaleHelpers.h>89JPH_NAMESPACE_BEGIN1011class SubShapeIDCreator;12class CollideShapeSettings;1314/// Class that constructs a ScaledShape15class JPH_EXPORT ScaledShapeSettings final : public DecoratedShapeSettings16{17JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, ScaledShapeSettings)1819public:20/// Default constructor for deserialization21ScaledShapeSettings() = default;2223/// Constructor that decorates another shape with a scale24ScaledShapeSettings(const ShapeSettings *inShape, Vec3Arg inScale) : DecoratedShapeSettings(inShape), mScale(inScale) { }2526/// Variant that uses a concrete shape, which means this object cannot be serialized.27ScaledShapeSettings(const Shape *inShape, Vec3Arg inScale) : DecoratedShapeSettings(inShape), mScale(inScale) { }2829// See: ShapeSettings30virtual ShapeResult Create() const override;3132Vec3 mScale = Vec3(1, 1, 1);33};3435/// A shape that scales a child shape in local space of that shape. The scale can be non-uniform and can even turn it inside out when one or three components of the scale are negative.36class JPH_EXPORT ScaledShape final : public DecoratedShape37{38public:39JPH_OVERRIDE_NEW_DELETE4041/// Constructor42ScaledShape() : DecoratedShape(EShapeSubType::Scaled) { }43ScaledShape(const ScaledShapeSettings &inSettings, ShapeResult &outResult);4445/// Constructor that decorates another shape with a scale46ScaledShape(const Shape *inShape, Vec3Arg inScale) : DecoratedShape(EShapeSubType::Scaled, inShape), mScale(inScale) { JPH_ASSERT(!ScaleHelpers::IsZeroScale(mScale)); }4748/// Get the scale49Vec3 GetScale() const { return mScale; }5051// See Shape::GetCenterOfMass52virtual Vec3 GetCenterOfMass() const override { return mScale * mInnerShape->GetCenterOfMass(); }5354// See Shape::GetLocalBounds55virtual AABox GetLocalBounds() const override;5657// See Shape::GetWorldSpaceBounds58virtual AABox GetWorldSpaceBounds(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale) const override;59using Shape::GetWorldSpaceBounds;6061// See Shape::GetInnerRadius62virtual float GetInnerRadius() const override { return mScale.ReduceMin() * mInnerShape->GetInnerRadius(); }6364// See Shape::GetMassProperties65virtual MassProperties GetMassProperties() const override;6667// See Shape::GetSubShapeTransformedShape68virtual TransformedShape GetSubShapeTransformedShape(const SubShapeID &inSubShapeID, Vec3Arg inPositionCOM, QuatArg inRotation, Vec3Arg inScale, SubShapeID &outRemainder) const override;6970// See Shape::GetSurfaceNormal71virtual Vec3 GetSurfaceNormal(const SubShapeID &inSubShapeID, Vec3Arg inLocalSurfacePosition) const override;7273// See Shape::GetSupportingFace74virtual void GetSupportingFace(const SubShapeID &inSubShapeID, Vec3Arg inDirection, Vec3Arg inScale, Mat44Arg inCenterOfMassTransform, SupportingFace &outVertices) const override;7576// See Shape::GetSubmergedVolume77virtual void GetSubmergedVolume(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, const Plane &inSurface, float &outTotalVolume, float &outSubmergedVolume, Vec3 &outCenterOfBuoyancy JPH_IF_DEBUG_RENDERER(, RVec3Arg inBaseOffset)) const override;7879#ifdef JPH_DEBUG_RENDERER80// See Shape::Draw81virtual void Draw(DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale, ColorArg inColor, bool inUseMaterialColors, bool inDrawWireframe) const override;8283// See Shape::DrawGetSupportFunction84virtual void DrawGetSupportFunction(DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale, ColorArg inColor, bool inDrawSupportDirection) const override;8586// See Shape::DrawGetSupportingFace87virtual void DrawGetSupportingFace(DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale) const override;88#endif // JPH_DEBUG_RENDERER8990// See Shape::CastRay91virtual bool CastRay(const RayCast &inRay, const SubShapeIDCreator &inSubShapeIDCreator, RayCastResult &ioHit) const override;92virtual void CastRay(const RayCast &inRay, const RayCastSettings &inRayCastSettings, const SubShapeIDCreator &inSubShapeIDCreator, CastRayCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override;9394// See: Shape::CollidePoint95virtual void CollidePoint(Vec3Arg inPoint, const SubShapeIDCreator &inSubShapeIDCreator, CollidePointCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override;9697// See: Shape::CollideSoftBodyVertices98virtual void CollideSoftBodyVertices(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, const CollideSoftBodyVertexIterator &inVertices, uint inNumVertices, int inCollidingShapeIndex) const override;99100// See Shape::CollectTransformedShapes101virtual void CollectTransformedShapes(const AABox &inBox, Vec3Arg inPositionCOM, QuatArg inRotation, Vec3Arg inScale, const SubShapeIDCreator &inSubShapeIDCreator, TransformedShapeCollector &ioCollector, const ShapeFilter &inShapeFilter) const override;102103// See Shape::TransformShape104virtual void TransformShape(Mat44Arg inCenterOfMassTransform, TransformedShapeCollector &ioCollector) const override;105106// See Shape::GetTrianglesStart107virtual void GetTrianglesStart(GetTrianglesContext &ioContext, const AABox &inBox, Vec3Arg inPositionCOM, QuatArg inRotation, Vec3Arg inScale) const override { JPH_ASSERT(false, "Cannot call on non-leaf shapes, use CollectTransformedShapes to collect the leaves first!"); }108109// See Shape::GetTrianglesNext110virtual int GetTrianglesNext(GetTrianglesContext &ioContext, int inMaxTrianglesRequested, Float3 *outTriangleVertices, const PhysicsMaterial **outMaterials = nullptr) const override { JPH_ASSERT(false, "Cannot call on non-leaf shapes, use CollectTransformedShapes to collect the leaves first!"); return 0; }111112// See Shape113virtual void SaveBinaryState(StreamOut &inStream) const override;114115// See Shape::GetStats116virtual Stats GetStats() const override { return Stats(sizeof(*this), 0); }117118// See Shape::GetVolume119virtual float GetVolume() const override;120121// See Shape::IsValidScale122virtual bool IsValidScale(Vec3Arg inScale) const override;123124// See Shape::MakeScaleValid125virtual Vec3 MakeScaleValid(Vec3Arg inScale) const override;126127// Register shape functions with the registry128static void sRegister();129130protected:131// See: Shape::RestoreBinaryState132virtual void RestoreBinaryState(StreamIn &inStream) override;133134private:135// Helper functions called by CollisionDispatch136static void sCollideScaledVsShape(const Shape *inShape1, const Shape *inShape2, Vec3Arg inScale1, Vec3Arg inScale2, Mat44Arg inCenterOfMassTransform1, Mat44Arg inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, const SubShapeIDCreator &inSubShapeIDCreator2, const CollideShapeSettings &inCollideShapeSettings, CollideShapeCollector &ioCollector, const ShapeFilter &inShapeFilter);137static void sCollideShapeVsScaled(const Shape *inShape1, const Shape *inShape2, Vec3Arg inScale1, Vec3Arg inScale2, Mat44Arg inCenterOfMassTransform1, Mat44Arg inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, const SubShapeIDCreator &inSubShapeIDCreator2, const CollideShapeSettings &inCollideShapeSettings, CollideShapeCollector &ioCollector, const ShapeFilter &inShapeFilter);138static void sCastScaledVsShape(const ShapeCast &inShapeCast, const ShapeCastSettings &inShapeCastSettings, const Shape *inShape, Vec3Arg inScale, const ShapeFilter &inShapeFilter, Mat44Arg inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, const SubShapeIDCreator &inSubShapeIDCreator2, CastShapeCollector &ioCollector);139static void sCastShapeVsScaled(const ShapeCast &inShapeCast, const ShapeCastSettings &inShapeCastSettings, const Shape *inShape, Vec3Arg inScale, const ShapeFilter &inShapeFilter, Mat44Arg inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, const SubShapeIDCreator &inSubShapeIDCreator2, CastShapeCollector &ioCollector);140141Vec3 mScale = Vec3(1, 1, 1);142};143144JPH_NAMESPACE_END145146147