Przeglądaj źródła

Made samples a bit less verbose (#1239)

- Changed CreateBody/AddBody to CreateAndAddBody
Jorrit Rouwe 1 rok temu
rodzic
commit
7ca910cb4d
39 zmienionych plików z 136 dodań i 282 usunięć
  1. 1 2
      Samples/Tests/General/ActiveEdgesTest.cpp
  2. 1 2
      Samples/Tests/General/BigVsSmallTest.cpp
  3. 3 6
      Samples/Tests/General/CenterOfMassTest.cpp
  4. 1 2
      Samples/Tests/General/ChangeMotionQualityTest.cpp
  5. 2 4
      Samples/Tests/General/ContactManifoldTest.cpp
  6. 2 4
      Samples/Tests/General/HeavyOnLightTest.cpp
  7. 1 2
      Samples/Tests/General/HighSpeedTest.cpp
  8. 1 2
      Samples/Tests/General/IslandTest.cpp
  9. 1 2
      Samples/Tests/General/KinematicTest.cpp
  10. 9 19
      Samples/Tests/General/ManifoldReductionTest.cpp
  11. 2 4
      Samples/Tests/General/RestitutionTest.cpp
  12. 3 6
      Samples/Tests/General/SimpleTest.cpp
  13. 1 2
      Samples/Tests/General/StackTest.cpp
  14. 1 2
      Samples/Tests/General/WallTest.cpp
  15. 1 2
      Samples/Tests/Rig/KinematicRigTest.cpp
  16. 6 12
      Samples/Tests/ScaledShapes/ScaledBoxShapeTest.cpp
  17. 5 10
      Samples/Tests/ScaledShapes/ScaledCapsuleShapeTest.cpp
  18. 5 10
      Samples/Tests/ScaledShapes/ScaledConvexHullShapeTest.cpp
  19. 5 10
      Samples/Tests/ScaledShapes/ScaledCylinderShapeTest.cpp
  20. 8 18
      Samples/Tests/ScaledShapes/ScaledHeightFieldShapeTest.cpp
  21. 8 18
      Samples/Tests/ScaledShapes/ScaledMeshShapeTest.cpp
  22. 5 10
      Samples/Tests/ScaledShapes/ScaledMutableCompoundShapeTest.cpp
  23. 2 4
      Samples/Tests/ScaledShapes/ScaledOffsetCenterOfMassShapeTest.cpp
  24. 8 18
      Samples/Tests/ScaledShapes/ScaledPlaneShapeTest.cpp
  25. 5 10
      Samples/Tests/ScaledShapes/ScaledSphereShapeTest.cpp
  26. 5 10
      Samples/Tests/ScaledShapes/ScaledStaticCompoundShapeTest.cpp
  27. 5 10
      Samples/Tests/ScaledShapes/ScaledTaperedCapsuleShapeTest.cpp
  28. 8 18
      Samples/Tests/ScaledShapes/ScaledTriangleShapeTest.cpp
  29. 3 6
      Samples/Tests/Shapes/BoxShapeTest.cpp
  30. 3 6
      Samples/Tests/Shapes/CapsuleShapeTest.cpp
  31. 7 14
      Samples/Tests/Shapes/ConvexHullShapeTest.cpp
  32. 2 4
      Samples/Tests/Shapes/HeightFieldShapeTest.cpp
  33. 1 2
      Samples/Tests/Shapes/MeshShapeTest.cpp
  34. 3 5
      Samples/Tests/Shapes/MutableCompoundShapeTest.cpp
  35. 1 2
      Samples/Tests/Shapes/RotatedTranslatedShapeTest.cpp
  36. 4 10
      Samples/Tests/Shapes/SphereShapeTest.cpp
  37. 1 2
      Samples/Tests/Shapes/StaticCompoundShapeTest.cpp
  38. 4 8
      Samples/Tests/Shapes/TaperedCapsuleShapeTest.cpp
  39. 2 4
      Samples/Tests/Shapes/TriangleShapeTest.cpp

+ 1 - 2
Samples/Tests/General/ActiveEdgesTest.cpp

@@ -94,6 +94,5 @@ void ActiveEdgesTest::Initialize()
 	BodyCreationSettings mesh_settings(&mesh_shape, RVec3::sZero(), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING);
 	BodyCreationSettings mesh_settings(&mesh_shape, RVec3::sZero(), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING);
 	// Instead of setting mActiveEdgeCosThresholdAngle you can also set: mesh_settings.mEnhancedInternalEdgeRemoval = true
 	// Instead of setting mActiveEdgeCosThresholdAngle you can also set: mesh_settings.mEnhancedInternalEdgeRemoval = true
 	mesh_settings.mFriction = 0.0f;
 	mesh_settings.mFriction = 0.0f;
-	Body &mesh = *mBodyInterface->CreateBody(mesh_settings);
-	mBodyInterface->AddBody(mesh.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(mesh_settings, EActivation::DontActivate);
 }
 }

+ 1 - 2
Samples/Tests/General/BigVsSmallTest.cpp

@@ -21,8 +21,7 @@ void BigVsSmallTest::Initialize()
 	// Create a big triangle
 	// Create a big triangle
 	TriangleList triangles;
 	TriangleList triangles;
 	triangles.push_back(Triangle(Float3(-100, 0, 0), Float3(0, 0, 100), Float3(100, 0, -100)));
 	triangles.push_back(Triangle(Float3(-100, 0, 0), Float3(0, 0, 100), Float3(100, 0, -100)));
-	Body &triangle = *mBodyInterface->CreateBody(BodyCreationSettings(new MeshShapeSettings(triangles), RVec3::sZero(), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(triangle.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new MeshShapeSettings(triangles), RVec3::sZero(), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// A small box
 	// A small box
 	Body &body = *mBodyInterface->CreateBody(BodyCreationSettings(new BoxShape(Vec3(0.1f, 0.1f, 0.1f)), RVec3(0, 1.0f, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
 	Body &body = *mBodyInterface->CreateBody(BodyCreationSettings(new BoxShape(Vec3(0.1f, 0.1f, 0.1f)), RVec3(0, 1.0f, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));

+ 3 - 6
Samples/Tests/General/CenterOfMassTest.cpp

@@ -25,8 +25,7 @@ void CenterOfMassTest::Initialize()
 	// Compound shape with center of mass offset
 	// Compound shape with center of mass offset
 	Ref<StaticCompoundShapeSettings> compound_shape1 = new StaticCompoundShapeSettings;
 	Ref<StaticCompoundShapeSettings> compound_shape1 = new StaticCompoundShapeSettings;
 	compound_shape1->AddShape(Vec3(10, 0, 0), Quat::sIdentity(), new SphereShape(2));
 	compound_shape1->AddShape(Vec3(10, 0, 0), Quat::sIdentity(), new SphereShape(2));
-	Body &body1 = *mBodyInterface->CreateBody(BodyCreationSettings(compound_shape1, RVec3(0, 10.0f, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body1.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(compound_shape1, RVec3(0, 10.0f, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Create box with center of mass offset
 	// Create box with center of mass offset
 	Array<Vec3> box;
 	Array<Vec3> box;
@@ -38,8 +37,7 @@ void CenterOfMassTest::Initialize()
 	box.push_back(Vec3(5, 10, 5));
 	box.push_back(Vec3(5, 10, 5));
 	box.push_back(Vec3(10, 5, 5));
 	box.push_back(Vec3(10, 5, 5));
 	box.push_back(Vec3(5, 5, 5));
 	box.push_back(Vec3(5, 5, 5));
-	Body &body2 = *mBodyInterface->CreateBody(BodyCreationSettings(new ConvexHullShapeSettings(box), RVec3(0, 10.0f, 20.0f), Quat::sRotation(Vec3::sAxisX(), 0.25f * JPH_PI), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body2.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ConvexHullShapeSettings(box), RVec3(0, 10.0f, 20.0f), Quat::sRotation(Vec3::sAxisX(), 0.25f * JPH_PI), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Compound
 	// Compound
 	Ref<StaticCompoundShapeSettings> compound_shape2 = new StaticCompoundShapeSettings;
 	Ref<StaticCompoundShapeSettings> compound_shape2 = new StaticCompoundShapeSettings;
@@ -47,6 +45,5 @@ void CenterOfMassTest::Initialize()
 	compound_shape2->AddShape(Vec3(10, 0, 0), rotation, new CapsuleShape(5, 1));
 	compound_shape2->AddShape(Vec3(10, 0, 0), rotation, new CapsuleShape(5, 1));
 	compound_shape2->AddShape(rotation * Vec3(10, -5, 0), Quat::sIdentity(), new SphereShape(4));
 	compound_shape2->AddShape(rotation * Vec3(10, -5, 0), Quat::sIdentity(), new SphereShape(4));
 	compound_shape2->AddShape(rotation * Vec3(10, 5, 0), Quat::sIdentity(), new SphereShape(2));
 	compound_shape2->AddShape(rotation * Vec3(10, 5, 0), Quat::sIdentity(), new SphereShape(2));
-	Body &body3 = *mBodyInterface->CreateBody(BodyCreationSettings(compound_shape2, RVec3(0, 10.0f, 40.0f), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body3.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(compound_shape2, RVec3(0, 10.0f, 40.0f), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 }
 }

+ 1 - 2
Samples/Tests/General/ChangeMotionQualityTest.cpp

@@ -33,8 +33,7 @@ void ChangeMotionQualityTest::Initialize()
 	enclosing_settings.mMotionType = EMotionType::Kinematic;
 	enclosing_settings.mMotionType = EMotionType::Kinematic;
 	enclosing_settings.mObjectLayer = Layers::MOVING;
 	enclosing_settings.mObjectLayer = Layers::MOVING;
 	enclosing_settings.mPosition = RVec3(0, 1, 0);
 	enclosing_settings.mPosition = RVec3(0, 1, 0);
-	Body &enclosing = *mBodyInterface->CreateBody(enclosing_settings);
-	mBodyInterface->AddBody(enclosing.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(enclosing_settings, EActivation::Activate);
 
 
 	// Create high speed sphere inside
 	// Create high speed sphere inside
 	BodyCreationSettings settings;
 	BodyCreationSettings settings;

+ 2 - 4
Samples/Tests/General/ContactManifoldTest.cpp

@@ -28,11 +28,9 @@ void ContactManifoldTest::Initialize()
 		for (int j = 0; j < 2; ++j)
 		for (int j = 0; j < 2; ++j)
 		{
 		{
 			// Create a box
 			// Create a box
-			Body &box = *mBodyInterface->CreateBody(BodyCreationSettings(big_box, RVec3(-20.0f + i * 10.0f, 4, -20.0f + j * 40.0f), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-			mBodyInterface->AddBody(box.GetID(), EActivation::DontActivate);
+			mBodyInterface->CreateAndAddBody(BodyCreationSettings(big_box, RVec3(-20.0f + i * 10.0f, 4, -20.0f + j * 40.0f), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 			// Place a dynamic body on it
 			// Place a dynamic body on it
-			Body &body = *mBodyInterface->CreateBody(BodyCreationSettings(j == 0? capsule : long_box, RVec3(-20.0f + i * 10.0f, 12, -5.0f + i * 5.0f - 20.0f + j * 40.0f), Quat::sRotation(Vec3::sAxisY(), 0.1f * JPH_PI) * Quat::sRotation(Vec3::sAxisX(), 0.5f * JPH_PI), EMotionType::Dynamic, Layers::MOVING));
-			mBodyInterface->AddBody(body.GetID(), EActivation::Activate);
+			mBodyInterface->CreateAndAddBody(BodyCreationSettings(j == 0? capsule : long_box, RVec3(-20.0f + i * 10.0f, 12, -5.0f + i * 5.0f - 20.0f + j * 40.0f), Quat::sRotation(Vec3::sAxisY(), 0.1f * JPH_PI) * Quat::sRotation(Vec3::sAxisX(), 0.5f * JPH_PI), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 		}
 		}
 }
 }

+ 2 - 4
Samples/Tests/General/HeavyOnLightTest.cpp

@@ -24,13 +24,11 @@ void HeavyOnLightTest::Initialize()
 
 
 	for (int i = 1; i <= 10; ++i)
 	for (int i = 1; i <= 10; ++i)
 	{
 	{
-		Body &body1 = *mBodyInterface->CreateBody(BodyCreationSettings(box, RVec3(-75.0f + i * 15.0f, 10.0f, 0.0f), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-		mBodyInterface->AddBody(body1.GetID(), EActivation::Activate);
+		mBodyInterface->CreateAndAddBody(BodyCreationSettings(box, RVec3(-75.0f + i * 15.0f, 10.0f, 0.0f), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 		Ref<BoxShape> box2 = new BoxShape(Vec3::sReplicate(5));
 		Ref<BoxShape> box2 = new BoxShape(Vec3::sReplicate(5));
 		box2->SetDensity(5000.0f * i);
 		box2->SetDensity(5000.0f * i);
 
 
-		Body &body2 = *mBodyInterface->CreateBody(BodyCreationSettings(box2, RVec3(-75.0f + i * 15.0f, 30.0f, 0.0f), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-		mBodyInterface->AddBody(body2.GetID(), EActivation::Activate);
+		mBodyInterface->CreateAndAddBody(BodyCreationSettings(box2, RVec3(-75.0f + i * 15.0f, 30.0f, 0.0f), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 	}
 	}
 }
 }

+ 1 - 2
Samples/Tests/General/HighSpeedTest.cpp

@@ -147,8 +147,7 @@ void HighSpeedTest::CreateSimpleScene()
 		enclosing_settings.mMotionType = EMotionType::Kinematic;
 		enclosing_settings.mMotionType = EMotionType::Kinematic;
 		enclosing_settings.mObjectLayer = Layers::MOVING;
 		enclosing_settings.mObjectLayer = Layers::MOVING;
 		enclosing_settings.mPosition = offset + Vec3(0, 1, 0);
 		enclosing_settings.mPosition = offset + Vec3(0, 1, 0);
-		Body &enclosing = *mBodyInterface->CreateBody(enclosing_settings);
-		mBodyInterface->AddBody(enclosing.GetID(), EActivation::Activate);
+		mBodyInterface->CreateAndAddBody(enclosing_settings, EActivation::Activate);
 
 
 		// Fast moving sphere in box
 		// Fast moving sphere in box
 		CreateDynamicObject(offset + Vec3(0, 0.5f, 0), Vec3(-speed, 0, -0.5f * speed), new SphereShape(radius));
 		CreateDynamicObject(offset + Vec3(0, 0.5f, 0), Vec3(-speed, 0, -0.5f * speed), new SphereShape(radius));

+ 1 - 2
Samples/Tests/General/IslandTest.cpp

@@ -27,7 +27,6 @@ void IslandTest::Initialize()
 			for (int k = 0; k < 8; ++k)
 			for (int k = 0; k < 8; ++k)
 			{
 			{
 				RVec3 position(-10 + j * 2.0f + (i & 1? 1.0f : 0.0f), 1.0f + i * 2.0f, 8.0f * (k - 4));
 				RVec3 position(-10 + j * 2.0f + (i & 1? 1.0f : 0.0f), 1.0f + i * 2.0f, 8.0f * (k - 4));
-				Body &wall = *mBodyInterface->CreateBody(BodyCreationSettings(box_shape, position, Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-				mBodyInterface->AddBody(wall.GetID(), EActivation::Activate);
+				mBodyInterface->CreateAndAddBody(BodyCreationSettings(box_shape, position, Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 			}
 			}
 }
 }

+ 1 - 2
Samples/Tests/General/KinematicTest.cpp

@@ -26,8 +26,7 @@ void KinematicTest::Initialize()
 		for (int j = i / 2; j < 10 - (i + 1) / 2; ++j)
 		for (int j = i / 2; j < 10 - (i + 1) / 2; ++j)
 		{
 		{
 			RVec3 position(-10.0f + j * 2.0f + (i & 1? 1.0f : 0.0f), 1.0f + i * 2.0f, 0);
 			RVec3 position(-10.0f + j * 2.0f + (i & 1? 1.0f : 0.0f), 1.0f + i * 2.0f, 0);
-			Body &wall = *mBodyInterface->CreateBody(BodyCreationSettings(box_shape, position, Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-			mBodyInterface->AddBody(wall.GetID(), EActivation::DontActivate);
+			mBodyInterface->CreateAndAddBody(BodyCreationSettings(box_shape, position, Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::DontActivate);
 		}
 		}
 
 
 	// Kinematic object
 	// Kinematic object

+ 9 - 19
Samples/Tests/General/ManifoldReductionTest.cpp

@@ -46,8 +46,7 @@ void ManifoldReductionTest::Initialize()
 	Ref<ShapeSettings> mesh_shape = new MeshShapeSettings(triangles, std::move(materials));
 	Ref<ShapeSettings> mesh_shape = new MeshShapeSettings(triangles, std::move(materials));
 
 
 	// Floor
 	// Floor
-	Body &floor = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(mesh_shape, Vec3::sReplicate(20)), RVec3::sZero(), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(floor.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(mesh_shape, Vec3::sReplicate(20)), RVec3::sZero(), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Create a box made of meshes
 	// Create a box made of meshes
 	Ref<StaticCompoundShapeSettings> mesh_box_shape = new StaticCompoundShapeSettings;
 	Ref<StaticCompoundShapeSettings> mesh_box_shape = new StaticCompoundShapeSettings;
@@ -75,16 +74,13 @@ void ManifoldReductionTest::Initialize()
 		three_box_shape->AddShape(Vec3(0, -1.1f, 0), Quat::sIdentity(), box_shape);
 		three_box_shape->AddShape(Vec3(0, -1.1f, 0), Quat::sIdentity(), box_shape);
 		three_box_shape->AddShape(Vec3(2.1f, 0, 0), Quat::sIdentity(), box_shape);
 		three_box_shape->AddShape(Vec3(2.1f, 0, 0), Quat::sIdentity(), box_shape);
 
 
-
 		// A set of 3 mesh boxes to rest on
 		// A set of 3 mesh boxes to rest on
-		Body &three_mesh_box = *mBodyInterface->CreateBody(BodyCreationSettings(three_mesh_box_shape, RVec3(0, 1, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-		mBodyInterface->AddBody(three_mesh_box.GetID(), EActivation::DontActivate);
+		mBodyInterface->CreateAndAddBody(BodyCreationSettings(three_mesh_box_shape, RVec3(0, 1, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 		// A set of 3 boxes that are dynamic where the middle one penetrates more than the other two
 		// A set of 3 boxes that are dynamic where the middle one penetrates more than the other two
 		BodyCreationSettings box_settings(three_box_shape, RVec3(0, 2.95f, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING);
 		BodyCreationSettings box_settings(three_box_shape, RVec3(0, 2.95f, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING);
 		box_settings.mAllowSleeping = false;
 		box_settings.mAllowSleeping = false;
-		Body &box = *mBodyInterface->CreateBody(box_settings);
-		mBodyInterface->AddBody(box.GetID(), EActivation::Activate);
+		mBodyInterface->CreateAndAddBody(box_settings, EActivation::Activate);
 	}
 	}
 
 
 	{
 	{
@@ -100,14 +96,12 @@ void ManifoldReductionTest::Initialize()
 
 
 
 
 		// A set of 2 mesh boxes to rest on
 		// A set of 2 mesh boxes to rest on
-		Body &two_mesh_box = *mBodyInterface->CreateBody(BodyCreationSettings(two_mesh_box_shape, RVec3(0, 1, 4), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-		mBodyInterface->AddBody(two_mesh_box.GetID(), EActivation::DontActivate);
+		mBodyInterface->CreateAndAddBody(BodyCreationSettings(two_mesh_box_shape, RVec3(0, 1, 4), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 		// A set of 2 boxes that are dynamic, one is lower than the other
 		// A set of 2 boxes that are dynamic, one is lower than the other
 		BodyCreationSettings box_settings(two_box_shape, RVec3(0, 4, 4), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING);
 		BodyCreationSettings box_settings(two_box_shape, RVec3(0, 4, 4), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING);
 		box_settings.mAllowSleeping = false;
 		box_settings.mAllowSleeping = false;
-		Body &box = *mBodyInterface->CreateBody(box_settings);
-		mBodyInterface->AddBody(box.GetID(), EActivation::Activate);
+		mBodyInterface->CreateAndAddBody(box_settings, EActivation::Activate);
 	}
 	}
 
 
 	{
 	{
@@ -117,14 +111,12 @@ void ManifoldReductionTest::Initialize()
 		two_mesh_shape->AddShape(Vec3(-1, 0, 0), Quat::sRotation(Vec3::sAxisZ(), DegreesToRadians(-2)), mesh_shape);
 		two_mesh_shape->AddShape(Vec3(-1, 0, 0), Quat::sRotation(Vec3::sAxisZ(), DegreesToRadians(-2)), mesh_shape);
 
 
 		// A set of 2 meshes to rest on
 		// A set of 2 meshes to rest on
-		Body &two_mesh_box = *mBodyInterface->CreateBody(BodyCreationSettings(two_mesh_shape, RVec3(0, 1, -4), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-		mBodyInterface->AddBody(two_mesh_box.GetID(), EActivation::DontActivate);
+		mBodyInterface->CreateAndAddBody(BodyCreationSettings(two_mesh_shape, RVec3(0, 1, -4), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 		// A box that is dynamic, resting on the slightly sloped surface. The surface normals are close enough so that the manifold should be merged.
 		// A box that is dynamic, resting on the slightly sloped surface. The surface normals are close enough so that the manifold should be merged.
 		BodyCreationSettings box_settings(box_shape, RVec3(0, 4, -4), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING);
 		BodyCreationSettings box_settings(box_shape, RVec3(0, 4, -4), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING);
 		box_settings.mAllowSleeping = false;
 		box_settings.mAllowSleeping = false;
-		Body &box = *mBodyInterface->CreateBody(box_settings);
-		mBodyInterface->AddBody(box.GetID(), EActivation::Activate);
+		mBodyInterface->CreateAndAddBody(box_settings, EActivation::Activate);
 	}
 	}
 
 
 	{
 	{
@@ -134,13 +126,11 @@ void ManifoldReductionTest::Initialize()
 		two_mesh_shape->AddShape(Vec3(-1, 0, 0), Quat::sRotation(Vec3::sAxisZ(), DegreesToRadians(-3)), mesh_shape);
 		two_mesh_shape->AddShape(Vec3(-1, 0, 0), Quat::sRotation(Vec3::sAxisZ(), DegreesToRadians(-3)), mesh_shape);
 
 
 		// A set of 2 meshes to rest on
 		// A set of 2 meshes to rest on
-		Body &two_mesh_box = *mBodyInterface->CreateBody(BodyCreationSettings(two_mesh_shape, RVec3(0, 1, -8), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-		mBodyInterface->AddBody(two_mesh_box.GetID(), EActivation::DontActivate);
+		mBodyInterface->CreateAndAddBody(BodyCreationSettings(two_mesh_shape, RVec3(0, 1, -8), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 		// A box that is dynamic, resting on the slightly sloped surface. The surface normals are not close enough so that the manifold should be merged.
 		// A box that is dynamic, resting on the slightly sloped surface. The surface normals are not close enough so that the manifold should be merged.
 		BodyCreationSettings box_settings(box_shape, RVec3(0, 4, -8), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING);
 		BodyCreationSettings box_settings(box_shape, RVec3(0, 4, -8), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING);
 		box_settings.mAllowSleeping = false;
 		box_settings.mAllowSleeping = false;
-		Body &box = *mBodyInterface->CreateBody(box_settings);
-		mBodyInterface->AddBody(box.GetID(), EActivation::Activate);
+		mBodyInterface->CreateAndAddBody(box_settings, EActivation::Activate);
 	}
 	}
 }
 }

+ 2 - 4
Samples/Tests/General/RestitutionTest.cpp

@@ -29,8 +29,7 @@ void RestitutionTest::Initialize()
 		BodyCreationSettings settings(sphere, RVec3(-50.0f + i * 10.0f, 20.0f, -20.0f), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING);
 		BodyCreationSettings settings(sphere, RVec3(-50.0f + i * 10.0f, 20.0f, -20.0f), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING);
 		settings.mRestitution = 0.1f * i;
 		settings.mRestitution = 0.1f * i;
 		settings.mLinearDamping = 0.0f;
 		settings.mLinearDamping = 0.0f;
-		Body &body = *mBodyInterface->CreateBody(settings);
-		mBodyInterface->AddBody(body.GetID(), EActivation::Activate);
+		mBodyInterface->CreateAndAddBody(settings, EActivation::Activate);
 	}
 	}
 
 
 	for (int i = 0; i <= 10; ++i)
 	for (int i = 0; i <= 10; ++i)
@@ -38,7 +37,6 @@ void RestitutionTest::Initialize()
 		BodyCreationSettings settings(box, RVec3(-50.0f + i * 10.0f, 20.0f, 20.0f), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING);
 		BodyCreationSettings settings(box, RVec3(-50.0f + i * 10.0f, 20.0f, 20.0f), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING);
 		settings.mRestitution = 0.1f * i;
 		settings.mRestitution = 0.1f * i;
 		settings.mLinearDamping = 0.0f;
 		settings.mLinearDamping = 0.0f;
-		Body &body = *mBodyInterface->CreateBody(settings);
-		mBodyInterface->AddBody(body.GetID(), EActivation::Activate);
+		mBodyInterface->CreateAndAddBody(settings, EActivation::Activate);
 	}
 	}
 }
 }

+ 3 - 6
Samples/Tests/General/SimpleTest.cpp

@@ -33,14 +33,11 @@ void SimpleTest::Initialize()
 	RefConst<Shape> box_shape = new BoxShape(Vec3(0.5f, 1.0f, 2.0f));
 	RefConst<Shape> box_shape = new BoxShape(Vec3(0.5f, 1.0f, 2.0f));
 
 
 	// Dynamic body 1
 	// Dynamic body 1
-	Body &body1 = *mBodyInterface->CreateBody(BodyCreationSettings(box_shape, RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body1.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(box_shape, RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Dynamic body 2
 	// Dynamic body 2
-	Body &body2 = *mBodyInterface->CreateBody(BodyCreationSettings(box_shape, RVec3(5, 10, 0), Quat::sRotation(Vec3::sAxisX(), 0.25f * JPH_PI), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body2.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(box_shape, RVec3(5, 10, 0), Quat::sRotation(Vec3::sAxisX(), 0.25f * JPH_PI), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Dynamic body 3
 	// Dynamic body 3
-	Body &body3 = *mBodyInterface->CreateBody(BodyCreationSettings(new SphereShape(2.0f), RVec3(10, 10, 0), Quat::sRotation(Vec3::sAxisX(), 0.25f * JPH_PI), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body3.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new SphereShape(2.0f), RVec3(10, 10, 0), Quat::sRotation(Vec3::sAxisX(), 0.25f * JPH_PI), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 }
 }

+ 1 - 2
Samples/Tests/General/StackTest.cpp

@@ -29,7 +29,6 @@ void StackTest::Initialize()
 			rotation = Quat::sRotation(Vec3::sAxisY(), 0.5f * JPH_PI);
 			rotation = Quat::sRotation(Vec3::sAxisY(), 0.5f * JPH_PI);
 		else
 		else
 			rotation = Quat::sIdentity();
 			rotation = Quat::sIdentity();
-		Body &stack = *mBodyInterface->CreateBody(BodyCreationSettings(box_shape, RVec3(10, 1.0f + i * 2.1f, 0), rotation, EMotionType::Dynamic, Layers::MOVING));
-		mBodyInterface->AddBody(stack.GetID(), EActivation::Activate);
+		mBodyInterface->CreateAndAddBody(BodyCreationSettings(box_shape, RVec3(10, 1.0f + i * 2.1f, 0), rotation, EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 	}
 	}
 }
 }

+ 1 - 2
Samples/Tests/General/WallTest.cpp

@@ -26,7 +26,6 @@ void WallTest::Initialize()
 		for (int j = i / 2; j < 50 - (i + 1) / 2; ++j)
 		for (int j = i / 2; j < 50 - (i + 1) / 2; ++j)
 		{
 		{
 			RVec3 position(-50 + j * 2.0f + (i & 1? 1.0f : 0.0f), 1.0f + i * 3.0f, 0);
 			RVec3 position(-50 + j * 2.0f + (i & 1? 1.0f : 0.0f), 1.0f + i * 3.0f, 0);
-			Body &wall = *mBodyInterface->CreateBody(BodyCreationSettings(box_shape, position, Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-			mBodyInterface->AddBody(wall.GetID(), EActivation::Activate);
+			mBodyInterface->CreateAndAddBody(BodyCreationSettings(box_shape, position, Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 		}
 		}
 }
 }

+ 1 - 2
Samples/Tests/Rig/KinematicRigTest.cpp

@@ -46,8 +46,7 @@ void KinematicRigTest::Initialize()
 		for (int j = i / 2; j < 10 - (i + 1) / 2; ++j)
 		for (int j = i / 2; j < 10 - (i + 1) / 2; ++j)
 		{
 		{
 			RVec3 position(-2.0f + j * 0.4f + (i & 1? 0.2f : 0.0f), 0.2f + i * 0.4f, -2.0f);
 			RVec3 position(-2.0f + j * 0.4f + (i & 1? 0.2f : 0.0f), 0.2f + i * 0.4f, -2.0f);
-			Body &wall = *mBodyInterface->CreateBody(BodyCreationSettings(box_shape, position, Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-			mBodyInterface->AddBody(wall.GetID(), EActivation::DontActivate);
+			mBodyInterface->CreateAndAddBody(BodyCreationSettings(box_shape, position, Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::DontActivate);
 		}
 		}
 
 
 	// Load ragdoll
 	// Load ragdoll

+ 6 - 12
Samples/Tests/ScaledShapes/ScaledBoxShapeTest.cpp

@@ -24,26 +24,20 @@ void ScaledBoxShapeTest::Initialize()
 	RefConst<BoxShape> box_shape = new BoxShape(Vec3(3, 2, 1.5f));
 	RefConst<BoxShape> box_shape = new BoxShape(Vec3(3, 2, 1.5f));
 
 
 	// Original shape
 	// Original shape
-	Body &body1 = *mBodyInterface->CreateBody(BodyCreationSettings(box_shape, RVec3(-30, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body1.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(box_shape, RVec3(-30, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Uniformly scaled shape < 1
 	// Uniformly scaled shape < 1
-	Body &body2 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShape(box_shape, Vec3::sReplicate(0.25f)), RVec3(-20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body2.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShape(box_shape, Vec3::sReplicate(0.25f)), RVec3(-20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Uniformly scaled shape > 1
 	// Uniformly scaled shape > 1
-	Body &body3 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShape(box_shape, Vec3::sReplicate(2.0f)), RVec3(-10, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body3.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShape(box_shape, Vec3::sReplicate(2.0f)), RVec3(-10, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Non-uniform scaled shape
 	// Non-uniform scaled shape
-	Body &body4 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShape(box_shape, Vec3(0.25f, 0.5f, 1.5f)), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body4.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShape(box_shape, Vec3(0.25f, 0.5f, 1.5f)), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Flipped in 2 axis
 	// Flipped in 2 axis
-	Body &body5 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShape(box_shape, Vec3(-0.25f, 0.5f, -1.5f)), RVec3(10, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body5.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShape(box_shape, Vec3(-0.25f, 0.5f, -1.5f)), RVec3(10, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Inside out
 	// Inside out
-	Body &body6 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShape(box_shape, Vec3(-0.25f, 0.5f, 1.5f)), RVec3(20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body6.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShape(box_shape, Vec3(-0.25f, 0.5f, 1.5f)), RVec3(20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 }
 }

+ 5 - 10
Samples/Tests/ScaledShapes/ScaledCapsuleShapeTest.cpp

@@ -24,22 +24,17 @@ void ScaledCapsuleShapeTest::Initialize()
 	RefConst<CapsuleShape> capsule_shape = new CapsuleShape(2.0f, 0.5f);
 	RefConst<CapsuleShape> capsule_shape = new CapsuleShape(2.0f, 0.5f);
 
 
 	// Original shape
 	// Original shape
-	Body &body1 = *mBodyInterface->CreateBody(BodyCreationSettings(capsule_shape, RVec3(-20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body1.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(capsule_shape, RVec3(-20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Uniformly scaled shape < 1
 	// Uniformly scaled shape < 1
-	Body &body2 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShape(capsule_shape, Vec3::sReplicate(0.25f)), RVec3(-10, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body2.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShape(capsule_shape, Vec3::sReplicate(0.25f)), RVec3(-10, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Uniformly scaled shape > 1
 	// Uniformly scaled shape > 1
-	Body &body3 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShape(capsule_shape, Vec3::sReplicate(2.0f)), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body3.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShape(capsule_shape, Vec3::sReplicate(2.0f)), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Flipped in 2 axis
 	// Flipped in 2 axis
-	Body &body4 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShape(capsule_shape, Vec3(-1.5f, -1.5f, 1.5f)), RVec3(10, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body4.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShape(capsule_shape, Vec3(-1.5f, -1.5f, 1.5f)), RVec3(10, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Inside out
 	// Inside out
-	Body &body5 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShape(capsule_shape, Vec3(-0.75f, 0.75f, 0.75f)), RVec3(20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body5.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShape(capsule_shape, Vec3(-0.75f, 0.75f, 0.75f)), RVec3(20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 }
 }

+ 5 - 10
Samples/Tests/ScaledShapes/ScaledConvexHullShapeTest.cpp

@@ -49,23 +49,18 @@ void ScaledConvexHullShapeTest::Initialize()
 	for (int i = 0; i < 2; ++i)
 	for (int i = 0; i < 2; ++i)
 	{
 	{
 		// Original shape
 		// Original shape
-		Body &body1 = *mBodyInterface->CreateBody(BodyCreationSettings(hull_shape[i], RVec3(-40, 10, i * 20.0f), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-		mBodyInterface->AddBody(body1.GetID(), EActivation::Activate);
+		mBodyInterface->CreateAndAddBody(BodyCreationSettings(hull_shape[i], RVec3(-40, 10, i * 20.0f), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 		// Uniformly scaled shape
 		// Uniformly scaled shape
-		Body &body2 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(hull_shape[i], Vec3::sReplicate(0.25f)), RVec3(-20, 10, i * 20.0f), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-		mBodyInterface->AddBody(body2.GetID(), EActivation::Activate);
+		mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(hull_shape[i], Vec3::sReplicate(0.25f)), RVec3(-20, 10, i * 20.0f), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 		// Non-uniform scaled shape
 		// Non-uniform scaled shape
-		Body &body3 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(hull_shape[i], Vec3(0.25f, 0.5f, 1.5f)), RVec3(0, 10, i * 20.0f), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-		mBodyInterface->AddBody(body3.GetID(), EActivation::Activate);
+		mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(hull_shape[i], Vec3(0.25f, 0.5f, 1.5f)), RVec3(0, 10, i * 20.0f), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 		// Flipped in 2 axis
 		// Flipped in 2 axis
-		Body &body4 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(hull_shape[i], Vec3(-0.25f, 0.5f, -1.5f)), RVec3(20, 10, i * 20.0f), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-		mBodyInterface->AddBody(body4.GetID(), EActivation::Activate);
+		mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(hull_shape[i], Vec3(-0.25f, 0.5f, -1.5f)), RVec3(20, 10, i * 20.0f), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 		// Inside out
 		// Inside out
-		Body &body5 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(hull_shape[i], Vec3(-0.25f, 0.5f, 1.5f)), RVec3(40, 10, i * 20.0f), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-		mBodyInterface->AddBody(body5.GetID(), EActivation::Activate);
+		mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(hull_shape[i], Vec3(-0.25f, 0.5f, 1.5f)), RVec3(40, 10, i * 20.0f), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 	}
 	}
 }
 }

+ 5 - 10
Samples/Tests/ScaledShapes/ScaledCylinderShapeTest.cpp

@@ -24,22 +24,17 @@ void ScaledCylinderShapeTest::Initialize()
 	RefConst<CylinderShape> cylinder_shape = new CylinderShape(3.0f, 2.0f);
 	RefConst<CylinderShape> cylinder_shape = new CylinderShape(3.0f, 2.0f);
 
 
 	// Original shape
 	// Original shape
-	Body &body1 = *mBodyInterface->CreateBody(BodyCreationSettings(cylinder_shape, RVec3(-20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body1.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(cylinder_shape, RVec3(-20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Uniformly scaled shape
 	// Uniformly scaled shape
-	Body &body2 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShape(cylinder_shape, Vec3::sReplicate(0.25f)), RVec3(-10, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body2.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShape(cylinder_shape, Vec3::sReplicate(0.25f)), RVec3(-10, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Non-uniform scaled shape
 	// Non-uniform scaled shape
-	Body &body3 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShape(cylinder_shape, Vec3(0.25f, 0.5f, 0.25f)), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body3.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShape(cylinder_shape, Vec3(0.25f, 0.5f, 0.25f)), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Flipped in 2 axis
 	// Flipped in 2 axis
-	Body &body4 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShape(cylinder_shape, Vec3(-1.5f, -0.5f, 1.5f)), RVec3(10, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body4.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShape(cylinder_shape, Vec3(-1.5f, -0.5f, 1.5f)), RVec3(10, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Inside out
 	// Inside out
-	Body &body5 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShape(cylinder_shape, Vec3(-0.25f, 1.5f, 0.25f)), RVec3(20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body5.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShape(cylinder_shape, Vec3(-0.25f, 1.5f, 0.25f)), RVec3(20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 }
 }

+ 8 - 18
Samples/Tests/ScaledShapes/ScaledHeightFieldShapeTest.cpp

@@ -50,40 +50,30 @@ void ScaledHeightFieldShapeTest::Initialize()
 	RefConst<ShapeSettings> height_field = new HeightFieldShapeSettings(heights, Vec3(-0.5f * cell_size * n, 0.0f, -0.5f * cell_size * n), Vec3(cell_size, 1.0f, cell_size), n);
 	RefConst<ShapeSettings> height_field = new HeightFieldShapeSettings(heights, Vec3(-0.5f * cell_size * n, 0.0f, -0.5f * cell_size * n), Vec3(cell_size, 1.0f, cell_size), n);
 
 
 	// Original shape
 	// Original shape
-	Body &body1 = *mBodyInterface->CreateBody(BodyCreationSettings(height_field, RVec3(-60, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body1.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(height_field, RVec3(-60, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Uniformly scaled shape < 1
 	// Uniformly scaled shape < 1
-	Body &body2 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(height_field, Vec3::sReplicate(0.5f)), RVec3(-40, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body2.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(height_field, Vec3::sReplicate(0.5f)), RVec3(-40, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Uniformly scaled shape > 1
 	// Uniformly scaled shape > 1
-	Body &body3 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(height_field, Vec3::sReplicate(1.5f)), RVec3(-20, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body3.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(height_field, Vec3::sReplicate(1.5f)), RVec3(-20, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Non-uniform scaled shape
 	// Non-uniform scaled shape
-	Body &body4 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(height_field, Vec3(0.5f, 1.0f, 1.5f)), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body4.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(height_field, Vec3(0.5f, 1.0f, 1.5f)), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Flipped in 2 axis
 	// Flipped in 2 axis
-	Body &body5 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(height_field, Vec3(-0.5f, 1.0f, -1.5f)), RVec3(20, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body5.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(height_field, Vec3(-0.5f, 1.0f, -1.5f)), RVec3(20, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Inside out
 	// Inside out
-	Body &body6 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(height_field, Vec3(-0.5f, 1.0f, 1.5f)), RVec3(40, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body6.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(height_field, Vec3(-0.5f, 1.0f, 1.5f)), RVec3(40, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Upside down
 	// Upside down
-	Body &body7 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(height_field, Vec3(0.5f, -1.0f, 1.5f)), RVec3(60, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body7.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(height_field, Vec3(0.5f, -1.0f, 1.5f)), RVec3(60, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Create a number of balls above the height fields
 	// Create a number of balls above the height fields
 	RefConst<Shape> sphere_shape = new SphereShape(0.2f);
 	RefConst<Shape> sphere_shape = new SphereShape(0.2f);
 	RefConst<Shape> box_shape = new BoxShape(Vec3(0.2f, 0.2f, 0.4f), 0.01f);
 	RefConst<Shape> box_shape = new BoxShape(Vec3(0.2f, 0.2f, 0.4f), 0.01f);
 	for (int i = 0; i < 7; ++i)
 	for (int i = 0; i < 7; ++i)
 		for (int j = 0; j < 5; ++j)
 		for (int j = 0; j < 5; ++j)
-		{
-			Body &dynamic = *mBodyInterface->CreateBody(BodyCreationSettings((j & 1)? box_shape : sphere_shape, RVec3(-60.0f + 20.0f * i, 10.0f + max_height + 0.5f * j, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-			mBodyInterface->AddBody(dynamic.GetID(), EActivation::Activate);
-		}
+			mBodyInterface->CreateAndAddBody(BodyCreationSettings((j & 1)? box_shape : sphere_shape, RVec3(-60.0f + 20.0f * i, 10.0f + max_height + 0.5f * j, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 }
 }

+ 8 - 18
Samples/Tests/ScaledShapes/ScaledMeshShapeTest.cpp

@@ -70,40 +70,30 @@ void ScaledMeshShapeTest::Initialize()
 	RefConst<ShapeSettings> mesh_shape = new MeshShapeSettings(triangles);
 	RefConst<ShapeSettings> mesh_shape = new MeshShapeSettings(triangles);
 
 
 	// Original shape
 	// Original shape
-	Body &body1 = *mBodyInterface->CreateBody(BodyCreationSettings(mesh_shape, RVec3(-60, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body1.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(mesh_shape, RVec3(-60, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Uniformly scaled shape < 1
 	// Uniformly scaled shape < 1
-	Body &body2 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(mesh_shape, Vec3::sReplicate(0.5f)), RVec3(-40, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body2.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(mesh_shape, Vec3::sReplicate(0.5f)), RVec3(-40, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Uniformly scaled shape > 1
 	// Uniformly scaled shape > 1
-	Body &body3 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(mesh_shape, Vec3::sReplicate(1.5f)), RVec3(-20, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body3.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(mesh_shape, Vec3::sReplicate(1.5f)), RVec3(-20, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Non-uniform scaled shape
 	// Non-uniform scaled shape
-	Body &body4 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(mesh_shape, Vec3(0.5f, 1.0f, 1.5f)), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body4.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(mesh_shape, Vec3(0.5f, 1.0f, 1.5f)), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Flipped in 2 axis
 	// Flipped in 2 axis
-	Body &body5 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(mesh_shape, Vec3(-0.5f, 1.0f, -1.5f)), RVec3(20, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body5.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(mesh_shape, Vec3(-0.5f, 1.0f, -1.5f)), RVec3(20, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Inside out
 	// Inside out
-	Body &body6 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(mesh_shape, Vec3(-0.5f, 1.0f, 1.5f)), RVec3(40, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body6.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(mesh_shape, Vec3(-0.5f, 1.0f, 1.5f)), RVec3(40, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Upside down
 	// Upside down
-	Body &body7 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(mesh_shape, Vec3(0.5f, -1.0f, 1.5f)), RVec3(60, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body7.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(mesh_shape, Vec3(0.5f, -1.0f, 1.5f)), RVec3(60, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Create a number of balls above the meshes
 	// Create a number of balls above the meshes
 	RefConst<Shape> sphere_shape = new SphereShape(0.2f);
 	RefConst<Shape> sphere_shape = new SphereShape(0.2f);
 	RefConst<Shape> box_shape = new BoxShape(Vec3(0.2f, 0.2f, 0.4f), 0.01f);
 	RefConst<Shape> box_shape = new BoxShape(Vec3(0.2f, 0.2f, 0.4f), 0.01f);
 	for (int i = 0; i < 7; ++i)
 	for (int i = 0; i < 7; ++i)
 		for (int j = 0; j < 5; ++j)
 		for (int j = 0; j < 5; ++j)
-		{
-			Body &dynamic = *mBodyInterface->CreateBody(BodyCreationSettings((j & 1)? box_shape : sphere_shape, RVec3(-60.0f + 20.0f * i, 10.0f + max_height + 0.5f * j, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-			mBodyInterface->AddBody(dynamic.GetID(), EActivation::Activate);
-		}
+			mBodyInterface->CreateAndAddBody(BodyCreationSettings((j & 1)? box_shape : sphere_shape, RVec3(-60.0f + 20.0f * i, 10.0f + max_height + 0.5f * j, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 }
 }

+ 5 - 10
Samples/Tests/ScaledShapes/ScaledMutableCompoundShapeTest.cpp

@@ -64,22 +64,17 @@ void ScaledMutableCompoundShapeTest::Initialize()
 	compound_shape->AddShape(Vec3(-5, -0.5f, -0.5f), Quat::sIdentity(), center_shape);
 	compound_shape->AddShape(Vec3(-5, -0.5f, -0.5f), Quat::sIdentity(), center_shape);
 
 
 	// Original shape
 	// Original shape
-	Body &body1 = *mBodyInterface->CreateBody(BodyCreationSettings(compound_shape, RVec3(-40, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body1.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(compound_shape, RVec3(-40, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Uniformly scaled shape
 	// Uniformly scaled shape
-	Body &body2 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(compound_shape, Vec3::sReplicate(0.25f)), RVec3(-20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body2.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(compound_shape, Vec3::sReplicate(0.25f)), RVec3(-20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Non-uniform scaled shape
 	// Non-uniform scaled shape
-	Body &body3 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(compound_shape, Vec3(0.25f, 0.5f, 1.5f)), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body3.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(compound_shape, Vec3(0.25f, 0.5f, 1.5f)), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Flipped in 2 axis
 	// Flipped in 2 axis
-	Body &body4 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(compound_shape, Vec3(-0.25f, 0.5f, -1.5f)), RVec3(20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body4.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(compound_shape, Vec3(-0.25f, 0.5f, -1.5f)), RVec3(20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Inside out
 	// Inside out
-	Body &body5 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(compound_shape, Vec3(-0.25f, 0.5f, 1.5f)), RVec3(40, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body5.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(compound_shape, Vec3(-0.25f, 0.5f, 1.5f)), RVec3(40, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 }
 }

+ 2 - 4
Samples/Tests/ScaledShapes/ScaledOffsetCenterOfMassShapeTest.cpp

@@ -47,11 +47,9 @@ void ScaledOffsetCenterOfMassShapeTest::Initialize()
 
 
 	// Shape that is scaled before the offset center of mass offset is applied
 	// Shape that is scaled before the offset center of mass offset is applied
 	ShapeRefC pre_scaled = OffsetCenterOfMassShapeSettings(Vec3(0, 0, 5.0f), new ScaledShape(new SphereShape(1.0f), JPH::Vec3::sReplicate(2.0f))).Create().Get();
 	ShapeRefC pre_scaled = OffsetCenterOfMassShapeSettings(Vec3(0, 0, 5.0f), new ScaledShape(new SphereShape(1.0f), JPH::Vec3::sReplicate(2.0f))).Create().Get();
-	Body &body_pre_scaled = *mBodyInterface->CreateBody(BodyCreationSettings(pre_scaled, RVec3(0, 5, -15), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body_pre_scaled.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(pre_scaled, RVec3(0, 5, -15), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Shape that is scaled after the offset center of mass offset is applied
 	// Shape that is scaled after the offset center of mass offset is applied
 	ShapeRefC post_scaled = new ScaledShape(OffsetCenterOfMassShapeSettings(Vec3(0, 0, 5.0f), new SphereShape(1.0f)).Create().Get(), JPH::Vec3::sReplicate(2.0f));
 	ShapeRefC post_scaled = new ScaledShape(OffsetCenterOfMassShapeSettings(Vec3(0, 0, 5.0f), new SphereShape(1.0f)).Create().Get(), JPH::Vec3::sReplicate(2.0f));
-	Body &body_post_scaled = *mBodyInterface->CreateBody(BodyCreationSettings(post_scaled, RVec3(5, 5, -15), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body_post_scaled.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(post_scaled, RVec3(5, 5, -15), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 }
 }

+ 8 - 18
Samples/Tests/ScaledShapes/ScaledPlaneShapeTest.cpp

@@ -25,40 +25,30 @@ void ScaledPlaneShapeTest::Initialize()
 	RefConst<ShapeSettings> plane_shape = new PlaneShapeSettings(Plane(Vec3(0.1f, 1.0f, 0.1f).Normalized(), -0.5f), nullptr, 5.0f);
 	RefConst<ShapeSettings> plane_shape = new PlaneShapeSettings(Plane(Vec3(0.1f, 1.0f, 0.1f).Normalized(), -0.5f), nullptr, 5.0f);
 
 
 	// Original shape
 	// Original shape
-	Body &body1 = *mBodyInterface->CreateBody(BodyCreationSettings(plane_shape, RVec3(-60, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body1.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(plane_shape, RVec3(-60, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Uniformly scaled shape < 1
 	// Uniformly scaled shape < 1
-	Body &body2 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(plane_shape, Vec3::sReplicate(0.5f)), RVec3(-40, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body2.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(plane_shape, Vec3::sReplicate(0.5f)), RVec3(-40, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Uniformly scaled shape > 1
 	// Uniformly scaled shape > 1
-	Body &body3 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(plane_shape, Vec3::sReplicate(1.5f)), RVec3(-20, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body3.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(plane_shape, Vec3::sReplicate(1.5f)), RVec3(-20, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Non-uniform scaled shape
 	// Non-uniform scaled shape
-	Body &body4 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(plane_shape, Vec3(0.5f, 1.0f, 1.5f)), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body4.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(plane_shape, Vec3(0.5f, 1.0f, 1.5f)), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Flipped in 2 axis
 	// Flipped in 2 axis
-	Body &body5 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(plane_shape, Vec3(-0.5f, 1.0f, -1.5f)), RVec3(20, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body5.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(plane_shape, Vec3(-0.5f, 1.0f, -1.5f)), RVec3(20, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Inside out
 	// Inside out
-	Body &body6 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(plane_shape, Vec3(-0.5f, 1.0f, 1.5f)), RVec3(40, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body6.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(plane_shape, Vec3(-0.5f, 1.0f, 1.5f)), RVec3(40, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Upside down
 	// Upside down
-	Body &body7 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(plane_shape, Vec3(0.5f, -1.0f, 1.5f)), RVec3(60, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body7.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(plane_shape, Vec3(0.5f, -1.0f, 1.5f)), RVec3(60, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Create a number of balls above the planes
 	// Create a number of balls above the planes
 	RefConst<Shape> sphere_shape = new SphereShape(0.2f);
 	RefConst<Shape> sphere_shape = new SphereShape(0.2f);
 	RefConst<Shape> box_shape = new BoxShape(Vec3(0.2f, 0.2f, 0.4f), 0.01f);
 	RefConst<Shape> box_shape = new BoxShape(Vec3(0.2f, 0.2f, 0.4f), 0.01f);
 	for (int i = 0; i < 7; ++i)
 	for (int i = 0; i < 7; ++i)
 		for (int j = 0; j < 5; ++j)
 		for (int j = 0; j < 5; ++j)
-		{
-			Body &dynamic = *mBodyInterface->CreateBody(BodyCreationSettings((j & 1)? box_shape : sphere_shape, RVec3(-60.0f + 20.0f * i, 15.0f + 0.5f * j, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-			mBodyInterface->AddBody(dynamic.GetID(), EActivation::Activate);
-		}
+			mBodyInterface->CreateAndAddBody(BodyCreationSettings((j & 1)? box_shape : sphere_shape, RVec3(-60.0f + 20.0f * i, 15.0f + 0.5f * j, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 }
 }

+ 5 - 10
Samples/Tests/ScaledShapes/ScaledSphereShapeTest.cpp

@@ -24,22 +24,17 @@ void ScaledSphereShapeTest::Initialize()
 	RefConst<SphereShape> sphere_shape = new SphereShape(2.0f);
 	RefConst<SphereShape> sphere_shape = new SphereShape(2.0f);
 
 
 	// Original shape
 	// Original shape
-	Body &body1 = *mBodyInterface->CreateBody(BodyCreationSettings(sphere_shape, RVec3(-20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body1.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(sphere_shape, RVec3(-20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Uniformly scaled shape < 1
 	// Uniformly scaled shape < 1
-	Body &body2 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShape(sphere_shape, Vec3::sReplicate(0.25f)), RVec3(-10, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body2.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShape(sphere_shape, Vec3::sReplicate(0.25f)), RVec3(-10, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Uniformly scaled shape > 1
 	// Uniformly scaled shape > 1
-	Body &body3 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShape(sphere_shape, Vec3::sReplicate(2.0f)), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body3.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShape(sphere_shape, Vec3::sReplicate(2.0f)), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Flipped in 2 axis
 	// Flipped in 2 axis
-	Body &body4 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShape(sphere_shape, Vec3(-0.25f, 0.25f, -0.25f)), RVec3(10, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body4.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShape(sphere_shape, Vec3(-0.25f, 0.25f, -0.25f)), RVec3(10, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Inside out
 	// Inside out
-	Body &body5 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShape(sphere_shape, Vec3::sReplicate(-0.25f)), RVec3(20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body5.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShape(sphere_shape, Vec3::sReplicate(-0.25f)), RVec3(20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 }
 }

+ 5 - 10
Samples/Tests/ScaledShapes/ScaledStaticCompoundShapeTest.cpp

@@ -64,22 +64,17 @@ void ScaledStaticCompoundShapeTest::Initialize()
 	compound_shape->AddShape(Vec3(-5, -0.5f, -0.5f), Quat::sIdentity(), center_shape);
 	compound_shape->AddShape(Vec3(-5, -0.5f, -0.5f), Quat::sIdentity(), center_shape);
 
 
 	// Original shape
 	// Original shape
-	Body &body1 = *mBodyInterface->CreateBody(BodyCreationSettings(compound_shape, RVec3(-40, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body1.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(compound_shape, RVec3(-40, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Uniformly scaled shape
 	// Uniformly scaled shape
-	Body &body2 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(compound_shape, Vec3::sReplicate(0.25f)), RVec3(-20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body2.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(compound_shape, Vec3::sReplicate(0.25f)), RVec3(-20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Non-uniform scaled shape
 	// Non-uniform scaled shape
-	Body &body3 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(compound_shape, Vec3(0.25f, 0.5f, 1.5f)), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body3.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(compound_shape, Vec3(0.25f, 0.5f, 1.5f)), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Flipped in 2 axis
 	// Flipped in 2 axis
-	Body &body4 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(compound_shape, Vec3(-0.25f, 0.5f, -1.5f)), RVec3(20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body4.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(compound_shape, Vec3(-0.25f, 0.5f, -1.5f)), RVec3(20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Inside out
 	// Inside out
-	Body &body5 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(compound_shape, Vec3(-0.25f, 0.5f, 1.5f)), RVec3(40, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body5.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(compound_shape, Vec3(-0.25f, 0.5f, 1.5f)), RVec3(40, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 }
 }

+ 5 - 10
Samples/Tests/ScaledShapes/ScaledTaperedCapsuleShapeTest.cpp

@@ -24,22 +24,17 @@ void ScaledTaperedCapsuleShapeTest::Initialize()
 	RefConst<ShapeSettings> tapered_capsule_shape = new TaperedCapsuleShapeSettings(2.0f, 0.75f, 1.25f);
 	RefConst<ShapeSettings> tapered_capsule_shape = new TaperedCapsuleShapeSettings(2.0f, 0.75f, 1.25f);
 
 
 	// Original shape
 	// Original shape
-	Body &body1 = *mBodyInterface->CreateBody(BodyCreationSettings(tapered_capsule_shape, RVec3(-20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body1.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(tapered_capsule_shape, RVec3(-20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Uniformly scaled shape < 1
 	// Uniformly scaled shape < 1
-	Body &body2 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(tapered_capsule_shape, Vec3::sReplicate(0.25f)), RVec3(-10, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body2.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(tapered_capsule_shape, Vec3::sReplicate(0.25f)), RVec3(-10, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Uniformly scaled shape > 1
 	// Uniformly scaled shape > 1
-	Body &body3 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(tapered_capsule_shape, Vec3::sReplicate(2.0f)), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body3.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(tapered_capsule_shape, Vec3::sReplicate(2.0f)), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Flipped in 2 axis
 	// Flipped in 2 axis
-	Body &body4 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(tapered_capsule_shape, Vec3(-1.5f, -1.5f, 1.5f)), RVec3(10, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body4.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(tapered_capsule_shape, Vec3(-1.5f, -1.5f, 1.5f)), RVec3(10, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Inside out
 	// Inside out
-	Body &body5 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(tapered_capsule_shape, Vec3::sReplicate(-0.75f)), RVec3(20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body5.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(tapered_capsule_shape, Vec3::sReplicate(-0.75f)), RVec3(20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 }
 }

+ 8 - 18
Samples/Tests/ScaledShapes/ScaledTriangleShapeTest.cpp

@@ -26,40 +26,30 @@ void ScaledTriangleShapeTest::Initialize()
 	RefConst<TriangleShape> triangle_shape = new TriangleShape(Vec3(-10, -1, 0), Vec3(0, 1, 10), Vec3(10, -2, -10));
 	RefConst<TriangleShape> triangle_shape = new TriangleShape(Vec3(-10, -1, 0), Vec3(0, 1, 10), Vec3(10, -2, -10));
 
 
 	// Original shape
 	// Original shape
-	Body &body1 = *mBodyInterface->CreateBody(BodyCreationSettings(triangle_shape, RVec3(-60, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body1.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(triangle_shape, RVec3(-60, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Uniformly scaled shape < 1
 	// Uniformly scaled shape < 1
-	Body &body2 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShape(triangle_shape, Vec3::sReplicate(0.5f)), RVec3(-40, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body2.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShape(triangle_shape, Vec3::sReplicate(0.5f)), RVec3(-40, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Uniformly scaled shape > 1
 	// Uniformly scaled shape > 1
-	Body &body3 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShape(triangle_shape, Vec3::sReplicate(1.5f)), RVec3(-20, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body3.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShape(triangle_shape, Vec3::sReplicate(1.5f)), RVec3(-20, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Non-uniform scaled shape
 	// Non-uniform scaled shape
-	Body &body4 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShape(triangle_shape, Vec3(0.5f, 1.0f, 1.5f)), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body4.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShape(triangle_shape, Vec3(0.5f, 1.0f, 1.5f)), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Flipped in 2 axis
 	// Flipped in 2 axis
-	Body &body5 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShape(triangle_shape, Vec3(-0.5f, 1.0f, -1.5f)), RVec3(20, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body5.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShape(triangle_shape, Vec3(-0.5f, 1.0f, -1.5f)), RVec3(20, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Inside out
 	// Inside out
-	Body &body6 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShape(triangle_shape, Vec3(-0.5f, 1.0f, 1.5f)), RVec3(40, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body6.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShape(triangle_shape, Vec3(-0.5f, 1.0f, 1.5f)), RVec3(40, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Upside down
 	// Upside down
-	Body &body7 = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShape(triangle_shape, Vec3(0.5f, -1.0f, 1.5f)), RVec3(60, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body7.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShape(triangle_shape, Vec3(0.5f, -1.0f, 1.5f)), RVec3(60, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Create a number of balls above the triangles
 	// Create a number of balls above the triangles
 	RefConst<Shape> sphere_shape = new SphereShape(0.2f);
 	RefConst<Shape> sphere_shape = new SphereShape(0.2f);
 	RefConst<Shape> box_shape = new BoxShape(Vec3(0.2f, 0.2f, 0.4f), 0.01f);
 	RefConst<Shape> box_shape = new BoxShape(Vec3(0.2f, 0.2f, 0.4f), 0.01f);
 	for (int i = 0; i < 7; ++i)
 	for (int i = 0; i < 7; ++i)
 		for (int j = 0; j < 5; ++j)
 		for (int j = 0; j < 5; ++j)
-		{
-			Body &dynamic = *mBodyInterface->CreateBody(BodyCreationSettings((j & 1)? box_shape : sphere_shape, RVec3(-60.0f + 20.0f * i, 10.0f + 0.5f * j, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-			mBodyInterface->AddBody(dynamic.GetID(), EActivation::Activate);
-		}
+			mBodyInterface->CreateAndAddBody(BodyCreationSettings((j & 1)? box_shape : sphere_shape, RVec3(-60.0f + 20.0f * i, 10.0f + 0.5f * j, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 }
 }

+ 3 - 6
Samples/Tests/Shapes/BoxShapeTest.cpp

@@ -20,12 +20,9 @@ void BoxShapeTest::Initialize()
 	CreateFloor();
 	CreateFloor();
 
 
 	// Different sized boxes
 	// Different sized boxes
-	Body &body1 = *mBodyInterface->CreateBody(BodyCreationSettings(new BoxShape(Vec3(20, 1, 1)), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body1.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new BoxShape(Vec3(20, 1, 1)), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
-	Body &body2 = *mBodyInterface->CreateBody(BodyCreationSettings(new BoxShape(Vec3(2, 3, 4)), RVec3(0, 10, 10), Quat::sRotation(Vec3::sAxisZ(), 0.25f * JPH_PI), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body2.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new BoxShape(Vec3(2, 3, 4)), RVec3(0, 10, 10), Quat::sRotation(Vec3::sAxisZ(), 0.25f * JPH_PI), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
-	Body &body3 = *mBodyInterface->CreateBody(BodyCreationSettings(new BoxShape(Vec3(0.5f, 0.75f, 1.0f)), RVec3(0, 10, 20), Quat::sRotation(Vec3::sAxisX(), 0.25f * JPH_PI) * Quat::sRotation(Vec3::sAxisZ(), 0.25f * JPH_PI), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body3.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new BoxShape(Vec3(0.5f, 0.75f, 1.0f)), RVec3(0, 10, 20), Quat::sRotation(Vec3::sAxisX(), 0.25f * JPH_PI) * Quat::sRotation(Vec3::sAxisZ(), 0.25f * JPH_PI), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 }
 }

+ 3 - 6
Samples/Tests/Shapes/CapsuleShapeTest.cpp

@@ -22,12 +22,10 @@ void CapsuleShapeTest::Initialize()
 	RefConst<Shape> big_capsule = new CapsuleShape(2.5f, 2);
 	RefConst<Shape> big_capsule = new CapsuleShape(2.5f, 2);
 
 
 	// Capsule on outer sphere
 	// Capsule on outer sphere
-	Body &body1 = *mBodyInterface->CreateBody(BodyCreationSettings(big_capsule, RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body1.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(big_capsule, RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Capsule on cylinder
 	// Capsule on cylinder
-	Body &body2 = *mBodyInterface->CreateBody(BodyCreationSettings(big_capsule, RVec3(10, 10, 0), Quat::sRotation(Vec3::sAxisX(), 0.5f * JPH_PI), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body2.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(big_capsule, RVec3(10, 10, 0), Quat::sRotation(Vec3::sAxisX(), 0.5f * JPH_PI), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	RefConst<Shape> long_capsule = new CapsuleShape(5, 1);
 	RefConst<Shape> long_capsule = new CapsuleShape(5, 1);
 
 
@@ -48,8 +46,7 @@ void CapsuleShapeTest::Initialize()
 				position = RVec3(0, 2.0f + 3.0f * i, -20.0f - 4.0f + 8.0f * j);
 				position = RVec3(0, 2.0f + 3.0f * i, -20.0f - 4.0f + 8.0f * j);
 				rotation = Quat::sRotation(Vec3::sAxisZ(), 0.5f * JPH_PI);
 				rotation = Quat::sRotation(Vec3::sAxisZ(), 0.5f * JPH_PI);
 			}
 			}
-			Body &body = *mBodyInterface->CreateBody(BodyCreationSettings(long_capsule, position, rotation, EMotionType::Dynamic, Layers::MOVING));
-			mBodyInterface->AddBody(body.GetID(), EActivation::Activate);
+			mBodyInterface->CreateAndAddBody(BodyCreationSettings(long_capsule, position, rotation, EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 		}
 		}
 	}
 	}
 }
 }

+ 7 - 14
Samples/Tests/Shapes/ConvexHullShapeTest.cpp

@@ -26,8 +26,7 @@ void ConvexHullShapeTest::Initialize()
 	tetrahedron.push_back(Vec3(5, 0, -5));
 	tetrahedron.push_back(Vec3(5, 0, -5));
 	tetrahedron.push_back(Vec3(0, -5, 0));
 	tetrahedron.push_back(Vec3(0, -5, 0));
 
 
-	Body &body_tetrahedron = *mBodyInterface->CreateBody(BodyCreationSettings(new ConvexHullShapeSettings(tetrahedron), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body_tetrahedron.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ConvexHullShapeSettings(tetrahedron), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Create box
 	// Create box
 	Array<Vec3> box;
 	Array<Vec3> box;
@@ -40,8 +39,7 @@ void ConvexHullShapeTest::Initialize()
 	box.push_back(Vec3(5, -5, -5));
 	box.push_back(Vec3(5, -5, -5));
 	box.push_back(Vec3(-5, -5, -5));
 	box.push_back(Vec3(-5, -5, -5));
 
 
-	Body &body_box = *mBodyInterface->CreateBody(BodyCreationSettings(new ConvexHullShapeSettings(box), RVec3(20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body_box.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ConvexHullShapeSettings(box), RVec3(20, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Add a sphere of many points
 	// Add a sphere of many points
 	Array<Vec3> sphere;
 	Array<Vec3> sphere;
@@ -49,8 +47,7 @@ void ConvexHullShapeTest::Initialize()
 		for (float phi = 0.0f; phi <= 2.0f * JPH_PI; phi += 2.0f * JPH_PI / 20.0f)
 		for (float phi = 0.0f; phi <= 2.0f * JPH_PI; phi += 2.0f * JPH_PI / 20.0f)
 			sphere.push_back(5.0f * Vec3::sUnitSpherical(theta, phi));
 			sphere.push_back(5.0f * Vec3::sUnitSpherical(theta, phi));
 
 
-	Body &body_sphere = *mBodyInterface->CreateBody(BodyCreationSettings(new ConvexHullShapeSettings(sphere), RVec3(40, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body_sphere.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ConvexHullShapeSettings(sphere), RVec3(40, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Add a tapered cylinder of many points
 	// Add a tapered cylinder of many points
 	Array<Vec3> tapered_cylinder;
 	Array<Vec3> tapered_cylinder;
@@ -60,8 +57,7 @@ void ConvexHullShapeTest::Initialize()
 		tapered_cylinder.push_back(4.5f * Vec3(0.1f, Sin(theta), Cos(theta)));
 		tapered_cylinder.push_back(4.5f * Vec3(0.1f, Sin(theta), Cos(theta)));
 	}
 	}
 
 
-	Body &body_tapered_cylinder = *mBodyInterface->CreateBody(BodyCreationSettings(new ConvexHullShapeSettings(tapered_cylinder), RVec3(60, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body_tapered_cylinder.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ConvexHullShapeSettings(tapered_cylinder), RVec3(60, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Create convex hull with on one side nearly coplanar faces
 	// Create convex hull with on one side nearly coplanar faces
 	Array<Vec3> coplanar;
 	Array<Vec3> coplanar;
@@ -86,8 +82,7 @@ void ConvexHullShapeTest::Initialize()
 	coplanar.push_back(Vec3(2.74527335f, 3.06491613f, 1.77647924f));
 	coplanar.push_back(Vec3(2.74527335f, 3.06491613f, 1.77647924f));
 	coplanar.push_back(Vec3(-1.53122997f, -2.18120861f, 2.31516361f));
 	coplanar.push_back(Vec3(-1.53122997f, -2.18120861f, 2.31516361f));
 
 
-	Body &body_coplanar = *mBodyInterface->CreateBody(BodyCreationSettings(new ConvexHullShapeSettings(coplanar), RVec3(80, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body_coplanar.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ConvexHullShapeSettings(coplanar), RVec3(80, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Bodies with random convex shapes
 	// Bodies with random convex shapes
 	default_random_engine random;
 	default_random_engine random;
@@ -99,8 +94,7 @@ void ConvexHullShapeTest::Initialize()
 		for (int j = 0; j < 20; ++j)
 		for (int j = 0; j < 20; ++j)
 			points.push_back(hull_size(random) * Vec3::sRandom(random));
 			points.push_back(hull_size(random) * Vec3::sRandom(random));
 
 
-		Body &body = *mBodyInterface->CreateBody(BodyCreationSettings(new ConvexHullShapeSettings(points), RVec3(-90.0f + i * 18.0f, 10, 20), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-		mBodyInterface->AddBody(body.GetID(), EActivation::Activate);
+		mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ConvexHullShapeSettings(points), RVec3(-90.0f + i * 18.0f, 10, 20), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 	}
 	}
 
 
 	// Bodies with random convex polygons (this is not something you should be doing, but this tests the 2D convex hull shape generation and allows you to test the probe against them)
 	// Bodies with random convex polygons (this is not something you should be doing, but this tests the 2D convex hull shape generation and allows you to test the probe against them)
@@ -125,7 +119,6 @@ void ConvexHullShapeTest::Initialize()
 		creation_settings.mMassPropertiesOverride.mMass = 1.0f;
 		creation_settings.mMassPropertiesOverride.mMass = 1.0f;
 		creation_settings.mMassPropertiesOverride.mInertia = Mat44::sIdentity();
 		creation_settings.mMassPropertiesOverride.mInertia = Mat44::sIdentity();
 
 
-		Body &body = *mBodyInterface->CreateBody(creation_settings);
-		mBodyInterface->AddBody(body.GetID(), EActivation::Activate);
+		mBodyInterface->CreateAndAddBody(creation_settings, EActivation::Activate);
 	}
 	}
 }
 }

+ 2 - 4
Samples/Tests/Shapes/HeightFieldShapeTest.cpp

@@ -138,8 +138,7 @@ void HeightFieldShapeTest::Initialize()
 	settings.mBlockSize = 1 << sBlockSizeShift;
 	settings.mBlockSize = 1 << sBlockSizeShift;
 	settings.mBitsPerSample = sBitsPerSample;
 	settings.mBitsPerSample = sBitsPerSample;
 	mHeightField = StaticCast<HeightFieldShape>(settings.Create().Get());
 	mHeightField = StaticCast<HeightFieldShape>(settings.Create().Get());
-	Body &terrain = *mBodyInterface->CreateBody(BodyCreationSettings(mHeightField, RVec3::sZero(), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(terrain.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(mHeightField, RVec3::sZero(), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Validate it
 	// Validate it
 	float max_diff = -1.0f;
 	float max_diff = -1.0f;
@@ -199,8 +198,7 @@ void HeightFieldShapeTest::Initialize()
 		mHitPos = ray.GetPointOnRay(result.mFraction);
 		mHitPos = ray.GetPointOnRay(result.mFraction);
 
 
 	// Dynamic body
 	// Dynamic body
-	Body &body1 = *mBodyInterface->CreateBody(BodyCreationSettings(new BoxShape(Vec3(0.5f, 1.0f, 2.0f)), mHitPos + Vec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body1.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new BoxShape(Vec3(0.5f, 1.0f, 2.0f)), mHitPos + Vec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 }
 }
 
 
 void HeightFieldShapeTest::PrePhysicsUpdate(const PreUpdateParams &inParams)
 void HeightFieldShapeTest::PrePhysicsUpdate(const PreUpdateParams &inParams)

+ 1 - 2
Samples/Tests/Shapes/MeshShapeTest.cpp

@@ -47,8 +47,7 @@ void MeshShapeTest::Initialize()
 		materials.push_back(new PhysicsMaterialSimple("Material " + ConvertToString(i), Color::sGetDistinctColor(i)));
 		materials.push_back(new PhysicsMaterialSimple("Material " + ConvertToString(i), Color::sGetDistinctColor(i)));
 
 
 	// Floor
 	// Floor
-	Body &floor = *mBodyInterface->CreateBody(BodyCreationSettings(new MeshShapeSettings(triangles, std::move(materials)), RVec3::sZero(), Quat::sRotation(Vec3::sAxisX(), 0.25f * JPH_PI), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(floor.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new MeshShapeSettings(triangles, std::move(materials)), RVec3::sZero(), Quat::sRotation(Vec3::sAxisX(), 0.25f * JPH_PI), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// 1 body with zero friction to test active edge detection
 	// 1 body with zero friction to test active edge detection
 	Ref<BoxShape> box_shape = new BoxShape(Vec3(2.0f, 2.0f, 2.0f), cDefaultConvexRadius, new PhysicsMaterialSimple("Box Material", Color::sYellow));
 	Ref<BoxShape> box_shape = new BoxShape(Vec3(2.0f, 2.0f, 2.0f), cDefaultConvexRadius, new PhysicsMaterialSimple("Box Material", Color::sYellow));

+ 3 - 5
Samples/Tests/Shapes/MutableCompoundShapeTest.cpp

@@ -22,8 +22,7 @@ JPH_IMPLEMENT_RTTI_VIRTUAL(MutableCompoundShapeTest)
 void MutableCompoundShapeTest::Initialize()
 void MutableCompoundShapeTest::Initialize()
 {
 {
 	// Floor (extra thick because we can randomly add sub shapes that then may stick out underneath the floor and cause objects to be pushed through)
 	// Floor (extra thick because we can randomly add sub shapes that then may stick out underneath the floor and cause objects to be pushed through)
-	Body &floor = *mBodyInterface->CreateBody(BodyCreationSettings(new BoxShape(Vec3(100.0f, 10.0f, 100.0f), 0.0f), RVec3(0.0f, -10.0f, 0.0f), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(floor.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new BoxShape(Vec3(100.0f, 10.0f, 100.0f), 0.0f), RVec3(0.0f, -10.0f, 0.0f), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Compound with sub compound and rotation
 	// Compound with sub compound and rotation
 	StaticCompoundShapeSettings sub_compound_settings;
 	StaticCompoundShapeSettings sub_compound_settings;
@@ -40,9 +39,8 @@ void MutableCompoundShapeTest::Initialize()
 		compound_shape->AddShape(Vec3::sZero(), Quat::sRotation(Vec3::sAxisX(), 0.25f * JPH_PI) * Quat::sRotation(Vec3::sAxisZ(), -0.75f * JPH_PI), mSubCompound);
 		compound_shape->AddShape(Vec3::sZero(), Quat::sRotation(Vec3::sAxisX(), 0.25f * JPH_PI) * Quat::sRotation(Vec3::sAxisZ(), -0.75f * JPH_PI), mSubCompound);
 
 
 		// Create a body
 		// Create a body
-		Body &body = *mBodyInterface->CreateBody(BodyCreationSettings(compound_shape, RVec3(0, 10.0f + 5.0f * i, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-		mBodyInterface->AddBody(body.GetID(), EActivation::Activate);
-		mBodyIDs.push_back(body.GetID());
+		BodyID body_id = mBodyInterface->CreateAndAddBody(BodyCreationSettings(compound_shape, RVec3(0, 10.0f + 5.0f * i, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
+		mBodyIDs.push_back(body_id);
 	}
 	}
 }
 }
 
 

+ 1 - 2
Samples/Tests/Shapes/RotatedTranslatedShapeTest.cpp

@@ -31,6 +31,5 @@ void RotatedTranslatedShapeTest::Initialize()
 	Ref<RotatedTranslatedShapeSettings> rot_trans = new RotatedTranslatedShapeSettings(Vec3(0, 2.5f, 0), Quat::sRotation(Vec3::sAxisX(), JPH_PI), convex_hull);
 	Ref<RotatedTranslatedShapeSettings> rot_trans = new RotatedTranslatedShapeSettings(Vec3(0, 2.5f, 0), Quat::sRotation(Vec3::sAxisX(), JPH_PI), convex_hull);
 
 
 	// Place at 0 so that the point touches the floor
 	// Place at 0 so that the point touches the floor
-	Body &body = *mBodyInterface->CreateBody(BodyCreationSettings(rot_trans, RVec3::sZero(), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(rot_trans, RVec3::sZero(), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 }
 }

+ 4 - 10
Samples/Tests/Shapes/SphereShapeTest.cpp

@@ -20,19 +20,13 @@ void SphereShapeTest::Initialize()
 	CreateFloor();
 	CreateFloor();
 
 
 	// Create different sized spheres
 	// Create different sized spheres
-	Body &body1 = *mBodyInterface->CreateBody(BodyCreationSettings(new SphereShape(1.0f), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body1.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new SphereShape(1.0f), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
-	Body &body2 = *mBodyInterface->CreateBody(BodyCreationSettings(new SphereShape(2.0f), RVec3(0, 10, 10), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body2.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new SphereShape(2.0f), RVec3(0, 10, 10), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
-	Body &body3 = *mBodyInterface->CreateBody(BodyCreationSettings(new SphereShape(0.5f), RVec3(0, 10, 20), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body3.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(new SphereShape(0.5f), RVec3(0, 10, 20), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Tower of spheres
 	// Tower of spheres
 	for (int i = 0; i < 10; ++i)
 	for (int i = 0; i < 10; ++i)
-	{
-		Body &body = *mBodyInterface->CreateBody(BodyCreationSettings(new SphereShape(0.5f), RVec3(10, 10 + 1.5f * i, 0), Quat::sRotation(Vec3::sAxisZ(), 0.25f * JPH_PI), EMotionType::Dynamic, Layers::MOVING));
-		mBodyInterface->AddBody(body.GetID(), EActivation::Activate);
-	}
+		mBodyInterface->CreateAndAddBody(BodyCreationSettings(new SphereShape(0.5f), RVec3(10, 10 + 1.5f * i, 0), Quat::sRotation(Vec3::sAxisZ(), 0.25f * JPH_PI), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 }
 }

+ 1 - 2
Samples/Tests/Shapes/StaticCompoundShapeTest.cpp

@@ -57,7 +57,6 @@ void StaticCompoundShapeTest::Initialize()
 				rotation = Quat::sRotation(Vec3::sAxisX(), 0.5f * JPH_PI);
 				rotation = Quat::sRotation(Vec3::sAxisX(), 0.5f * JPH_PI);
 			else
 			else
 				rotation = Quat::sRotation(Vec3::sAxisZ(), 0.5f * JPH_PI);
 				rotation = Quat::sRotation(Vec3::sAxisZ(), 0.5f * JPH_PI);
-			Body &body = *mBodyInterface->CreateBody(BodyCreationSettings(shapes[j], RVec3(0, 10.0f + 4.0f * i, j * 20.0f), rotation, EMotionType::Dynamic, Layers::MOVING));
-			mBodyInterface->AddBody(body.GetID(), EActivation::Activate);
+			mBodyInterface->CreateAndAddBody(BodyCreationSettings(shapes[j], RVec3(0, 10.0f + 4.0f * i, j * 20.0f), rotation, EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 		}
 		}
 }
 }

+ 4 - 8
Samples/Tests/Shapes/TaperedCapsuleShapeTest.cpp

@@ -23,16 +23,13 @@ void TaperedCapsuleShapeTest::Initialize()
 	RefConst<ShapeSettings> big_taperedcapsule2 = new TaperedCapsuleShapeSettings(2.0f, 3.0f, 1.0f);
 	RefConst<ShapeSettings> big_taperedcapsule2 = new TaperedCapsuleShapeSettings(2.0f, 3.0f, 1.0f);
 
 
 	// Tapered capsule on outer sphere
 	// Tapered capsule on outer sphere
-	Body &body1 = *mBodyInterface->CreateBody(BodyCreationSettings(big_taperedcapsule, RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body1.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(big_taperedcapsule, RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Tapered capsule on other outer sphere
 	// Tapered capsule on other outer sphere
-	Body &body2 = *mBodyInterface->CreateBody(BodyCreationSettings(big_taperedcapsule2, RVec3(10, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body2.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(big_taperedcapsule2, RVec3(10, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	// Tapered capsule on side
 	// Tapered capsule on side
-	Body &body3 = *mBodyInterface->CreateBody(BodyCreationSettings(big_taperedcapsule, RVec3(20, 10, 0), Quat::sRotation(Vec3::sAxisX(), 0.5f * JPH_PI), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(body3.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(big_taperedcapsule, RVec3(20, 10, 0), Quat::sRotation(Vec3::sAxisX(), 0.5f * JPH_PI), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 
 
 	RefConst<ShapeSettings> long_taperedcapsule = new TaperedCapsuleShapeSettings(5, 0.5f, 1.0f);
 	RefConst<ShapeSettings> long_taperedcapsule = new TaperedCapsuleShapeSettings(5, 0.5f, 1.0f);
 
 
@@ -53,8 +50,7 @@ void TaperedCapsuleShapeTest::Initialize()
 				position = RVec3(0, 2.0f + 3.0f * i, -20.0f - 4.0f + 8.0f * j);
 				position = RVec3(0, 2.0f + 3.0f * i, -20.0f - 4.0f + 8.0f * j);
 				rotation = Quat::sRotation(Vec3::sAxisZ(), 0.5f * JPH_PI + (j & 1) * JPH_PI);
 				rotation = Quat::sRotation(Vec3::sAxisZ(), 0.5f * JPH_PI + (j & 1) * JPH_PI);
 			}
 			}
-			Body &body = *mBodyInterface->CreateBody(BodyCreationSettings(long_taperedcapsule, position, rotation, EMotionType::Dynamic, Layers::MOVING));
-			mBodyInterface->AddBody(body.GetID(), EActivation::Activate);
+			mBodyInterface->CreateAndAddBody(BodyCreationSettings(long_taperedcapsule, position, rotation, EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 		}
 		}
 	}
 	}
 }
 }

+ 2 - 4
Samples/Tests/Shapes/TriangleShapeTest.cpp

@@ -19,11 +19,9 @@ void TriangleShapeTest::Initialize()
 {
 {
 	// Single triangle
 	// Single triangle
 	RefConst<TriangleShape> triangle_shape = new TriangleShape(Vec3(-10, -1, 0), Vec3(0, 1, 10), Vec3(10, -2, -10), 0.01f);
 	RefConst<TriangleShape> triangle_shape = new TriangleShape(Vec3(-10, -1, 0), Vec3(0, 1, 10), Vec3(10, -2, -10), 0.01f);
-	Body &body1 = *mBodyInterface->CreateBody(BodyCreationSettings(triangle_shape, RVec3::sZero(), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING));
-	mBodyInterface->AddBody(body1.GetID(), EActivation::DontActivate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(triangle_shape, RVec3::sZero(), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
 
 
 	// Create a box above the triangle
 	// Create a box above the triangle
 	RefConst<Shape> box_shape = new BoxShape(Vec3(0.2f, 0.2f, 0.4f), 0.01f);
 	RefConst<Shape> box_shape = new BoxShape(Vec3(0.2f, 0.2f, 0.4f), 0.01f);
-	Body &dynamic = *mBodyInterface->CreateBody(BodyCreationSettings(box_shape, RVec3(0, 5, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
-	mBodyInterface->AddBody(dynamic.GetID(), EActivation::Activate);
+	mBodyInterface->CreateAndAddBody(BodyCreationSettings(box_shape, RVec3(0, 5, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
 }
 }