Skip to content

Commit

Permalink
Improve EmptyShape, EmptyShapeSettings logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
amerkoleci committed Jan 27, 2025
1 parent 7dd3110 commit cc730ce
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 34 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ endif ()
FetchContent_Declare(
JoltPhysics
GIT_REPOSITORY "https://github.com/jrouwe/JoltPhysics"
GIT_TAG "94d88064a654412aa1980d7e1bf396ccba3e8857"
GIT_TAG "1ee535591341aa39e360f731041427a44d3de71c"
SOURCE_SUBDIR "Build"
)
FetchContent_MakeAvailable(JoltPhysics)
Expand Down
4 changes: 2 additions & 2 deletions include/joltc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@ JPH_CAPI float JPH_TaperedCapsuleShape_GetBottomRadius(const JPH_TaperedCapsuleS
JPH_CAPI float JPH_TaperedCapsuleShape_GetHalfHeight(const JPH_TaperedCapsuleShape* shape);

/* CompoundShape */
JPH_CAPI void JPH_CompoundShapeSettings_AddShape(JPH_CompoundShapeSettings* settings, const JPH_Vec3* position, const JPH_Quat* rotation, const JPH_ShapeSettings* shape, uint32_t userData);
JPH_CAPI void JPH_CompoundShapeSettings_AddShape(JPH_CompoundShapeSettings* settings, const JPH_Vec3* position, const JPH_Quat* rotation, const JPH_ShapeSettings* shapeSettings, uint32_t userData);
JPH_CAPI void JPH_CompoundShapeSettings_AddShape2(JPH_CompoundShapeSettings* settings, const JPH_Vec3* position, const JPH_Quat* rotation, const JPH_Shape* shape, uint32_t userData);
JPH_CAPI uint32_t JPH_CompoundShape_GetNumSubShapes(const JPH_CompoundShape* shape);
JPH_CAPI void JPH_CompoundShape_GetSubShape(const JPH_CompoundShape* shape, uint32_t index, const JPH_Shape** subShape, JPH_Vec3* positionCOM, JPH_Quat* rotation, uint32_t* userData);
Expand Down Expand Up @@ -1312,7 +1312,7 @@ JPH_CAPI JPH_EmptyShape* JPH_EmptyShapeSettings_CreateShape(const JPH_EmptyShape

/* JPH_BodyCreationSettings */
JPH_CAPI JPH_BodyCreationSettings* JPH_BodyCreationSettings_Create(void);
JPH_CAPI JPH_BodyCreationSettings* JPH_BodyCreationSettings_Create2(JPH_ShapeSettings* settings,
JPH_CAPI JPH_BodyCreationSettings* JPH_BodyCreationSettings_Create2(const JPH_ShapeSettings* settings,
const JPH_RVec3* position,
const JPH_Quat* rotation,
JPH_MotionType motionType,
Expand Down
74 changes: 43 additions & 31 deletions src/joltc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,18 @@ DEF_MAP_DECL(SoftBodyCreationSettings, JPH_SoftBodyCreationSettings)
DEF_MAP_DECL(Body, JPH_Body)
DEF_MAP_DECL(BodyInterface, JPH_BodyInterface)
DEF_MAP_DECL(BodyLockInterface, JPH_BodyLockInterface)
DEF_MAP_DECL(Shape, JPH_Shape)
DEF_MAP_DECL(MotionProperties, JPH_MotionProperties)
DEF_MAP_DECL(BroadPhaseQuery, JPH_BroadPhaseQuery)
DEF_MAP_DECL(NarrowPhaseQuery, JPH_NarrowPhaseQuery)
DEF_MAP_DECL(PhysicsMaterial, JPH_PhysicsMaterial)
DEF_MAP_DECL(Shape, JPH_Shape)
DEF_MAP_DECL(ShapeSettings, JPH_ShapeSettings)
DEF_MAP_DECL(EmptyShape, JPH_EmptyShape)
DEF_MAP_DECL(EmptyShapeSettings, JPH_EmptyShapeSettings)
DEF_MAP_DECL(CompoundShape, JPH_CompoundShape)
DEF_MAP_DECL(CompoundShapeSettings, JPH_CompoundShapeSettings)
DEF_MAP_DECL(MutableCompoundShape, JPH_MutableCompoundShape)
DEF_MAP_DECL(MutableCompoundShapeSettings, JPH_MutableCompoundShapeSettings)
DEF_MAP_DECL(MeshShape, JPH_MeshShape)
DEF_MAP_DECL(MeshShapeSettings, JPH_MeshShapeSettings)
DEF_MAP_DECL(Constraint, JPH_Constraint)
Expand Down Expand Up @@ -2381,18 +2388,22 @@ float JPH_TaperedCapsuleShape_GetHalfHeight(const JPH_TaperedCapsuleShape* shape
}

/* CompoundShape */
void JPH_CompoundShapeSettings_AddShape(JPH_CompoundShapeSettings* settings, const JPH_Vec3* position, const JPH_Quat* rotation, const JPH_ShapeSettings* shape, uint32_t userData)
void JPH_CompoundShapeSettings_AddShape(JPH_CompoundShapeSettings* settings, const JPH_Vec3* position, const JPH_Quat* rotation, const JPH_ShapeSettings* shapeSettings, uint32_t userData)
{
auto joltShapeSettings = reinterpret_cast<const JPH::ShapeSettings*>(shape);
auto joltSettings = reinterpret_cast<JPH::CompoundShapeSettings*>(settings);
joltSettings->AddShape(ToJolt(position), ToJolt(rotation), joltShapeSettings, userData);
AsCompoundShapeSettings(settings)->AddShape(
ToJolt(position),
ToJolt(rotation),
AsShapeSettings(shapeSettings),
userData);
}

void JPH_CompoundShapeSettings_AddShape2(JPH_CompoundShapeSettings* settings, const JPH_Vec3* position, const JPH_Quat* rotation, const JPH_Shape* shape, uint32_t userData)
{
auto joltShape = reinterpret_cast<const JPH::Shape*>(shape);
auto joltSettings = reinterpret_cast<JPH::CompoundShapeSettings*>(settings);
joltSettings->AddShape(ToJolt(position), ToJolt(rotation), joltShape, userData);
AsCompoundShapeSettings(settings)->AddShape(
ToJolt(position),
ToJolt(rotation),
AsShape(shape),
userData);
}

uint32_t JPH_CompoundShape_GetNumSubShapes(const JPH_CompoundShape* shape)
Expand Down Expand Up @@ -2503,25 +2514,23 @@ const JPH_Shape* JPH_DecoratedShape_GetInnerShape(const JPH_DecoratedShape* shap
/* RotatedTranslatedShape */
JPH_RotatedTranslatedShapeSettings* JPH_RotatedTranslatedShapeSettings_Create(const JPH_Vec3* position, const JPH_Quat* rotation, const JPH_ShapeSettings* shapeSettings)
{
auto joltSettings = reinterpret_cast<const JPH::ShapeSettings*>(shapeSettings);

auto settings = new JPH::RotatedTranslatedShapeSettings(
ToJolt(position),
rotation != nullptr ? ToJolt(rotation) : JPH::Quat::sIdentity(),
joltSettings);
shapeSettings != nullptr ? AsShapeSettings(shapeSettings) : new EmptyShapeSettings()
);
settings->AddRef();

return reinterpret_cast<JPH_RotatedTranslatedShapeSettings*>(settings);
}

JPH_RotatedTranslatedShapeSettings* JPH_RotatedTranslatedShapeSettings_Create2(const JPH_Vec3* position, const JPH_Quat* rotation, const JPH_Shape* shape)
{
auto joltShape = reinterpret_cast<const JPH::Shape*>(shape);

auto settings = new JPH::RotatedTranslatedShapeSettings(
ToJolt(position),
rotation != nullptr ? ToJolt(rotation) : JPH::Quat::sIdentity(),
joltShape);
AsShape(shape)
);
settings->AddRef();

return reinterpret_cast<JPH_RotatedTranslatedShapeSettings*>(settings);
Expand Down Expand Up @@ -2569,19 +2578,21 @@ void JPH_RotatedTranslatedShape_GetRotation(const JPH_RotatedTranslatedShape* sh

JPH_ScaledShapeSettings* JPH_ScaledShapeSettings_Create(const JPH_ShapeSettings* shapeSettings, const JPH_Vec3* scale)
{
auto joltSettings = reinterpret_cast<const JPH::ShapeSettings*>(shapeSettings);

auto settings = new JPH::ScaledShapeSettings(joltSettings, ToJolt(scale));
auto settings = new JPH::ScaledShapeSettings(
AsShapeSettings(shapeSettings),
ToJolt(scale)
);
settings->AddRef();

return reinterpret_cast<JPH_ScaledShapeSettings*>(settings);
}

JPH_ScaledShapeSettings* JPH_ScaledShapeSettings_Create2(const JPH_Shape* shape, const JPH_Vec3* scale)
{
auto joltShape = reinterpret_cast<const JPH::Shape*>(shape);

auto settings = new JPH::ScaledShapeSettings(joltShape, ToJolt(scale));
auto settings = new JPH::ScaledShapeSettings(
AsShape(shape),
ToJolt(scale)
);
settings->AddRef();

return reinterpret_cast<JPH_ScaledShapeSettings*>(settings);
Expand Down Expand Up @@ -2671,43 +2682,45 @@ JPH_EmptyShapeSettings* JPH_EmptyShapeSettings_Create(const JPH_Vec3* centerOfMa
auto settings = new EmptyShapeSettings(ToJolt(centerOfMass));
settings->AddRef();

return reinterpret_cast<JPH_EmptyShapeSettings*>(settings);
return ToEmptyShapeSettings(settings);
}

JPH_EmptyShape* JPH_EmptyShapeSettings_CreateShape(const JPH_EmptyShapeSettings* settings)
{
const EmptyShapeSettings* joltSettings = reinterpret_cast<const EmptyShapeSettings*>(settings);
auto shape_res = joltSettings->Create();
auto shape_res = AsEmptyShapeSettings(settings)->Create();
if (!shape_res.IsValid())
{
return nullptr;
}

auto shape = shape_res.Get().GetPtr();
shape->AddRef();

return reinterpret_cast<JPH_EmptyShape*>(shape);
return ToEmptyShape(static_cast<EmptyShape*>(shape));
}

/* JPH_BodyCreationSettings */
JPH_BodyCreationSettings* JPH_BodyCreationSettings_Create(void)
{
auto bodyCreationSettings = new JPH::BodyCreationSettings();
return reinterpret_cast<JPH_BodyCreationSettings*>(bodyCreationSettings);
return ToBodyCreationSettings(bodyCreationSettings);
}

JPH_BodyCreationSettings* JPH_BodyCreationSettings_Create2(
JPH_ShapeSettings* shapeSettings,
const JPH_ShapeSettings* shapeSettings,
const JPH_RVec3* position,
const JPH_Quat* rotation,
JPH_MotionType motionType,
JPH_ObjectLayer objectLayer)
{
JPH::ShapeSettings* joltShapeSettings = reinterpret_cast<JPH::ShapeSettings*>(shapeSettings);
auto bodyCreationSettings = new JPH::BodyCreationSettings(
joltShapeSettings,
AsShapeSettings(shapeSettings),
ToJolt(position),
rotation != nullptr ? ToJolt(rotation) : JPH::Quat::sIdentity(),
(JPH::EMotionType)motionType,
objectLayer
);
return reinterpret_cast<JPH_BodyCreationSettings*>(bodyCreationSettings);
return ToBodyCreationSettings(bodyCreationSettings);
}

JPH_BodyCreationSettings* JPH_BodyCreationSettings_Create3(
Expand All @@ -2717,9 +2730,8 @@ JPH_BodyCreationSettings* JPH_BodyCreationSettings_Create3(
JPH_MotionType motionType,
JPH_ObjectLayer objectLayer)
{
const JPH::Shape* joltShape = AsShape(shape);
auto bodyCreationSettings = new JPH::BodyCreationSettings(
joltShape,
AsShape(shape),
ToJolt(position),
rotation != nullptr ? ToJolt(rotation) : JPH::Quat::sIdentity(),
(JPH::EMotionType)motionType,
Expand Down

0 comments on commit cc730ce

Please sign in to comment.