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

📄 building.cpp

📁 使用stl技术,(还没看,是听说的)
💻 CPP
字号:
/** @file Building.cpp
	@brief Contains functions for quickly setting up building structures.
*/

// Includes
#include "Demo.h"

// constructBuilding()
void constructBuilding(const String& name,
						const Vector3& basePosition, 
						const Vector3& cornerSize,
						Real cornerMass,
						String cornerSurface,
						const Vector3& floorSize,
						Real floorMass,
						String floorSurface,
						unsigned int numFloors)
{
	// Temporary box object
	DynamicBox* tempBox;

	// Compute coeffecients once
	Real negX = basePosition.x + (cornerSize.x / 2) - (floorSize.x / 2);
	Real posX = basePosition.x + (floorSize.x / 2) - (cornerSize.x / 2);
	Real negZ = basePosition.z + (cornerSize.z / 2) - (floorSize.z / 2);
	Real posZ = basePosition.z + (floorSize.z / 2) - (cornerSize.z / 2);
	Real cornerOffset = cornerSize.y / 2;
	Real floorHeight = cornerSize.y + floorSize.y;
	Real floorOffset = floorSize.y / 2;

	// Loop through number of floors
	for(unsigned int floor = 0; floor < numFloors; floor++)
	{
		// Create the center pillar
		tempBox = Simulation::getSingleton().createDynamicBox(name + "_Floor_" + StringConverter::toString(floor) + "_CenterPillar",
																String::BLANK, 
																String::BLANK, 
																Vector3(basePosition.x, basePosition.y + cornerOffset + (floor * floorHeight), basePosition.z),
																Quaternion::IDENTITY,
																cornerSurface,
																cornerSize,
																cornerMass,
																true);
		
		// Create the NegativeX/NegativeZ corner
		tempBox = Simulation::getSingleton().createDynamicBox(name + "_Floor_" + StringConverter::toString(floor) + "_Corner_NegXNegZ",
																String::BLANK, 
																String::BLANK, 
																Vector3(negX, basePosition.y + cornerOffset + (floor * floorHeight), negZ),
																Quaternion::IDENTITY,
																cornerSurface,
																cornerSize,
																cornerMass,
																true);
		
		// Create the PositiveX/NegativeZ corner
		tempBox = Simulation::getSingleton().createDynamicBox(name + "_Floor_" + StringConverter::toString(floor) + "_Corner_PosXNegZ",
																String::BLANK, 
																String::BLANK, 
																Vector3(posX, basePosition.y + cornerOffset + (floor * floorHeight), negZ),
																Quaternion::IDENTITY,
																cornerSurface,
																cornerSize,
																cornerMass,
																true);
		
		// Create the NegativeX/PositiveZ corner
		tempBox = Simulation::getSingleton().createDynamicBox(name + "_Floor_" + StringConverter::toString(floor) + "_Corner_NegXPosZ",
																String::BLANK, 
																String::BLANK, 
																Vector3(negX, basePosition.y + cornerOffset + (floor * floorHeight), posZ),
																Quaternion::IDENTITY,
																cornerSurface,
																cornerSize,
																cornerMass,
																true);
		
		// Create the PositiveX/PositiveZ corner
		tempBox = Simulation::getSingleton().createDynamicBox(name + "_Floor_" + StringConverter::toString(floor) + "_Corner_PosXPosZ",
																String::BLANK, 
																String::BLANK, 
																Vector3(posX, basePosition.y + cornerOffset + (floor * floorHeight), posZ),
																Quaternion::IDENTITY,
																cornerSurface,
																cornerSize,
																cornerMass,
																true);
		
		// Create the floor
		tempBox = Simulation::getSingleton().createDynamicBox(name + "_Floor_" + StringConverter::toString(floor),
																String::BLANK, 
																String::BLANK, 
																Vector3(basePosition.x, basePosition.y + floorOffset + (floor * (floorHeight)) + cornerSize.y, basePosition.z),
																Quaternion::IDENTITY,
																floorSurface,
																floorSize,
																floorMass,
																true);
	}
}


⌨️ 快捷键说明

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