Skip to content

Commit

Permalink
Foundational work for CastShapeCollector
Browse files Browse the repository at this point in the history
  • Loading branch information
LPGhatguy committed Oct 17, 2024
1 parent 4c6293a commit 65eada9
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
32 changes: 32 additions & 0 deletions JoltC/Functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,23 @@ typedef struct JPC_RayCastResult {
JPC_SubShapeID SubShapeID2;
} JPC_RayCastResult;

typedef struct JPC_ShapeCastResult {
// From CollideShapeResult
JPC_Vec3 ContactPointOn1;
JPC_Vec3 ContactPointOn2;
JPC_Vec3 PenetrationAxis;
float PenetrationDepth;
// SubShapeID SubShapeID1;
// SubShapeID SubShapeID2;
JPC_BodyID BodyID2;
// Face Shape1Face;
// Face Shape2Face;

// From ShapeCastResult
float Fraction;
bool IsBackFaceHit;
} JPC_ShapeCastResult;

typedef struct JPC_Body JPC_Body;

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -293,6 +310,21 @@ JPC_API JPC_ObjectLayerPairFilter* JPC_ObjectLayerPairFilter_new(

JPC_API void JPC_ObjectLayerPairFilter_delete(JPC_ObjectLayerPairFilter* object);

////////////////////////////////////////////////////////////////////////////////
// CastShapeCollector

typedef struct JPC_CastShapeCollectorFns {
void (*AddHit)(const void *self, const JPC_ShapeCastResult *Result);
} JPC_CastShapeCollectorFns;

typedef struct JPC_CastShapeCollector JPC_CastShapeCollector;

JPC_API JPC_CastShapeCollector* JPC_CastShapeCollector_new(
const void *self,
JPC_CastShapeCollectorFns fns);

JPC_API void JPC_CastShapeCollector_delete(JPC_CastShapeCollector* object);

////////////////////////////////////////////////////////////////////////////////
// DrawSettings

Expand Down
49 changes: 49 additions & 0 deletions JoltC/JoltC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,26 @@ static JPC_RayCastResult to_jpc(JPH::RayCastResult in) {
return out;
}

static JPC_ShapeCastResult to_jpc(JPH::ShapeCastResult in) {
JPC_ShapeCastResult out{0};

Check warning on line 194 in JoltC/JoltC.cpp

View workflow job for this annotation

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

missing field 'y' initializer [-Wmissing-field-initializers]

Check warning on line 194 in JoltC/JoltC.cpp

View workflow job for this annotation

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

suggest braces around initialization of subobject [-Wmissing-braces]

Check warning on line 194 in JoltC/JoltC.cpp

View workflow job for this annotation

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

missing field 'ContactPointOn2' initializer [-Wmissing-field-initializers]

Check warning on line 194 in JoltC/JoltC.cpp

View workflow job for this annotation

GitHub Actions / Tests - ubuntu-latest Debug -DOBJECT_LAYER_BITS=32

missing field 'y' initializer [-Wmissing-field-initializers]

Check warning on line 194 in JoltC/JoltC.cpp

View workflow job for this annotation

GitHub Actions / Tests - ubuntu-latest Debug -DOBJECT_LAYER_BITS=32

suggest braces around initialization of subobject [-Wmissing-braces]

Check warning on line 194 in JoltC/JoltC.cpp

View workflow job for this annotation

GitHub Actions / Tests - ubuntu-latest Debug -DOBJECT_LAYER_BITS=32

missing field 'ContactPointOn2' initializer [-Wmissing-field-initializers]

Check warning on line 194 in JoltC/JoltC.cpp

View workflow job for this annotation

GitHub Actions / Tests - ubuntu-latest Debug

missing field 'y' initializer [-Wmissing-field-initializers]

Check warning on line 194 in JoltC/JoltC.cpp

View workflow job for this annotation

GitHub Actions / Tests - ubuntu-latest Debug

suggest braces around initialization of subobject [-Wmissing-braces]

Check warning on line 194 in JoltC/JoltC.cpp

View workflow job for this annotation

GitHub Actions / Tests - ubuntu-latest Debug

missing field 'ContactPointOn2' initializer [-Wmissing-field-initializers]
// CollideShapeResult
out.ContactPointOn1 = to_jpc(in.mContactPointOn1);
out.ContactPointOn2 = to_jpc(in.mContactPointOn2);
out.PenetrationAxis = to_jpc(in.mPenetrationAxis);
out.PenetrationDepth = in.mPenetrationDepth;
// SubShapeID SubShapeID1;
// SubShapeID SubShapeID2;
out.BodyID2 = to_jpc(in.mBodyID2);
// Face Shape1Face;
// Face Shape2Face;

// ShapeCastResult
out.Fraction = in.mFraction;
out.IsBackFaceHit = in.mIsBackFaceHit;

return out;
}

JPC_API void JPC_RegisterDefaultAllocator() {
JPH::RegisterDefaultAllocator();
}
Expand Down Expand Up @@ -422,6 +442,35 @@ JPC_API JPC_ObjectLayerPairFilter* JPC_ObjectLayerPairFilter_new(
return to_jpc(new JPC_ObjectLayerPairFilterBridge(self, fns));
}

////////////////////////////////////////////////////////////////////////////////
// JPC_CastShapeCollector

class JPC_CastShapeCollectorBridge final : public JPH::CastShapeCollector {
using ResultType = JPH::ShapeCastResult;

public:
explicit JPC_CastShapeCollectorBridge(const void *self, JPC_CastShapeCollectorFns fns) : self(self), fns(fns) {}

virtual void AddHit(const ResultType &inResult) {
JPC_ShapeCastResult result = to_jpc(inResult);
fns.AddHit(self, &result);
}

private:
const void* self;
JPC_CastShapeCollectorFns fns;
};

OPAQUE_WRAPPER(JPC_CastShapeCollector, JPC_CastShapeCollectorBridge)
DESTRUCTOR(JPC_CastShapeCollector)

JPC_API JPC_CastShapeCollector* JPC_CastShapeCollector_new(
const void *self,
JPC_CastShapeCollectorFns fns)
{
return to_jpc(new JPC_CastShapeCollectorBridge(self, fns));
}

////////////////////////////////////////////////////////////////////////////////
// BodyManager::DrawSettings

Expand Down

0 comments on commit 65eada9

Please sign in to comment.