Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
StaticCompoundShape.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
10
12
14class TempAllocator;
15
18{
20
21public:
24 virtual ShapeResult Create() const override;
25
27 ShapeResult Create(TempAllocator &inTempAllocator) const;
28};
29
34{
35public:
37
40 StaticCompoundShape(const StaticCompoundShapeSettings &inSettings, TempAllocator &inTempAllocator, ShapeResult &outResult);
41
42 // See Shape::CastRay
43 virtual bool CastRay(const RayCast &inRay, const SubShapeIDCreator &inSubShapeIDCreator, RayCastResult &ioHit) const override;
44 virtual void CastRay(const RayCast &inRay, const RayCastSettings &inRayCastSettings, const SubShapeIDCreator &inSubShapeIDCreator, CastRayCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override;
45
46 // See: Shape::CollidePoint
47 virtual void CollidePoint(Vec3Arg inPoint, const SubShapeIDCreator &inSubShapeIDCreator, CollidePointCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override;
48
49 // See Shape::CollectTransformedShapes
50 virtual void CollectTransformedShapes(const AABox &inBox, Vec3Arg inPositionCOM, QuatArg inRotation, Vec3Arg inScale, const SubShapeIDCreator &inSubShapeIDCreator, TransformedShapeCollector &ioCollector, const ShapeFilter &inShapeFilter) const override;
51
52 // See: CompoundShape::GetIntersectingSubShapes
53 virtual int GetIntersectingSubShapes(const AABox &inBox, uint *outSubShapeIndices, int inMaxSubShapeIndices) const override;
54
55 // See: CompoundShape::GetIntersectingSubShapes
56 virtual int GetIntersectingSubShapes(const OrientedBox &inBox, uint *outSubShapeIndices, int inMaxSubShapeIndices) const override;
57
58 // See Shape
59 virtual void SaveBinaryState(StreamOut &inStream) const override;
60
61 // See Shape::GetStats
62 virtual Stats GetStats() const override { return Stats(sizeof(*this) + mSubShapes.size() * sizeof(SubShape) + mNodes.size() * sizeof(Node), 0); }
63
64 // Register shape functions with the registry
65 static void sRegister();
66
67protected:
68 // See: Shape::RestoreBinaryState
69 virtual void RestoreBinaryState(StreamIn &inStream) override;
70
71private:
72 // Visitor for GetIntersectingSubShapes
73 template <class BoxType>
74 struct GetIntersectingSubShapesVisitorSC : public GetIntersectingSubShapesVisitor<BoxType>
75 {
76 using GetIntersectingSubShapesVisitor<BoxType>::GetIntersectingSubShapesVisitor;
77
78 JPH_INLINE bool ShouldVisitNode(int inStackTop) const
79 {
80 return true;
81 }
82
83 JPH_INLINE int VisitNodes(Vec4Arg inBoundsMinX, Vec4Arg inBoundsMinY, Vec4Arg inBoundsMinZ, Vec4Arg inBoundsMaxX, Vec4Arg inBoundsMaxY, Vec4Arg inBoundsMaxZ, UVec4 &ioProperties, int inStackTop)
84 {
85 // Test if point overlaps with box
86 UVec4 collides = GetIntersectingSubShapesVisitor<BoxType>::TestBounds(inBoundsMinX, inBoundsMinY, inBoundsMinZ, inBoundsMaxX, inBoundsMaxY, inBoundsMaxZ);
87 return CountAndSortTrues(collides, ioProperties);
88 }
89 };
90
93 static void sPartition(uint *ioBodyIdx, AABox *ioBounds, int inNumber, int &outMidPoint);
94
98 static void sPartition4(uint *ioBodyIdx, AABox *ioBounds, int inBegin, int inEnd, int *outSplit);
99
100 // Helper functions called by CollisionDispatch
101 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);
102 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);
103 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);
104
105 // Maximum size of the stack during tree walk
106 static constexpr int cStackSize = 128;
107
108 template <class Visitor>
109 JPH_INLINE void WalkTree(Visitor &ioVisitor) const;
110
112 enum : uint32
113 {
114 IS_SUBSHAPE = 0x80000000,
115 INVALID_NODE = 0x7fffffff,
116 };
117
119 struct Node
120 {
121 void SetChildBounds(uint inIndex, const AABox &inBounds);
122 void SetChildInvalid(uint inIndex);
123
124 HalfFloat mBoundsMinX[4];
125 HalfFloat mBoundsMinY[4];
126 HalfFloat mBoundsMinZ[4];
127 HalfFloat mBoundsMaxX[4];
128 HalfFloat mBoundsMaxY[4];
129 HalfFloat mBoundsMaxZ[4];
130 uint32 mNodeProperties[4];
131 };
132
133 static_assert(sizeof(Node) == 64, "Node should be 64 bytes");
134
135 using Nodes = Array<Node>;
136
137 Nodes mNodes;
138};
139
#define JPH_EXPORT
Definition Core.h:283
unsigned int uint
Definition Core.h:510
#define JPH_NAMESPACE_END
Definition Core.h:434
std::uint32_t uint32
Definition Core.h:513
#define JPH_NAMESPACE_BEGIN
Definition Core.h:428
uint16 HalfFloat
Definition HalfFloat.h:12
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:50
#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
JPH_INLINE int CountAndSortTrues(UVec4Arg inValue, UVec4 &ioIdentifiers)
Definition SortReverseAndStore.h:39
Axis aligned box.
Definition AABox.h:16
Definition Array.h:36
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
Holds a 4x4 matrix of floats, but supports also operations on the 3x3 upper left part of the matrix.
Definition Mat44.h:13
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
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.
Definition StaticCompoundShape.h:34
JPH_OVERRIDE_NEW_DELETE StaticCompoundShape()
Constructor.
Definition StaticCompoundShape.h:39
virtual Stats GetStats() const override
Get stats of this shape. Use for logging / data collection purposes only. Does not add values from ch...
Definition StaticCompoundShape.h:62
Class that constructs a StaticCompoundShape. Note that if you only want a compound of 1 shape,...
Definition StaticCompoundShape.h:18
Simple binary input stream.
Definition StreamIn.h:13
Simple binary output stream.
Definition StreamOut.h:13
Definition SubShapeID.h:108
Definition TempAllocator.h:16
Definition UVec4.h:12
Definition Vec3.h:17
Definition Vec4.h:14
constexpr int cStackSize
Stack size to use during WalkHeightField.
Definition HeightFieldShape.h:26
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