Lucien Greathouse 1 year ago
parent
commit
dccd33afea
3 changed files with 51 additions and 5 deletions
  1. 30 5
      HelloWorld/main.cpp
  2. 8 0
      JoltC/Functions.h
  3. 13 0
      JoltC/JoltC.cpp

+ 30 - 5
HelloWorld/main.cpp

@@ -113,12 +113,12 @@ int main() {
 
 	JPC_BodyInterface* body_interface = JPC_PhysicsSystem_GetBodyInterface(physics_system);
 
-	JPC_BoxShapeSettings* floor_shape_settings = JPC_BoxShapeSettings_new(JPC_Vec3{100.0f, 100.0f, 100.0f});
+	JPC_BoxShapeSettings* floor_shape_settings = JPC_BoxShapeSettings_new(JPC_Vec3{100.0f, 1.0f, 100.0f});
 	JPC_ConvexShapeSettings_SetDensity((JPC_ConvexShapeSettings*)floor_shape_settings, 1000.0f);
 
-	JPC_Shape* shape;
+	JPC_Shape* floor_shape;
 	JPC_String* err;
-	if (!JPC_ShapeSettings_Create((JPC_ShapeSettings*)floor_shape_settings, &shape, &err)) {
+	if (!JPC_ShapeSettings_Create((JPC_ShapeSettings*)floor_shape_settings, &floor_shape, &err)) {
 		printf("fatal error: %s\n", JPC_String_c_str(err));
 
 		// the world is ending, but I guess we can still free memory
@@ -132,12 +132,34 @@ int main() {
 	floor_settings.Position = JPC_RVec3{0.0, -1.0, 0.0};
 	floor_settings.MotionType = JPC_MOTION_TYPE_STATIC;
 	floor_settings.ObjectLayer = HELLO_OL_NON_MOVING;
-	floor_settings.Shape = shape;
+	floor_settings.Shape = floor_shape;
 
 	JPC_Body* floor = JPC_BodyInterface_CreateBody(body_interface, &floor_settings);
 	JPC_BodyInterface_AddBody(body_interface, JPC_Body_GetID(floor), JPC_ACTIVATION_DONT_ACTIVATE);
 
-	// BodyCreationSettings sphere_settings(new SphereShape(0.5f), RVec3(0.0_r, 2.0_r, 0.0_r), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING);
+	JPC_SphereShapeSettings* sphere_shape_settings = JPC_SphereShapeSettings_new(0.5);
+
+	JPC_Shape* sphere_shape;
+	if (!JPC_ShapeSettings_Create((JPC_ShapeSettings*)sphere_shape_settings, &sphere_shape, &err)) {
+		printf("fatal error: %s\n", JPC_String_c_str(err));
+
+		// the world is ending, but I guess we can still free memory
+		JPC_String_delete(err);
+
+		exit(1);
+	}
+
+	JPC_BodyCreationSettings sphere_settings;
+	JPC_BodyCreationSettings_default(&sphere_settings);
+	sphere_settings.Position = JPC_RVec3{0.0, 2.0, 0.0};
+	sphere_settings.MotionType = JPC_MOTION_TYPE_DYNAMIC;
+	sphere_settings.ObjectLayer = HELLO_OL_MOVING;
+	sphere_settings.Shape = sphere_shape;
+
+	JPC_Body* sphere = JPC_BodyInterface_CreateBody(body_interface, &sphere_settings);
+	JPC_BodyID sphere_id = JPC_Body_GetID(sphere);
+	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));
@@ -154,6 +176,9 @@ int main() {
 
 	// TODO: RemoveBody and DestroyBody
 
+	JPC_BodyInterface_RemoveBody(body_interface, sphere_id);
+	JPC_BodyInterface_DestroyBody(body_interface, sphere_id);
+
 	JPC_BodyInterface_RemoveBody(body_interface, JPC_Body_GetID(floor));
 	JPC_BodyInterface_DestroyBody(body_interface, JPC_Body_GetID(floor));
 

+ 8 - 0
JoltC/Functions.h

@@ -195,6 +195,14 @@ typedef struct JPC_BoxShapeSettings JPC_BoxShapeSettings;
 JPC_API JPC_BoxShapeSettings* JPC_BoxShapeSettings_new(JPC_Vec3 inHalfExtent);
 JPC_API void JPC_BoxShapeSettings_delete(JPC_BoxShapeSettings* object);
 
+////////////////////////////////////////////////////////////////////////////////
+// SphereShapeSettings
+
+typedef struct JPC_SphereShapeSettings JPC_SphereShapeSettings;
+
+JPC_API JPC_SphereShapeSettings* JPC_SphereShapeSettings_new(float inRadius);
+JPC_API void JPC_SphereShapeSettings_delete(JPC_SphereShapeSettings* object);
+
 ////////////////////////////////////////////////////////////////////////////////
 // BodyCreationSettings
 

+ 13 - 0
JoltC/JoltC.cpp

@@ -60,6 +60,9 @@ DESTRUCTOR(JPC_String)
 OPAQUE_WRAPPER(JPC_BoxShapeSettings, JPH::BoxShapeSettings)
 DESTRUCTOR(JPC_BoxShapeSettings)
 
+OPAQUE_WRAPPER(JPC_SphereShapeSettings, JPH::SphereShapeSettings)
+DESTRUCTOR(JPC_SphereShapeSettings)
+
 static auto to_jpc(JPH::BroadPhaseLayer in) { return in.GetValue(); }
 static auto to_jph(JPC_BroadPhaseLayer in) { return JPH::BroadPhaseLayer(in); }
 
@@ -283,6 +286,16 @@ JPC_API JPC_BoxShapeSettings* JPC_BoxShapeSettings_new(JPC_Vec3 inHalfExtent) {
 	return to_jpc(new JPH::BoxShapeSettings(to_jph(inHalfExtent)));
 }
 
+////////////////////////////////////////////////////////////////////////////////
+// SphereShapeSettings
+
+JPC_API JPC_SphereShapeSettings* JPC_SphereShapeSettings_new(float inRadius) {
+	auto settings = new JPH::SphereShapeSettings{};
+	settings->mRadius = inRadius;
+
+	return to_jpc(settings);
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 // BodyCreationSettings