Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
MutableCompoundShape.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
8
10
12
15{
17
18public:
19 // See: ShapeSettings
20 virtual ShapeResult Create() const override;
21};
22
33{
34public:
36
39 MutableCompoundShape(const MutableCompoundShapeSettings &inSettings, ShapeResult &outResult);
40
42 Ref<MutableCompoundShape> Clone() const;
43
44 // See Shape::CastRay
45 virtual bool CastRay(const RayCast &inRay, const SubShapeIDCreator &inSubShapeIDCreator, RayCastResult &ioHit) const override;
46 virtual void CastRay(const RayCast &inRay, const RayCastSettings &inRayCastSettings, const SubShapeIDCreator &inSubShapeIDCreator, CastRayCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override;
47
48 // See: Shape::CollidePoint
49 virtual void CollidePoint(Vec3Arg inPoint, const SubShapeIDCreator &inSubShapeIDCreator, CollidePointCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override;
50
51 // See Shape::CollectTransformedShapes
52 virtual void CollectTransformedShapes(const AABox &inBox, Vec3Arg inPositionCOM, QuatArg inRotation, Vec3Arg inScale, const SubShapeIDCreator &inSubShapeIDCreator, TransformedShapeCollector &ioCollector, const ShapeFilter &inShapeFilter) const override;
53
54 // See: CompoundShape::GetIntersectingSubShapes
55 virtual int GetIntersectingSubShapes(const AABox &inBox, uint *outSubShapeIndices, int inMaxSubShapeIndices) const override;
56
57 // See: CompoundShape::GetIntersectingSubShapes
58 virtual int GetIntersectingSubShapes(const OrientedBox &inBox, uint *outSubShapeIndices, int inMaxSubShapeIndices) const override;
59
60 // See Shape
61 virtual void SaveBinaryState(StreamOut &inStream) const override;
62
63 // See Shape::GetStats
64 virtual Stats GetStats() const override { return Stats(sizeof(*this) + mSubShapes.size() * sizeof(SubShape) + mSubShapeBounds.size() * sizeof(Bounds), 0); }
65
68
77 uint AddShape(Vec3Arg inPosition, QuatArg inRotation, const Shape *inShape, uint32 inUserData = 0, uint inIndex = UINT_MAX);
78
81 void RemoveShape(uint inIndex);
82
85 void ModifyShape(uint inIndex, Vec3Arg inPosition, QuatArg inRotation);
86
89 void ModifyShape(uint inIndex, Vec3Arg inPosition, QuatArg inRotation, const Shape *inShape);
90
99 void ModifyShapes(uint inStartIndex, uint inNumber, const Vec3 *inPositions, const Quat *inRotations, uint inPositionStride = sizeof(Vec3), uint inRotationStride = sizeof(Quat));
100
111 void ModifyShapes(uint inStartIndex, uint inNumber, const Vec3 *inPositions, const Quat *inRotations, const Shape * const *inShapes, uint inPositionStride = sizeof(Vec3), uint inRotationStride = sizeof(Quat), uint inShapeStride = sizeof(const Shape *));
112
117 void AdjustCenterOfMass();
118
120
121 // Register shape functions with the registry
122 static void sRegister();
123
124protected:
125 // See: Shape::RestoreBinaryState
126 virtual void RestoreBinaryState(StreamIn &inStream) override;
127
128private:
129 // Visitor for GetIntersectingSubShapes
130 template <class BoxType>
131 struct GetIntersectingSubShapesVisitorMC : public GetIntersectingSubShapesVisitor<BoxType>
132 {
133 using GetIntersectingSubShapesVisitor<BoxType>::GetIntersectingSubShapesVisitor;
134
135 using Result = UVec4;
136
137 JPH_INLINE Result TestBlock(Vec4Arg inBoundsMinX, Vec4Arg inBoundsMinY, Vec4Arg inBoundsMinZ, Vec4Arg inBoundsMaxX, Vec4Arg inBoundsMaxY, Vec4Arg inBoundsMaxZ) const
138 {
139 return GetIntersectingSubShapesVisitor<BoxType>::TestBounds(inBoundsMinX, inBoundsMinY, inBoundsMinZ, inBoundsMaxX, inBoundsMaxY, inBoundsMaxZ);
140 }
141
142 JPH_INLINE bool ShouldVisitBlock(UVec4Arg inResult) const
143 {
144 return inResult.TestAnyTrue();
145 }
146
147 JPH_INLINE bool ShouldVisitSubShape(UVec4Arg inResult, uint inIndexInBlock) const
148 {
149 return inResult[inIndexInBlock] != 0;
150 }
151 };
152
154 inline uint GetNumBlocks() const { return ((uint)mSubShapes.size() + 3) >> 2; }
155
157 void EnsureSubShapeBoundsCapacity();
158
162 void CalculateSubShapeBounds(uint inStartIdx, uint inNumber);
163
165 void CalculateLocalBounds();
166
167 template <class Visitor>
168 JPH_INLINE void WalkSubShapes(Visitor &ioVisitor) const;
169
170 // Helper functions called by CollisionDispatch
171 static void sCollideCompoundVsShape(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);
172 static void sCollideShapeVsCompound(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);
173 static void sCastShapeVsCompound(const ShapeCast &inShapeCast, const ShapeCastSettings &inShapeCastSettings, const Shape *inShape, Vec3Arg inScale, const ShapeFilter &inShapeFilter, Mat44Arg inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, const SubShapeIDCreator &inSubShapeIDCreator2, CastShapeCollector &ioCollector);
174
175 struct Bounds
176 {
177 Vec4 mMinX;
178 Vec4 mMinY;
179 Vec4 mMinZ;
180 Vec4 mMaxX;
181 Vec4 mMaxY;
182 Vec4 mMaxZ;
183 };
184
185 Array<Bounds> mSubShapeBounds;
186};
187
#define JPH_EXPORT
Definition Core.h:303
unsigned int uint
Definition Core.h:564
#define JPH_NAMESPACE_END
Definition Core.h:487
std::uint32_t uint32
Definition Core.h:567
#define JPH_NAMESPACE_BEGIN
Definition Core.h:481
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:51
#define JPH_DECLARE_SERIALIZABLE_VIRTUAL(linkage, class_name)
Definition SerializableObject.h:109
EShapeSubType
This enumerates all shape types, each shape can return its type through Shape::GetSubType.
Definition Shape.h:76
Axis aligned box.
Definition AABox.h:16
Definition Array.h:22
Settings to be passed with a collision query.
Definition CollideShape.h:94
Virtual interface that allows collecting multiple collision results.
Definition CollisionCollector.h:45
Base class for a compound shape.
Definition CompoundShape.h:53
Base class settings to construct a compound shape.
Definition CompoundShape.h:18
void AddShape(Vec3Arg inPosition, QuatArg inRotation, const ShapeSettings *inShape, uint32 inUserData=0)
Add a shape to the compound.
Definition CompoundShape.cpp:37
Holds a 4x4 matrix of floats, but supports also operations on the 3x3 upper left part of the matrix.
Definition Mat44.h:13
Definition MutableCompoundShape.h:33
JPH_OVERRIDE_NEW_DELETE MutableCompoundShape()
Constructor.
Definition MutableCompoundShape.h:38
virtual Stats GetStats() const override
Get stats of this shape. Use for logging / data collection purposes only. Does not add values from ch...
Definition MutableCompoundShape.h:64
Class that constructs a MutableCompoundShape.
Definition MutableCompoundShape.h:15
Oriented box.
Definition OrientedBox.h:18
Definition Quat.h:33
Specialization of cast result against a shape.
Definition CastResult.h:30
Settings to be passed with a ray cast.
Definition RayCast.h:70
Definition Reference.h:110
Settings to be passed with a shape cast.
Definition ShapeCast.h:92
Filter class.
Definition ShapeFilter.h:17
Base class for all shapes (collision volume of a body). Defines a virtual interface for collision det...
Definition Shape.h:185
virtual ShapeResult Create() const =0
Create a shape according to the settings specified by this object.
Simple binary input stream.
Definition StreamIn.h:13
Simple binary output stream.
Definition StreamOut.h:13
Definition SubShapeID.h:108
Definition UVec4.h:12
JPH_INLINE bool TestAnyTrue() const
Test if any of the components are true (true is when highest bit of component is set)
Definition UVec4.inl:648
Definition Vec3.h:17
Definition Vec4.h:14
Definition CompoundShape.h:142
Definition RayCast.h:47
Class that holds information about the shape that can be used for logging / data collection purposes.
Definition Shape.h:407
Definition ShapeCast.h:69