Przeglądaj źródła

Sub shape ID, raycasting

Lucien Greathouse 1 rok temu
rodzic
commit
fa96126978
2 zmienionych plików z 52 dodań i 6 usunięć
  1. 19 0
      JoltC/Functions.h
  2. 33 6
      JoltC/JoltC.cpp

+ 19 - 0
JoltC/Functions.h

@@ -110,6 +110,9 @@ ENSURE_SIZE_ALIGN(JPC_RVec3, JPH::RVec3)
 typedef uint32_t JPC_BodyID;
 ENSURE_SIZE_ALIGN(JPC_BodyID, JPH::BodyID)
 
+typedef uint32_t JPC_SubShapeID;
+ENSURE_SIZE_ALIGN(JPC_SubShapeID, JPH::SubShapeID)
+
 typedef uint8_t JPC_BroadPhaseLayer;
 ENSURE_SIZE_ALIGN(JPC_BroadPhaseLayer, JPH::BroadPhaseLayer)
 
@@ -150,6 +153,12 @@ typedef struct JPC_RRayCast {
 	JPC_Vec3 Direction;
 } JPC_RRayCast;
 
+typedef struct JPC_RayCastResult {
+	JPC_BodyID BodyID;
+	float Fraction;
+	JPC_SubShapeID SubShapeID2;
+} JPC_RayCastResult;
+
 ////////////////////////////////////////////////////////////////////////////////
 // VertexList == Array<Float3> == std::vector<Float3>
 
@@ -717,6 +726,16 @@ JPC_API void JPC_BodyInterface_InvalidateContactCache(JPC_BodyInterface *self, J
 
 typedef struct JPC_NarrowPhaseQuery JPC_NarrowPhaseQuery;
 
+typedef struct JPC_NarrowPhaseQuery_CastRayArgs {
+	JPC_RRayCast Ray;
+	JPC_RayCastResult Result;
+	// BroadPhaseLayerFilter
+	// ObjectLayerFilter
+	// BodyFilter
+} JPC_NarrowPhaseQuery_CastRayArgs;
+
+JPC_API bool JPC_NarrowPhaseQuery_CastRay(JPC_NarrowPhaseQuery* self, JPC_NarrowPhaseQuery_CastRayArgs* args);
+
 ////////////////////////////////////////////////////////////////////////////////
 // PhysicsSystem
 

+ 33 - 6
JoltC/JoltC.cpp

@@ -5,6 +5,7 @@
 #include <Jolt/Core/TempAllocator.h>
 #include <Jolt/Physics/Body/BodyActivationListener.h>
 #include <Jolt/Physics/Body/BodyCreationSettings.h>
+#include <Jolt/Physics/Collision/CastResult.h>
 #include <Jolt/Physics/Collision/RayCast.h>
 #include <Jolt/Physics/Collision/Shape/BoxShape.h>
 #include <Jolt/Physics/Collision/Shape/CapsuleShape.h>
@@ -166,12 +167,18 @@ static JPH::RRayCast to_jph(JPC_RRayCast in) {
 	return JPH::RRayCast(to_jph(in.Origin), to_jph(in.Direction));
 }
 
-// static JPC_BodyID to_jpc(JPH::BodyID in) {
-// 	return in.GetIndexAndSequenceNumber();
-// }
-// static JPH::BodyID to_jph(JPC_BodyID in) {
-// 	return JPH::BodyID(in);
-// }
+static JPC_SubShapeID to_jpc(JPH::SubShapeID in) {
+	return in.GetValue();
+}
+
+static JPC_RayCastResult to_jpc(JPH::RayCastResult in) {
+	JPC_RayCastResult out{0};
+	out.BodyID = to_jpc(in.mBodyID);
+	out.Fraction = in.mFraction;
+	out.SubShapeID2 = to_jpc(in.mSubShapeID2);
+
+	return out;
+}
 
 JPC_API void JPC_RegisterDefaultAllocator() {
 	JPH::RegisterDefaultAllocator();
@@ -1322,6 +1329,26 @@ JPC_API void JPC_BodyInterface_InvalidateContactCache(JPC_BodyInterface *self, J
 	return to_jph(self)->InvalidateContactCache(to_jph(inBodyID));
 }
 
+////////////////////////////////////////////////////////////////////////////////
+// NarrowPhaseQuery
+
+JPC_API bool JPC_NarrowPhaseQuery_CastRay(JPC_NarrowPhaseQuery* self, JPC_NarrowPhaseQuery_CastRayArgs* args) {
+	JPH::RayCastResult result;
+
+	bool hit = to_jph(self)->CastRay(
+		to_jph(args->Ray),
+		result
+		// BroadPhaseLayerFilter
+		// ObjectLayerFilter
+		// BodyFilter
+	);
+
+	if (hit) {
+		args->Result = to_jpc(result);
+	}
+
+	return hit;
+}
 
 ////////////////////////////////////////////////////////////////////////////////
 // PhysicsSystem