Skip to content

Commit

Permalink
Continue implementing CastShape API, now converting settings
Browse files Browse the repository at this point in the history
  • Loading branch information
LPGhatguy committed Oct 23, 2024
1 parent 21aa3c4 commit ae76c40
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 54 deletions.
8 changes: 4 additions & 4 deletions JoltC/Enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,12 @@ ENSURE_ENUM_EQ(JPC_VALIDATE_RESULT_REJECT_ALL_CONTACTS,
JPH::ValidateResult::RejectAllContactsForThisBodyPair);

typedef enum JPC_BackFaceMode: uint8_t {
JPC_BACK_FACE_IGNORE,
JPC_BACK_FACE_COLLIDE,
JPC_BACK_FACE_MODE_IGNORE,
JPC_BACK_FACE_MODE_COLLIDE,
} JPC_BackFaceMode;

ENSURE_ENUM_EQ(JPC_BACK_FACE_IGNORE, JPH::EBackFaceMode::IgnoreBackFaces)
ENSURE_ENUM_EQ(JPC_BACK_FACE_COLLIDE, JPH::EBackFaceMode::CollideWithBackFaces)
ENSURE_ENUM_EQ(JPC_BACK_FACE_MODE_IGNORE, JPH::EBackFaceMode::IgnoreBackFaces)
ENSURE_ENUM_EQ(JPC_BACK_FACE_MODE_COLLIDE, JPH::EBackFaceMode::CollideWithBackFaces)

typedef enum JPC_BodyType: uint8_t {
JPC_BODY_TYPE_RIGID_BODY = 0,
Expand Down
7 changes: 3 additions & 4 deletions JoltC/Functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -824,8 +824,8 @@ typedef struct JPC_ShapeCastSettings {
JPC_Vec3 ActiveEdgeMovementDirection;

// JPH::ShapeCastSettings
// EBackFaceMode BackFaceModeTriangles;
// EBackFaceMode BackFaceModeConvex;
JPC_BackFaceMode BackFaceModeTriangles;
JPC_BackFaceMode BackFaceModeConvex;
bool UseShrunkenShapeAndConvexRadius;
bool ReturnDeepestPoint;
} JPC_ShapeCastSettings;
Expand All @@ -843,8 +843,7 @@ typedef struct JPC_NarrowPhaseQuery_CastShapeArgs {
// const JPC_ShapeFilter *ShapeFilter;
} JPC_NarrowPhaseQuery_CastShapeArgs;

JPC_API void JPC_NarrowPhaseQuery_CastShape(const JPC_NarrowPhaseQuery* self, JPC_NarrowPhaseQuery_CastShapeArgs* args);
JPC_API bool JPC_NarrowPhaseQuery_CastShapeEasiest(const JPC_NarrowPhaseQuery* self, JPC_NarrowPhaseQuery_CastShapeArgs* args);
JPC_API bool JPC_NarrowPhaseQuery_CastShape(const JPC_NarrowPhaseQuery* self, JPC_NarrowPhaseQuery_CastShapeArgs* args);

////////////////////////////////////////////////////////////////////////////////
// PhysicsSystem
Expand Down
70 changes: 24 additions & 46 deletions JoltC/JoltC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,24 @@ static JPC_ShapeCastResult to_jpc(JPH::ShapeCastResult in) {
return out;
}

static JPH::ShapeCastSettings to_jph(JPC_ShapeCastSettings in) {
JPH::ShapeCastSettings out{};
// JPH::CollideSettingsBase
// EActiveEdgeMode ActiveEdgeMode;
// ECollectFacesMode CollectFacesMode;
out.mCollisionTolerance = in.CollisionTolerance;
out.mPenetrationTolerance = in.PenetrationTolerance;
out.mActiveEdgeMovementDirection = to_jph(in.ActiveEdgeMovementDirection);

// JPH::ShapeCastSettings
out.mBackFaceModeTriangles = static_cast<JPH::EBackFaceMode>(in.BackFaceModeTriangles);
out.mBackFaceModeConvex = static_cast<JPH::EBackFaceMode>(in.BackFaceModeConvex);
out.mUseShrunkenShapeAndConvexRadius = in.UseShrunkenShapeAndConvexRadius;
out.mReturnDeepestPoint = in.ReturnDeepestPoint;

return out;
}

JPC_API void JPC_RegisterDefaultAllocator() {
JPH::RegisterDefaultAllocator();
}
Expand Down Expand Up @@ -1573,54 +1591,14 @@ JPC_API void JPC_ShapeCastSettings_default(JPC_ShapeCastSettings* object) {
object->ActiveEdgeMovementDirection = JPC_Vec3{0};

// JPH::ShapeCastSettings
// EBackFaceMode BackFaceModeTriangles;
// EBackFaceMode BackFaceModeConvex;
object->UseShrunkenShapeAndConvexRadius;
object->ReturnDeepestPoint;
}

JPC_API void JPC_NarrowPhaseQuery_CastShape(const JPC_NarrowPhaseQuery* self, JPC_NarrowPhaseQuery_CastShapeArgs* args) {
JPH::ShapeCastSettings settings{};

JPH::ClosestHitCollisionCollector<JPH::CastShapeCollector> collector{};

JPH::BroadPhaseLayerFilter defaultBplFilter{};
const JPH::BroadPhaseLayerFilter* bplFilter = &defaultBplFilter;
if (args->BroadPhaseLayerFilter != nullptr) {
bplFilter = to_jph(args->BroadPhaseLayerFilter);
}

JPH::ObjectLayerFilter defaultOlFilter{};
const JPH::ObjectLayerFilter* olFilter = &defaultOlFilter;
if (args->ObjectLayerFilter != nullptr) {
olFilter = to_jph(args->ObjectLayerFilter);
}

JPH::BodyFilter defaultBodyFilter{};
const JPH::BodyFilter* bodyFilter = &defaultBodyFilter;
if (args->BodyFilter != nullptr) {
bodyFilter = to_jph(args->BodyFilter);
}

JPH::ShapeFilter defaultShapeFilter{};
const JPH::ShapeFilter* shapeFilter = &defaultShapeFilter;
// if (args->ShapeFilter != nullptr) {
// shapeFilter = to_jph(args->ShapeFilter);
// }

to_jph(self)->CastShape(
to_jph(args->ShapeCast),
settings,
to_jph(args->BaseOffset),
collector,
*bplFilter,
*olFilter,
*bodyFilter,
*shapeFilter);
object->BackFaceModeTriangles = JPC_BACK_FACE_MODE_IGNORE;
object->BackFaceModeConvex = JPC_BACK_FACE_MODE_IGNORE;
object->UseShrunkenShapeAndConvexRadius = false;
object->ReturnDeepestPoint = false;
}

JPC_API bool JPC_NarrowPhaseQuery_CastShapeEasiest(const JPC_NarrowPhaseQuery* self, JPC_NarrowPhaseQuery_CastShapeArgs* args) {
JPH::ShapeCastSettings settings{};
JPC_API bool JPC_NarrowPhaseQuery_CastShape(const JPC_NarrowPhaseQuery* self, JPC_NarrowPhaseQuery_CastShapeArgs* args) {
JPH::ShapeCastSettings settings = to_jph(args->Settings);

JPH::ClosestHitCollisionCollector<JPH::CastShapeCollector> collector{};

Expand Down

0 comments on commit ae76c40

Please sign in to comment.