⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testsims.cpp

📁 赫赫大名的 OGRE 游戏引擎
💻 CPP
📖 第 1 页 / 共 3 页
字号:

	// Add a few Elements to the complex
	box = complex2->addCubicElement("box1",
									String::BLANK,
									String::BLANK,
									Vector3(-50.0f, 75.0f, 0.0f),
									Quaternion::IDENTITY,
									String::BLANK,
									Vector3(50.0f, 150.0f, 50.0f),
									true);
	box->setBreakageType(neGeometry::NE_BREAK_DISABLE);
	box = complex2->addCubicElement("box2",
									String::BLANK,
									String::BLANK,
									Vector3(0.0f, 125.0f, 0.0f),
									Quaternion::IDENTITY,
									String::BLANK,
									Vector3(50.0f, 50.0f, 50.0f),
									true);
	box->setBreakageType(neGeometry::NE_BREAK_NORMAL);
	box->setBreakageMagnitude(1.0f);
	box->setBreakageMass(25.0f);
	box->setBreakageCubicInertiaTensor(50.0f, 50.0f, 50.0f, 25.0f);
*/

	// Create the bullet
	bullet = Simulation::getSingleton().createDynamicSphere("bullet",
															String::BLANK,
															String::BLANK,
															Vector3(1000.0f, 25.0f, 1000.0f),
															Quaternion::IDENTITY,
															String::BLANK,
															50.0f,
															25.0,
															true);
	
	// Prevent the bullet from rolling forever
	bullet->setAngularDamping(0.0025f);	

	// Return the bullet
	return bullet;
}

// setupTestSim8
DynamicSphere* setupTestSim8(SceneNode* rootNode)
{
	// Test sims will return a bullet object for interactivity
	DynamicSphere* bullet;

	// Simulation already running
	if(Simulation::getSingleton().isInitialised())
	{
		// Shutdown the Simulation (clears all existing objects)
		Simulation::getSingleton().shutdown();
	}

	// Initalise the Simulation
	Simulation::getSingleton().initialise(rootNode,
											OGRETOK_DEFAULT_STEPS_PER_SECOND,
											Vector3(0.0f, -490.0f, 0.0f),
											5,
											150,
											0,
											1);

	// Create the ground
	Simulation::getSingleton().createStaticBox("ground",
												String::BLANK,
												String::BLANK,
												Vector3(0.0f, -2.5f, 0.0f),
												Quaternion::IDENTITY,
												String::BLANK,
												Vector3(2500.0f, 5.0f, 2500.0f),
												true);

	// Create a new surface for the blocks
	Simulation::getSingleton().createSurface("slipperyBrick", 0.1f, 0.0f);
	
	// Row sizes
	const unsigned int numXRows = 5;
	const unsigned int numZRows = 5;
	const unsigned int numYRows = 5;

	// Loop through X rows
	for(unsigned int x = 0; x < numXRows; x++)
	{
		// Loop through Z rows
		for(unsigned int z = 0; z < numZRows; z++)
		{
			// Loop through Y rows (stacks)
			for(unsigned int y = 0; y < numYRows; y++)
			{
				// Create a box
				Simulation::getSingleton().createDynamicBox("box_" +
															StringConverter::toString(x) + "_" +
															StringConverter::toString(z) + "_" +
															StringConverter::toString(y),
															String::BLANK,
															String::BLANK,
															Vector3((x * 50.0f * 2.0f) - (numXRows / 2 * 50.0f * 2.0f), (y * 50.0f) + 25.0f, (z * 50.0f * 2.0f) - (numZRows / 2 * 50.0f * 2.0f)),
															Quaternion::IDENTITY,
															"slipperyBrick",
															Vector3(50.0f, 50.0f, 50.0f),
															25.0f,
															true);
			}
		}
	}

	// Create the bullet (with exceptional mass)
	bullet = Simulation::getSingleton().createDynamicSphere("bullet",
															String::BLANK,
															String::BLANK,
															Vector3(1000.0f, 25.0f, 1000.0f),
															Quaternion::IDENTITY,
															String::BLANK,
															50.0f,
															1000.0f,
															true);
	
	// Prevent the bullet from rolling forever
	bullet->setAngularDamping(0.0025f);	

	// Return the bullet
	return bullet;
}

// setupTestSim9
DynamicSphere* setupTestSim9(SceneNode* rootNode)
{
	// Test sims will return a bullet object for interactivity
	DynamicSphere* bullet;

	// Simulation already running
	if(Simulation::getSingleton().isInitialised())
	{
		// Shutdown the Simulation (clears all existing objects)
		Simulation::getSingleton().shutdown();
	}

	// Initalise the Simulation
	Simulation::getSingleton().initialise(rootNode,
											OGRETOK_DEFAULT_STEPS_PER_SECOND,
											Vector3(0.0f, -490.0f, 0.0f),
											10,
											30,
											0,
											0);

	// Create a new surface for the scaley terrain
	Simulation::getSingleton().createSurface("scaley", 0.1f, 0.5f);
	Simulation::getSingleton().createSurface("rocky", 0.7f, 0.2f);

	// Manually load the terrain mesh without the WRITE_ONLY flag, for direct access
	MeshManager::getSingleton().load("terrain.mesh", HardwareBuffer::HBU_STATIC, HardwareBuffer::HBU_STATIC, false, false);
	
	// Rotate one of the TriMeshes
	Matrix3 angleMat;
	angleMat.FromEulerAnglesXYZ(0.0f, PI/4, 0.0f);
	Quaternion angleQuat;
	angleQuat.FromRotationMatrix(angleMat);

	// Create the TriMeshes
	Simulation::getSingleton().createTriMesh("terrain",
												"terrain.mesh",
												"Demo/Scales",
												Vector3(500.0f, -500.0f, 0.0f),
												Quaternion::IDENTITY,
												"scaley");
	Simulation::getSingleton().createTriMesh("terrain2",												
												"terrain.mesh",
												"Demo/Rocky",
												Vector3(-400.0f, -750.0f, -200.0f),
												angleQuat,
												"rocky");
	
	// Create a few extra obstacles
	Simulation::getSingleton().createStaticBox("obstacle1",
												String::BLANK,
												String::BLANK,
												Vector3(-250.0f, -500.0f, -250.0f),
												Quaternion::IDENTITY,
												String::BLANK,
												Vector3(100.0f, 500.0f, 100.0f),
												true);
	Simulation::getSingleton().createStaticBox("obstacle2",
												String::BLANK,
												String::BLANK,
												Vector3(-250.0f, -500.0f, 250.0f),
												Quaternion::IDENTITY,
												String::BLANK,
												Vector3(100.0f, 500.0f, 100.0f),
												true);
	Simulation::getSingleton().createStaticBox("obstacle3",
												String::BLANK,
												String::BLANK,
												Vector3(250.0f, -500.0f, 250.0f),
												Quaternion::IDENTITY,
												String::BLANK,
												Vector3(100.0f, 500.0f, 100.0f),
												true);
	Simulation::getSingleton().createStaticBox("obstacle4",
												String::BLANK,
												String::BLANK,
												Vector3(250.0f, -500.0f, -250.0f),
												Quaternion::IDENTITY,
												String::BLANK,
												Vector3(100.0f, 500.0f, 100.0f),
												true);
	Simulation::getSingleton().createStaticBox("obstacle5",
												String::BLANK,
												String::BLANK,
												Vector3(0.0f, -500.0f, 0.0f),
												Quaternion::IDENTITY,
												String::BLANK,
												Vector3(100.0f, 500.0f, 100.0f),
												true);

	// Row sizes
	const unsigned int numXRows = 5;
	const unsigned int numZRows = 5;
	const unsigned int numYRows = 1;

	// Total number of objects created
	unsigned int totalCount = 0;

	// The object being created
	DynamicObject* temp;

	// Loop through X rows
	for(unsigned int x = 0; x < numXRows; x++)
	{
		// Loop through Z rows
		for(unsigned int z = 0; z < numZRows; z++)
		{
			// Loop through Y rows (stacks)
			for(unsigned int y = 0; y < numYRows; y++)
			{
				// First object is a box
				if(totalCount % 3 == 0)
				{
					// Create a box
					temp = Simulation::getSingleton().createDynamicBox("box_" +
																		StringConverter::toString(x) + "_" +
																		StringConverter::toString(z) + "_" +
																		StringConverter::toString(y),
																		String::BLANK,
																		String::BLANK,
																		Vector3((x * 50.0f * 2.0f) - (numXRows / 2 * 50.0f * 2.0f), (y * 50.0f) + 25.0f, (z * 50.0f * 2.0f) - (numZRows / 2 * 50.0f * 2.0f)),
																		Quaternion::IDENTITY,
																		String::BLANK,
																		Vector3(50.0f, 50.0f, 50.0f),
																		25.0f,
																		true);
				}
				// Second object is a sphere
				else if(totalCount % 3 == 1)
				{
					// Create a box
					temp = Simulation::getSingleton().createDynamicSphere("sphere_" +
																			StringConverter::toString(x) + "_" +
																			StringConverter::toString(z) + "_" +
																			StringConverter::toString(y),
																			String::BLANK,
																			String::BLANK,
																			Vector3((x * 50.0f * 2.0f) - (numXRows / 2 * 50.0f * 2.0f), (y * 50.0f) + 25.0f, (z * 50.0f * 2.0f) - (numZRows / 2 * 50.0f * 2.0f)),
																			Quaternion::IDENTITY,
																			String::BLANK,
																			50.0f,
																			25.0f,
																			true);
				}
				// Third object is a cylinder
				else if(totalCount % 3 == 2)
				{
					// Create a box
					temp = Simulation::getSingleton().createDynamicCapsule("cylinder_" +
																			StringConverter::toString(x) + "_" +
																			StringConverter::toString(z) + "_" +
																			StringConverter::toString(y),
																			String::BLANK,
																			String::BLANK,
																			Vector3((x * 50.0f * 2.0f) - (numXRows / 2 * 50.0f * 2.0f), (y * 150.0f) + 25.0f, (z * 50.0f * 2.0f) - (numZRows / 2 * 50.0f * 2.0f)),
																			Quaternion::IDENTITY,
																			String::BLANK,
																			50.0f, 100.0f,
																			25.0f,
																			true);
				}

				// Apply some damping (so the objects will come to a complete stop)
				temp->setAngularDamping(0.0025f);
				temp->setLinearDamping(0.0025f);

				// Total number of objects created
				totalCount++;
			}
		}
	}

	// Create the bullet
	bullet = Simulation::getSingleton().createDynamicSphere("bullet",
															String::BLANK,
															String::BLANK,
															Vector3(1000.0f, 25.0f, 1000.0f),
															Quaternion::IDENTITY,
															String::BLANK,
															50.0f,
															25.0f,
															true);
	
	// Prevent the bullet from rolling forever
	bullet->setAngularDamping(0.0025f);	

	// Return the bullet
	return bullet;
}

// setupTestSim0
/* Based on source by KayNine, many thanks to him for letting me use it. :) */
DynamicSphere* setupTestSim0(SceneNode* rootNode)
{
	// Test sims will return a bullet object for interactivity
	DynamicSphere* bullet;

	// Simulation already running
	if(Simulation::getSingleton().isInitialised())
	{
		// Shutdown the Simulation (clears all existing objects automatically)
		Simulation::getSingleton().shutdown();
	}

	// Initialise the Simulation
	Simulation::getSingleton().initialise(rootNode,
											150,
											Vector3(0.0f, -980.0f, 0.0f),
											20,
											210,
											200);


	// Manually load the terrain mesh without the WRITE_ONLY flag, for direct access
	MeshManager::getSingleton().load("terrain.mesh", HardwareBuffer::HBU_STATIC, HardwareBuffer::HBU_STATIC, false, false);
	
	// Create the TriMesh
	Simulation::getSingleton().createTriMesh("terrain",
												"terrain.mesh",
												"Demo/Scales",
												Vector3(0.0f, -600.0f, -750.0f),
												Quaternion::IDENTITY,
												String::BLANK);
	
	// Create the steps
	for(unsigned int i = 0; i < 10; i++)
	{
		Simulation::getSingleton().createStaticBox(String("step") + StringConverter::toString(i),
										String::BLANK,
										"Demo/Rocky",
										Vector3(0.0f, (-280.0f + (i * 50.0f)), (-1000.0f - (i * 40.0f))),
										Quaternion::IDENTITY,
										String::BLANK,
										Vector3(1000.0f, 40.0f, 80.0f),
										true);
	}

	// Create ragdolls
	for(unsigned int i = 0; i < 5; i++)
	{
		constructRagDoll("doll_" + StringConverter::toString(i),
							Vector3(Math::RangeRandom(-250.0f, 250.0f), (500.0f + (i * 250.0f)), -1250.0f),
							40.0f,
							8.0f,
							4);
	}

	// Pin the first doll up by his arm/hand
	BallSocket* pin = Simulation::getSingleton().createBallSocket("pin",
													Simulation::getSingleton().getPhysicalObject("doll_0_leftForearm"),
													0,
													Simulation::getSingleton().getPhysicalObject("doll_0_leftForearm")->getPosition(),
													Quaternion::IDENTITY);
	pin->setNumIterations(10);
	pin->setDampingFactor(0.025f);
	
	// Create the bullet
	bullet = Simulation::getSingleton().createDynamicSphere("bullet",
											"",
											"Demo/Scales",
											Vector3(1000.0f, 25.0f, 1000.0f),
											Quaternion::IDENTITY,
											String::BLANK,
											50.0f,
											1000.0f,
											true);
   
	// Prevent the bullet from rolling forever
	bullet->setAngularDamping(0.0025f);   

	// Return the bullet
	return bullet;
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -