ソースを参照

Bind EstimateCollisionResponse

Rasmus Brönnegård 3 ヶ月 前
コミット
5e56ea238e
3 ファイル変更62 行追加2 行削除
  1. 34 0
      JoltC/Functions.h
  2. 25 0
      JoltCImpl/JoltC.cpp
  3. 3 2
      JoltCImpl/Test.cpp

+ 34 - 0
JoltC/Functions.h

@@ -572,6 +572,40 @@ JPC_API JPC_ContactListener* JPC_ContactListener_new(
 
 JPC_API void JPC_ContactListener_delete(JPC_ContactListener* object);
 
+static const uint JPC_ContactPointsCapacity = 64;
+
+typedef struct JPC_Impulse {
+	float ContactImpulse;				///< Estimated contact impulses (kg m / s)
+	float FrictionImpulse1;				///< Estimated friction impulses in the direction of tangent 1 (kg m / s)
+	float FrictionImpulse2;				///< Estimated friction impulses in the direction of tangent 2 (kg m / s)
+} JPC_Impulse;
+
+typedef struct JPC_CollisionEstimationResult {
+	JPC_Vec3 LinearVelocity1;				///< The estimated linear velocity of body 1 after collision
+	JPC_Vec3 AngularVelocity1;				///< The estimated angular velocity of body 1 after collision
+	JPC_Vec3 LinearVelocity2;				///< The estimated linear velocity of body 2 after collision
+	JPC_Vec3 AngularVelocity2;				///< The estimated angular velocity of body 2 after collision
+
+	JPC_Vec3 Tangent1;						///< Normalized tangent of contact normal
+	JPC_Vec3 Tangent2;						///< Second normalized tangent of contact normal (forms a basis with mTangent1 and mWorldSpaceNormal)
+
+	uint NumImpulses;
+	JPC_Impulse Impulses[JPC_ContactPointsCapacity];
+} JPC_CollisionEstimationResult;
+
+ENSURE_SIZE_ALIGN(JPC_CollisionEstimationResult, JPH::CollisionEstimationResult)
+
+JPC_API void JPC_EstimateCollisionResponse(
+	const JPC_Body* inBody1,
+	const JPC_Body* inBody2,
+	const JPC_ContactManifold* inManifold,
+	JPC_CollisionEstimationResult* outResult,
+	float inCombinedFriction,
+	float inCombinedRestitution,
+	float inMinVelocityForRestitution,	///< = 1.0f
+	uint inNumIterations				///< = 10
+);
+
 ////////////////////////////////////////////////////////////////////////////////
 // CastShapeCollector
 

+ 25 - 0
JoltCImpl/JoltC.cpp

@@ -12,6 +12,7 @@
 #include <Jolt/Physics/Collision/CollideShape.h>
 #include <Jolt/Physics/Collision/CollisionCollectorImpl.h>
 #include <Jolt/Physics/Collision/ContactListener.h>
+#include <Jolt/Physics/Collision/EstimateCollisionResponse.h>
 #include <Jolt/Physics/Collision/RayCast.h>
 #include <Jolt/Physics/Collision/Shape/BoxShape.h>
 #include <Jolt/Physics/Collision/Shape/CapsuleShape.h>
@@ -748,6 +749,30 @@ JPC_API JPC_ContactListener* JPC_ContactListener_new(
 	return to_jpc(new JPC_ContactListenerBridge(self, fns));
 }
 
+JPC_API void JPC_EstimateCollisionResponse(
+	const JPC_Body* inBody1,
+	const JPC_Body* inBody2,
+	const JPC_ContactManifold* inManifold,
+	JPC_CollisionEstimationResult* outResult,
+	float inCombinedFriction,
+	float inCombinedRestitution,
+	float inMinVelocityForRestitution,	///< = 1.0f
+	uint inNumIterations				///< = 10
+) {
+	const auto* jphManifold = reinterpret_cast<const JPH::ContactManifold*>(inManifold);
+	auto* jphResult = reinterpret_cast<JPH::CollisionEstimationResult*>(outResult);
+
+	JPH::EstimateCollisionResponse(
+		*to_jph(inBody1),
+		*to_jph(inBody2),
+		*jphManifold,
+		*jphResult,
+		inCombinedFriction,
+		inCombinedRestitution,
+		inMinVelocityForRestitution,
+		inNumIterations);
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 // JPC_CastShapeCollector
 

+ 3 - 2
JoltCImpl/Test.cpp

@@ -19,6 +19,7 @@
 #include <Jolt/Physics/Collision/ActiveEdgeMode.h>
 #include <Jolt/Physics/Collision/CollectFacesMode.h>
 #include <Jolt/Physics/Collision/CollideShape.h>
+#include <Jolt/Physics/Collision/EstimateCollisionResponse.h>
 #include <Jolt/Physics/Collision/Shape/BoxShape.h>
 #include <Jolt/Physics/Collision/Shape/SphereShape.h>
 #include <Jolt/Physics/Collision/ShapeCast.h>
@@ -29,7 +30,7 @@
 #include <Jolt/RegisterTypes.h>
 
 template<typename E>
-constexpr auto to_integral(E e) -> typename std::underlying_type<E>::type 
+constexpr auto to_integral(E e) -> typename std::underlying_type<E>::type
 {
 	return static_cast<typename std::underlying_type<E>::type>(e);
 }
@@ -81,4 +82,4 @@ constexpr auto to_integral(E e) -> typename std::underlying_type<E>::type
 #include "JoltC/Enums.h"
 #undef const
 
-#include "JoltC/Functions.h"
+#include "JoltC/Functions.h"