Skip to content

Commit

Permalink
Stub shape casting API
Browse files Browse the repository at this point in the history
  • Loading branch information
LPGhatguy committed Oct 17, 2024
1 parent f69f6be commit 8fd931d
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
36 changes: 36 additions & 0 deletions JoltC/Functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,42 @@ typedef struct JPC_NarrowPhaseQuery_CastRayArgs {

JPC_API bool JPC_NarrowPhaseQuery_CastRay(const JPC_NarrowPhaseQuery* self, JPC_NarrowPhaseQuery_CastRayArgs* args);

typedef struct JPC_RShapeCast {
const JPC_Shape *Shape;
JPC_Vec3 Scale;
JPC_RMat44 CenterOfMassStart;
JPC_Vec3 Direction;
// const JPC_AABox ShapeWorldBounds;
} JPC_RShapeCast;

typedef struct JPC_ShapeCastSettings {
// JPH::CollideSettingsBase
// EActiveEdgeMode ActiveEdgeMode;
// ECollectFacesMode CollectFacesMode;
float CollisionTolerance;
float PenetrationTolerance;
JPC_Vec3 ActiveEdgeMovementDirection;

// JPH::ShapeCastSettings
// EBackFaceMode BackFaceModeTriangles;
// EBackFaceMode BackFaceModeConvex;
bool UseShrunkenShapeAndConvexRadius;
bool ReturnDeepestPoint;
} JPC_ShapeCastSettings;

typedef struct JPC_NarrowPhaseQuery_CastShapeArgs {
JPC_RShapeCast ShapeCast;
JPC_ShapeCastSettings Settings;
JPC_RVec3 BaseOffset;
// JPC_CastShapeCollector *Collector;
const JPC_BroadPhaseLayerFilter *BroadPhaseLayerFilter;
const JPC_ObjectLayerFilter *ObjectLayerFilter;
const JPC_BodyFilter *BodyFilter;
// const JPC_ShapeFilter *ShapeFilter;
} JPC_NarrowPhaseQuery_CastShapeArgs;

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

////////////////////////////////////////////////////////////////////////////////
// PhysicsSystem

Expand Down
50 changes: 50 additions & 0 deletions JoltC/JoltC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <Jolt/Physics/Body/BodyActivationListener.h>
#include <Jolt/Physics/Body/BodyCreationSettings.h>
#include <Jolt/Physics/Collision/CastResult.h>
#include <Jolt/Physics/Collision/CollisionCollectorImpl.h>
#include <Jolt/Physics/Collision/RayCast.h>
#include <Jolt/Physics/Collision/Shape/BoxShape.h>
#include <Jolt/Physics/Collision/Shape/CapsuleShape.h>
Expand All @@ -16,6 +17,7 @@
#include <Jolt/Physics/Collision/Shape/SphereShape.h>
#include <Jolt/Physics/Collision/Shape/StaticCompoundShape.h>
#include <Jolt/Physics/Collision/Shape/TriangleShape.h>
#include <Jolt/Physics/Collision/ShapeCast.h>
#include <Jolt/Physics/PhysicsSettings.h>
#include <Jolt/Physics/PhysicsSystem.h>
#include <Jolt/RegisterTypes.h>
Expand Down Expand Up @@ -167,6 +169,14 @@ static JPH::RRayCast to_jph(JPC_RRayCast in) {
return JPH::RRayCast(to_jph(in.Origin), to_jph(in.Direction));
}

static JPH::RShapeCast to_jph(JPC_RShapeCast in) {
return JPH::RShapeCast(
to_jph(in.Shape),
to_jph(in.Scale),
to_jph(in.CenterOfMassStart),

Check failure on line 176 in JoltC/JoltC.cpp

View workflow job for this annotation

GitHub Actions / Tests - ubuntu-latest Debug -DDOUBLE_PRECISION=ON

no matching function for call to 'to_jph'
to_jph(in.Direction));
}

static JPC_SubShapeID to_jpc(JPH::SubShapeID in) {
return in.GetValue();
}
Expand Down Expand Up @@ -1457,6 +1467,46 @@ JPC_API bool JPC_NarrowPhaseQuery_CastRay(const JPC_NarrowPhaseQuery* self, JPC_
return hit;
}

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);
}

////////////////////////////////////////////////////////////////////////////////
// PhysicsSystem

Expand Down

0 comments on commit 8fd931d

Please sign in to comment.