Browse Source

SetLinearVelocity / IsActive on BodyInterface

Lucien Greathouse 1 year ago
parent
commit
faa490aa26
3 changed files with 16 additions and 6 deletions
  1. 6 6
      HelloWorld/main.cpp
  2. 2 0
      JoltC/Functions.h
  3. 8 0
      JoltC/JoltC.cpp

+ 6 - 6
HelloWorld/main.cpp

@@ -160,9 +160,7 @@ int main() {
 	JPC_BodyID sphere_id = JPC_Body_GetID(sphere);
 	JPC_BodyID sphere_id = JPC_Body_GetID(sphere);
 	JPC_BodyInterface_AddBody(body_interface, sphere_id, JPC_ACTIVATION_ACTIVATE);
 	JPC_BodyInterface_AddBody(body_interface, sphere_id, JPC_ACTIVATION_ACTIVATE);
 
 
-	// BodyID sphere_id = body_interface.CreateAndAddBody(sphere_settings, EActivation::Activate);
-
-	// body_interface.SetLinearVelocity(sphere_id, Vec3(0.0f, -5.0f, 0.0f));
+	JPC_BodyInterface_SetLinearVelocity(body_interface, sphere_id, JPC_Vec3{0.0, -5.0, 0.0});
 
 
 	// TODO: PhysicsSystem::OptimizeBroadPhase
 	// TODO: PhysicsSystem::OptimizeBroadPhase
 
 
@@ -170,12 +168,14 @@ int main() {
 	const int cCollisionSteps = 1;
 	const int cCollisionSteps = 1;
 
 
 	// TODO: Update loop
 	// TODO: Update loop
-	for (int i = 0; i < 35; i++) {
+	int step = 0;
+	while (JPC_BodyInterface_IsActive(body_interface, sphere_id)) {
+		++step;
+
 		JPC_RVec3 position = JPC_BodyInterface_GetCenterOfMassPosition(body_interface, sphere_id);
 		JPC_RVec3 position = JPC_BodyInterface_GetCenterOfMassPosition(body_interface, sphere_id);
 		JPC_Vec3 velocity = JPC_BodyInterface_GetLinearVelocity(body_interface, sphere_id);
 		JPC_Vec3 velocity = JPC_BodyInterface_GetLinearVelocity(body_interface, sphere_id);
 
 
-		printf("Step %d: Position = (%f, %f, %f), Velocity = (%f, %f, %f)\n", i, position.x, position.y, position.z, velocity.x, velocity.y, velocity.z);
-		// cout << "Step " << step << ": Position = (" << position.GetX() << ", " << position.GetY() << ", " << position.GetZ() << "), Velocity = (" << velocity.GetX() << ", " << velocity.GetY() << ", " << velocity.GetZ() << ")" << endl;
+		printf("Step %d: Position = (%f, %f, %f), Velocity = (%f, %f, %f)\n", step, position.x, position.y, position.z, velocity.x, velocity.y, velocity.z);
 
 
 		JPC_PhysicsSystem_Update(physics_system, cDeltaTime, cCollisionSteps, temp_allocator, job_system);
 		JPC_PhysicsSystem_Update(physics_system, cDeltaTime, cCollisionSteps, temp_allocator, job_system);
 	}
 	}

+ 2 - 0
JoltC/Functions.h

@@ -287,8 +287,10 @@ JPC_API void JPC_BodyInterface_AddBody(JPC_BodyInterface* self, JPC_BodyID inBod
 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);
 JPC_API void JPC_BodyInterface_DestroyBody(JPC_BodyInterface* self, JPC_BodyID inBodyID);
 
 
+JPC_API bool JPC_BodyInterface_IsActive(JPC_BodyInterface* self, JPC_BodyID inBodyID);
 JPC_API JPC_RVec3 JPC_BodyInterface_GetCenterOfMassPosition(JPC_BodyInterface* self, JPC_BodyID inBodyID);
 JPC_API JPC_RVec3 JPC_BodyInterface_GetCenterOfMassPosition(JPC_BodyInterface* self, JPC_BodyID inBodyID);
 JPC_API JPC_Vec3 JPC_BodyInterface_GetLinearVelocity(JPC_BodyInterface* self, JPC_BodyID inBodyID);
 JPC_API JPC_Vec3 JPC_BodyInterface_GetLinearVelocity(JPC_BodyInterface* self, JPC_BodyID inBodyID);
+JPC_API void JPC_BodyInterface_SetLinearVelocity(JPC_BodyInterface* self, JPC_BodyID inBodyID, JPC_Vec3 inVelocity);
 
 
 ////////////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////////
 // PhysicsSystem
 // PhysicsSystem

+ 8 - 0
JoltC/JoltC.cpp

@@ -375,6 +375,10 @@ JPC_API void JPC_BodyInterface_DestroyBody(JPC_BodyInterface* self, JPC_BodyID i
 	to_jph(self)->DestroyBody(to_jph(inBodyID));
 	to_jph(self)->DestroyBody(to_jph(inBodyID));
 }
 }
 
 
+JPC_API bool JPC_BodyInterface_IsActive(JPC_BodyInterface* self, JPC_BodyID inBodyID) {
+	return to_jph(self)->IsActive(to_jph(inBodyID));
+}
+
 JPC_API JPC_RVec3 JPC_BodyInterface_GetCenterOfMassPosition(JPC_BodyInterface* self, JPC_BodyID inBodyID) {
 JPC_API JPC_RVec3 JPC_BodyInterface_GetCenterOfMassPosition(JPC_BodyInterface* self, JPC_BodyID inBodyID) {
 	return to_jpc(to_jph(self)->GetCenterOfMassPosition(to_jph(inBodyID)));
 	return to_jpc(to_jph(self)->GetCenterOfMassPosition(to_jph(inBodyID)));
 }
 }
@@ -383,6 +387,10 @@ JPC_API JPC_Vec3 JPC_BodyInterface_GetLinearVelocity(JPC_BodyInterface* self, JP
 	return to_jpc(to_jph(self)->GetLinearVelocity(to_jph(inBodyID)));
 	return to_jpc(to_jph(self)->GetLinearVelocity(to_jph(inBodyID)));
 }
 }
 
 
+JPC_API void JPC_BodyInterface_SetLinearVelocity(JPC_BodyInterface* self, JPC_BodyID inBodyID, JPC_Vec3 inVelocity) {
+	return to_jph(self)->SetLinearVelocity(to_jph(inBodyID), to_jph(inVelocity));
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////////
 // PhysicsSystem
 // PhysicsSystem