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

📄 testsims.cpp

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

	// 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);	

	// Construct a building (small)
	constructBuilding("SmallBuilding1",
						Vector3(-200.0f, 0.0f, -200.0f),
						Vector3(25.0f, 50.0f, 25.0f),
						25.0f,
						String::BLANK,
						Vector3(200.0f, 25.0f, 200.0f),
						25.0f,
						String::BLANK,
						5);

	
	// Construct a building (small)
	constructBuilding("SmallBuilding2",
						Vector3(200.0f, 0.0f, -200.0f),
						Vector3(25.0f, 50.0f, 25.0f),
						25.0f,
						String::BLANK,
						Vector3(200.0f, 25.0f, 200.0f),
						25.0f,
						String::BLANK,
						5);
	
	// Construct a building (small)
	constructBuilding("SmallBuilding3",
						Vector3(-200.0f, 0.0f, 200.0f),
						Vector3(25.0f, 50.0f, 25.0f),
						25.0f,
						String::BLANK,
						Vector3(200.0f, 25.0f, 200.0f),
						25.0f,
						String::BLANK,
						5);
	
	// Construct a building (small)
	constructBuilding("SmallBuilding4",
						Vector3(200.0f, 0.0f, 200.0f),
						Vector3(25.0f, 50.0f, 25.0f),
						25.0f,
						String::BLANK,
						Vector3(200.0f, 25.0f, 200.0f),
						25.0f,
						String::BLANK,
						5);

	// Return the bullet
	return bullet;
}

// setupTestSim5()
DynamicSphere* setupTestSim5(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,
											15,
											15);

	// 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 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);

	// Resusable pointers
	DynamicBox* newBox;
	DynamicBox* lastBox;
	BallSocket *joint;

	// Create the first box
	lastBox = Simulation::getSingleton().createDynamicBox("box0",
															String::BLANK,
															String::BLANK,
															Vector3(0.0f, 25.0f + 50.0f, 0.0f),
															Quaternion::IDENTITY,
															String::BLANK,
															Vector3(50.0f, 50.0f, 50.0f),
															1.0f,
															true);
	lastBox->setAngularDamping(0.0025f);
	lastBox->setLinearDamping(0.0025f);

	// Create the other 9 boxes
	for(int i = 1; i < 10; i++)
	{
		// Create the next box in the chain
		newBox = Simulation::getSingleton().createDynamicBox("box" + StringConverter::toString(i),
																String::BLANK,
																String::BLANK,
																Vector3(0.0f, (i * 50.0f) + 25.0f + 50.0f, 0.0f),
																Quaternion::IDENTITY,
																String::BLANK,
																Vector3(50.0f, 50.0f, 50.0f),
																1.0f,
																true);
		newBox->setAngularDamping(0.0025f);
		newBox->setLinearDamping(0.0025f);

		// Links the boxes together
		joint = Simulation::getSingleton().createBallSocket("joint" + StringConverter::toString(i),
															lastBox, newBox,
															Vector3(0.0f, (i * 50.0f) + 50.0f, 0.0f),
															Quaternion::IDENTITY);

		// Set the last box for the next joint
		lastBox = newBox;
	}

	// Links the last box to the world
	joint = Simulation::getSingleton().createBallSocket("jointToWorld",
														lastBox,
														0,
														Vector3(0.0f, ((10 * 50.0f) + 25.0f + 50.0f), 0.0f),
														Quaternion::IDENTITY);
	
	// Return the bullet
	return bullet;
}

// setupTestSim6()
DynamicSphere* setupTestSim6(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,
											15,
											15);

	// 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 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);

	// Resusable pointers
	DynamicBox* newBox;
	DynamicBox* lastBox;
	Hinge *joint;

	// Get a quaternion for the rotation of the joint
	Matrix3 angleMat;
	angleMat.FromEulerAnglesXYZ(0.0f, 0.0f, (PI / 2.0f));
	Quaternion angleQuat;
	angleQuat.FromRotationMatrix(angleMat);

	// Create the first box
	lastBox = Simulation::getSingleton().createDynamicBox("box0",
															String::BLANK,
															String::BLANK,
															Vector3(0.0f, 25.0f + 50.0f, 0.0f),
															Quaternion::IDENTITY,
															String::BLANK,
															Vector3(50.0f, 50.0f, 50.0f),
															1.0f,
															true);
	lastBox->setAngularDamping(0.0025f);
	lastBox->setLinearDamping(0.0025f);

	// Create the other 9 boxes
	for(int i = 1; i < 10; i++)
	{
		// Create the next box in the chain
		newBox = Simulation::getSingleton().createDynamicBox("box" + StringConverter::toString(i),
																String::BLANK,
																String::BLANK,
																Vector3(0.0f, (i * 50.0f) + 25.0f + 50.0f, 0.0f),
																Quaternion::IDENTITY,
																String::BLANK,
																Vector3(50.0f, 50.0f, 50.0f),
																1.0f,
																true);
		newBox->setAngularDamping(0.0025f);
		newBox->setLinearDamping(0.0025f);

		// Links the boxes together
		joint = Simulation::getSingleton().createHinge("joint" + StringConverter::toString(i),
															lastBox, newBox,
															50.0f,
															Vector3(0.0f, (i * 50.0f) + 50.0f, 0.0f),
															angleQuat);

		// Limit the motion of the joint
		joint->setLowerLimit(-PI/8);
		joint->setUpperLimit(PI/8);
		joint->setLimitEnabled(true);

		// Set the last box for the next joint
		lastBox = newBox;
	}
	
	// Links the last box to the world
	Simulation::getSingleton().createBallSocket("jointToWorld",
												lastBox,
												0,
												Vector3(0.0f, ((10 * 50.0f) + 25.0f + 50.0f), 0.0f),
												Quaternion::IDENTITY);
	
	// Return the bullet
	return bullet;
}

// setupTestSim7
DynamicSphere* setupTestSim7(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,
											10,
											0,
											10);

	// Enable breakage callbacks
	Simulation::getSingleton().setBreakageCallback(testBreakageCallback);

	// 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 StaticComplex
	StaticComplex* complex = Simulation::getSingleton().createStaticComplex("complex1",
													String::BLANK,	
													String::BLANK,
													Vector3(0.0f, 0.0f, 0.0f),
													Quaternion::IDENTITY);

	// Add a few Elements to the complex
	CubicElement* box = complex->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 = complex->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);
	box = complex->addCubicElement("box3",
									String::BLANK,
									String::BLANK,
									Vector3(0.0f, 175.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);
	box = complex->addCubicElement("box4",
									String::BLANK,
									String::BLANK,
									Vector3(-50.0f, 175.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);
	box = complex->addCubicElement("box5",
									String::BLANK,
									String::BLANK,
									Vector3(-100.0f, 175.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);
	box = complex->addCubicElement("box6",
									String::BLANK,
									String::BLANK,
									Vector3(-100.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 a DynamicComplex
	DynamicComplex* complex2 = Simulation::getSingleton().createDynamicComplex("complex2",
																				String::BLANK,	
																				String::BLANK,
																				Vector3(500.0f, 0.0f, 0.0f),
																				Quaternion::IDENTITY,
																				25.0f);

	// Approximate the mass distribution for this object
	complex2->setCubicInertiaTensor(100.0f, 150.0f, 50.0f, 25.0f);

⌨️ 快捷键说明

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