EmptyShape.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2024 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #include <Jolt/Jolt.h>
  5. #include <Jolt/Physics/Collision/Shape/EmptyShape.h>
  6. #include <Jolt/Physics/Collision/CollisionDispatch.h>
  7. #include <Jolt/ObjectStream/TypeDeclarations.h>
  8. #ifdef JPH_DEBUG_RENDERER
  9. #include <Jolt/Renderer/DebugRenderer.h>
  10. #endif // JPH_DEBUG_RENDERER
  11. JPH_NAMESPACE_BEGIN
  12. JPH_IMPLEMENT_SERIALIZABLE_VIRTUAL(EmptyShapeSettings)
  13. {
  14. JPH_ADD_BASE_CLASS(EmptyShapeSettings, ShapeSettings)
  15. JPH_ADD_ATTRIBUTE(EmptyShapeSettings, mCenterOfMass)
  16. }
  17. ShapeSettings::ShapeResult EmptyShapeSettings::Create() const
  18. {
  19. if (mCachedResult.IsEmpty())
  20. new EmptyShape(*this, mCachedResult);
  21. return mCachedResult;
  22. }
  23. MassProperties EmptyShape::GetMassProperties() const
  24. {
  25. MassProperties mass_properties;
  26. mass_properties.mMass = 1.0f;
  27. mass_properties.mInertia = Mat44::sIdentity();
  28. return mass_properties;
  29. }
  30. #ifdef JPH_DEBUG_RENDERER
  31. void EmptyShape::Draw(DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale, ColorArg inColor, [[maybe_unused]] bool inUseMaterialColors, [[maybe_unused]] bool inDrawWireframe) const
  32. {
  33. inRenderer->DrawMarker(inCenterOfMassTransform.GetTranslation(), inColor, abs(inScale.GetX()) * 0.1f);
  34. }
  35. #endif // JPH_DEBUG_RENDERER
  36. void EmptyShape::sRegister()
  37. {
  38. ShapeFunctions &f = ShapeFunctions::sGet(EShapeSubType::Empty);
  39. f.mConstruct = []() -> Shape * { return new EmptyShape; };
  40. f.mColor = Color::sBlack;
  41. 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 */ };
  42. 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 */ };
  43. for (const EShapeSubType s : sAllSubShapeTypes)
  44. {
  45. CollisionDispatch::sRegisterCollideShape(EShapeSubType::Empty, s, collide_empty);
  46. CollisionDispatch::sRegisterCollideShape(s, EShapeSubType::Empty, collide_empty);
  47. CollisionDispatch::sRegisterCastShape(EShapeSubType::Empty, s, cast_empty);
  48. CollisionDispatch::sRegisterCastShape(s, EShapeSubType::Empty, cast_empty);
  49. }
  50. }
  51. JPH_NAMESPACE_END