Debian Codegraph @

thirdparty/jolt_physics/Jolt/Physics/Collision/Shape/EmptyShape.cpp

raw symbols SCIP
1 // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2 // SPDX-FileCopyrightText: 2024 Jorrit Rouwe
3 // SPDX-License-Identifier: MIT
4
5 #include <Jolt/Jolt.h>
6
7 #include <Jolt/Physics/Collision/Shape/EmptyShape.h>
8 #include <Jolt/Physics/Collision/CollisionDispatch.h>
9 #include <Jolt/ObjectStream/TypeDeclarations.h>
10 #ifdef JPH_DEBUG_RENDERER
11 #include <Jolt/Renderer/DebugRenderer.h>
12 #endif // JPH_DEBUG_RENDERER
13
14 JPH_NAMESPACE_BEGIN
15
16 JPH_IMPLEMENT_SERIALIZABLE_VIRTUAL(EmptyShapeSettings)
17 {
18 JPH_ADD_BASE_CLASS(EmptyShapeSettings, ShapeSettings)
19
20 JPH_ADD_ATTRIBUTE(EmptyShapeSettings, mCenterOfMass)
21 }
22
23 ShapeSettings::ShapeResult EmptyShapeSettings::Create() const
24 {
25 if (mCachedResult.IsEmpty())
26 new EmptyShape(*this, mCachedResult);
27
28 return mCachedResult;
29 }
30
31 MassProperties EmptyShape::GetMassProperties() const
32 {
33 MassProperties mass_properties;
34 mass_properties.mMass = 1.0f;
35 mass_properties.mInertia = Mat44::sIdentity();
36 return mass_properties;
37 }
38
39 #ifdef JPH_DEBUG_RENDERER
40 void EmptyShape::Draw(DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale, ColorArg inColor, [[maybe_unused]] bool inUseMaterialColors, [[maybe_unused]] bool inDrawWireframe) const
41 {
42 inRenderer->DrawMarker(inCenterOfMassTransform.GetTranslation(), inColor, abs(inScale.GetX()) * 0.1f);
43 }
44 #endif // JPH_DEBUG_RENDERER
45
46 void EmptyShape::sRegister()
47 {
48 ShapeFunctions &f = ShapeFunctions::sGet(EShapeSubType::Empty);
49 f.mConstruct = []() -> Shape * { return new EmptyShape; };
50 f.mColor = Color::sBlack;
51
52 auto collide_empty = []([[maybe_unused]] const Shape *inShape1, [[maybe_unused]] const Shape *inShape2, [[maybe_unused]] Vec3Arg inScale1, [[maybe_unused]] Vec3Arg inScale2, [[maybe_unused]] Mat44Arg inCenterOfMassTransform1, [[maybe_unused]] Mat44Arg inCenterOfMassTransform2, [[maybe_unused]] const SubShapeIDCreator &inSubShapeIDCreator1, [[maybe_unused]] const SubShapeIDCreator &inSubShapeIDCreator2, [[maybe_unused]] const CollideShapeSettings &inCollideShapeSettings, [[maybe_unused]] CollideShapeCollector &ioCollector, [[maybe_unused]] const ShapeFilter &inShapeFilter) { /* Do Nothing */ };
53 auto cast_empty = []([[maybe_unused]] const ShapeCast &inShapeCast, [[maybe_unused]] const ShapeCastSettings &inShapeCastSettings, [[maybe_unused]] const Shape *inShape, [[maybe_unused]] Vec3Arg inScale, [[maybe_unused]] const ShapeFilter &inShapeFilter, [[maybe_unused]] Mat44Arg inCenterOfMassTransform2, [[maybe_unused]] const SubShapeIDCreator &inSubShapeIDCreator1, [[maybe_unused]] const SubShapeIDCreator &inSubShapeIDCreator2, [[maybe_unused]] CastShapeCollector &ioCollector) { /* Do nothing */ };
54
55 for (const EShapeSubType s : sAllSubShapeTypes)
56 {
57 CollisionDispatch::sRegisterCollideShape(EShapeSubType::Empty, s, collide_empty);
58 CollisionDispatch::sRegisterCollideShape(s, EShapeSubType::Empty, collide_empty);
59
60 CollisionDispatch::sRegisterCastShape(EShapeSubType::Empty, s, cast_empty);
61 CollisionDispatch::sRegisterCastShape(s, EShapeSubType::Empty, cast_empty);
62 }
63 }
64
65 JPH_NAMESPACE_END