Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/Collision/Shape/EmptyShape.cpp
9913 views
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)1// SPDX-FileCopyrightText: 2024 Jorrit Rouwe2// SPDX-License-Identifier: MIT34#include <Jolt/Jolt.h>56#include <Jolt/Physics/Collision/Shape/EmptyShape.h>7#include <Jolt/Physics/Collision/CollisionDispatch.h>8#include <Jolt/ObjectStream/TypeDeclarations.h>9#ifdef JPH_DEBUG_RENDERER10#include <Jolt/Renderer/DebugRenderer.h>11#endif // JPH_DEBUG_RENDERER1213JPH_NAMESPACE_BEGIN1415JPH_IMPLEMENT_SERIALIZABLE_VIRTUAL(EmptyShapeSettings)16{17JPH_ADD_BASE_CLASS(EmptyShapeSettings, ShapeSettings)1819JPH_ADD_ATTRIBUTE(EmptyShapeSettings, mCenterOfMass)20}2122ShapeSettings::ShapeResult EmptyShapeSettings::Create() const23{24if (mCachedResult.IsEmpty())25new EmptyShape(*this, mCachedResult);2627return mCachedResult;28}2930MassProperties EmptyShape::GetMassProperties() const31{32MassProperties mass_properties;33mass_properties.mMass = 1.0f;34mass_properties.mInertia = Mat44::sIdentity();35return mass_properties;36}3738#ifdef JPH_DEBUG_RENDERER39void EmptyShape::Draw(DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale, ColorArg inColor, [[maybe_unused]] bool inUseMaterialColors, [[maybe_unused]] bool inDrawWireframe) const40{41inRenderer->DrawMarker(inCenterOfMassTransform.GetTranslation(), inColor, abs(inScale.GetX()) * 0.1f);42}43#endif // JPH_DEBUG_RENDERER4445void EmptyShape::sRegister()46{47ShapeFunctions &f = ShapeFunctions::sGet(EShapeSubType::Empty);48f.mConstruct = []() -> Shape * { return new EmptyShape; };49f.mColor = Color::sBlack;5051auto 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 */ };52auto 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 */ };5354for (const EShapeSubType s : sAllSubShapeTypes)55{56CollisionDispatch::sRegisterCollideShape(EShapeSubType::Empty, s, collide_empty);57CollisionDispatch::sRegisterCollideShape(s, EShapeSubType::Empty, collide_empty);5859CollisionDispatch::sRegisterCastShape(EShapeSubType::Empty, s, cast_empty);60CollisionDispatch::sRegisterCastShape(s, EShapeSubType::Empty, cast_empty);61}62}6364JPH_NAMESPACE_END656667