Browse Source

Add, Remove, and Destroy bodies

Lucien Greathouse 1 year ago
parent
commit
a19f4bc6cd
3 changed files with 42 additions and 4 deletions
  1. 8 2
      HelloWorld/main.cpp
  2. 8 2
      JoltC/Functions.h
  3. 26 0
      JoltC/JoltC.cpp

+ 8 - 2
HelloWorld/main.cpp

@@ -135,10 +135,13 @@ int main() {
 	floor_settings.Shape = shape;
 	floor_settings.Shape = shape;
 
 
 	JPC_Body* floor = JPC_BodyInterface_CreateBody(body_interface, &floor_settings);
 	JPC_Body* floor = JPC_BodyInterface_CreateBody(body_interface, &floor_settings);
+	JPC_BodyInterface_AddBody(body_interface, JPC_Body_GetID(floor), JPC_ACTIVATION_DONT_ACTIVATE);
 
 
-	// body_interface.AddBody(floor->GetID(), EActivation::DontActivate);
+	// BodyCreationSettings sphere_settings(new SphereShape(0.5f), RVec3(0.0_r, 2.0_r, 0.0_r), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING);
+	// BodyID sphere_id = body_interface.CreateAndAddBody(sphere_settings, EActivation::Activate);
+
+	// body_interface.SetLinearVelocity(sphere_id, Vec3(0.0f, -5.0f, 0.0f));
 
 
-	// TODO: creating bodies
 	// TODO: PhysicsSystem::OptimizeBroadPhase
 	// TODO: PhysicsSystem::OptimizeBroadPhase
 
 
 	const float cDeltaTime = 1.0f / 60.0f;
 	const float cDeltaTime = 1.0f / 60.0f;
@@ -151,6 +154,9 @@ int main() {
 
 
 	// TODO: RemoveBody and DestroyBody
 	// TODO: RemoveBody and DestroyBody
 
 
+	JPC_BodyInterface_RemoveBody(body_interface, JPC_Body_GetID(floor));
+	JPC_BodyInterface_DestroyBody(body_interface, JPC_Body_GetID(floor));
+
 	JPC_PhysicsSystem_delete(physics_system);
 	JPC_PhysicsSystem_delete(physics_system);
 	JPC_BroadPhaseLayerInterface_delete(broad_phase_layer_interface);
 	JPC_BroadPhaseLayerInterface_delete(broad_phase_layer_interface);
 	JPC_ObjectVsBroadPhaseLayerFilter_delete(object_vs_broad_phase_layer_filter);
 	JPC_ObjectVsBroadPhaseLayerFilter_delete(object_vs_broad_phase_layer_filter);

+ 8 - 2
JoltC/Functions.h

@@ -223,16 +223,22 @@ typedef struct JPC_BodyCreationSettings JPC_BodyCreationSettings;
 
 
 JPC_API JPC_BodyCreationSettings* JPC_BodyCreationSettings_new();
 JPC_API JPC_BodyCreationSettings* JPC_BodyCreationSettings_new();
 
 
+////////////////////////////////////////////////////////////////////////////////
+// Body
+
+typedef struct JPC_Body JPC_Body;
+
+JPC_API JPC_BodyID JPC_Body_GetID(JPC_Body* self);
+
 ////////////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////////
 // BodyInterface
 // BodyInterface
 
 
 typedef struct JPC_BodyInterface JPC_BodyInterface;
 typedef struct JPC_BodyInterface JPC_BodyInterface;
 
 
-typedef struct JPC_Body JPC_Body;
-
 JPC_API JPC_Body* JPC_BodyInterface_CreateBody(JPC_BodyInterface* self, JPC_BodyCreationSettings* inSettingsC);
 JPC_API JPC_Body* JPC_BodyInterface_CreateBody(JPC_BodyInterface* self, JPC_BodyCreationSettings* inSettingsC);
 JPC_API void JPC_BodyInterface_AddBody(JPC_BodyInterface* self, JPC_BodyID inBodyID, JPC_Activation inActivationMode);
 JPC_API void JPC_BodyInterface_AddBody(JPC_BodyInterface* self, JPC_BodyID inBodyID, JPC_Activation inActivationMode);
 JPC_API void JPC_BodyInterface_RemoveBody(JPC_BodyInterface* self, JPC_BodyID inBodyID);
 JPC_API void JPC_BodyInterface_RemoveBody(JPC_BodyInterface* self, JPC_BodyID inBodyID);
+JPC_API void JPC_BodyInterface_DestroyBody(JPC_BodyInterface* self, JPC_BodyID inBodyID);
 
 
 ////////////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////////
 // PhysicsSystem
 // PhysicsSystem

+ 26 - 0
JoltC/JoltC.cpp

@@ -36,6 +36,7 @@ constexpr auto to_integral(E e) -> typename std::underlying_type<E>::type
 
 
 ENUM_CONVERSION(JPC_MotionType, JPH::EMotionType)
 ENUM_CONVERSION(JPC_MotionType, JPH::EMotionType)
 ENUM_CONVERSION(JPC_AllowedDOFs, JPH::EAllowedDOFs)
 ENUM_CONVERSION(JPC_AllowedDOFs, JPH::EAllowedDOFs)
+ENUM_CONVERSION(JPC_Activation, JPH::EActivation)
 
 
 OPAQUE_WRAPPER(JPC_PhysicsSystem, JPH::PhysicsSystem)
 OPAQUE_WRAPPER(JPC_PhysicsSystem, JPH::PhysicsSystem)
 DESTRUCTOR(JPC_PhysicsSystem)
 DESTRUCTOR(JPC_PhysicsSystem)
@@ -83,6 +84,12 @@ static JPH::Quat to_jph(JPC_Quat in) {
 	return JPH::Quat(in.x, in.y, in.z, in.w);
 	return JPH::Quat(in.x, in.y, in.z, in.w);
 }
 }
 
 
+static JPC_BodyID to_jpc(JPH::BodyID in) {
+	return in.GetIndexAndSequenceNumber();
+}
+static JPH::BodyID to_jph(JPC_BodyID in) {
+	return JPH::BodyID(in);
+}
 
 
 JPC_API void JPC_RegisterDefaultAllocator() {
 JPC_API void JPC_RegisterDefaultAllocator() {
 	JPH::RegisterDefaultAllocator();
 	JPH::RegisterDefaultAllocator();
@@ -292,6 +299,13 @@ JPC_API void JPC_BodyCreationSettings_default(JPC_BodyCreationSettings* settings
 	settings->AllowedDOFs = JPC_ALLOWED_DOFS_ALL;
 	settings->AllowedDOFs = JPC_ALLOWED_DOFS_ALL;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////////////////
+// Body
+
+JPC_API JPC_BodyID JPC_Body_GetID(JPC_Body* self) {
+	return to_jpc(to_jph(self)->GetID());
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////////
 // BodyInterface
 // BodyInterface
 
 
@@ -314,6 +328,18 @@ JPC_API JPC_Body* JPC_BodyInterface_CreateBody(JPC_BodyInterface* self, JPC_Body
 	return to_jpc(body);
 	return to_jpc(body);
 }
 }
 
 
+JPC_API void JPC_BodyInterface_AddBody(JPC_BodyInterface* self, JPC_BodyID inBodyID, JPC_Activation inActivationMode) {
+	to_jph(self)->AddBody(to_jph(inBodyID), to_jph(inActivationMode));
+}
+
+JPC_API void JPC_BodyInterface_RemoveBody(JPC_BodyInterface* self, JPC_BodyID inBodyID) {
+	to_jph(self)->RemoveBody(to_jph(inBodyID));
+}
+
+JPC_API void JPC_BodyInterface_DestroyBody(JPC_BodyInterface* self, JPC_BodyID inBodyID) {
+	to_jph(self)->DestroyBody(to_jph(inBodyID));
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////////
 // PhysicsSystem
 // PhysicsSystem