当前位置: 首页>>代码示例>>C++>>正文


C++ PhysicsComponent::addTranslationalForce方法代码示例

本文整理汇总了C++中PhysicsComponent::addTranslationalForce方法的典型用法代码示例。如果您正苦于以下问题:C++ PhysicsComponent::addTranslationalForce方法的具体用法?C++ PhysicsComponent::addTranslationalForce怎么用?C++ PhysicsComponent::addTranslationalForce使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PhysicsComponent的用法示例。


在下文中一共展示了PhysicsComponent::addTranslationalForce方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: run

string RocketController::run(string myState)
{
	string game_state_request;
	for(vector<Entity*>::size_type i = 0; i != controlled_entities.size(); i++) 
	{
		Entity* ent = controlled_entities[i];
		if(ent->getGameState() == myState)
			{
			if(ent->getActive())
			{
				//SUBTRACT FUEL
				SpaceshipComponent* spaceship = (SpaceshipComponent*) ent->getComponent("Spaceship");
				float current_fuel = spaceship->getCurrentFuel();

				CollectionComponent* collection = (CollectionComponent*) ent->getComponent("Collection");
				vector<Entity*> attached_entities = collection->getAttachedEntities();

				//Cycling through attached entities
				for(vector<Entity*>::size_type p = 0; p != attached_entities.size(); p++) 
				{
					Entity* attached_entity = attached_entities[p];
					attached_entity->setActive(true);

					if(attached_entity->checkIfHasComponent("Rocket"))
					{
						RocketComponent* rocket = (RocketComponent*) attached_entity->getComponent("Rocket");
						TetheredComponent* tethered = (TetheredComponent*) attached_entity->getComponent("Tethered");
						PositionComponent* position = (PositionComponent*) attached_entity->getComponent("Position");
						PhysicsComponent* physics = (PhysicsComponent*) attached_entity->getComponent("Physics");

						physics->clearForces();

						if(rocket->getOnOrOff())
						{
							if(spaceship->getCurrentFuel() - rocket->getFuelConsumption() >= 0)
							{
								//The rocket is on
								float force_exerted = rocket->getForceExerted();
								float angle = position->getAngle();

								float x =  rocket->getForceExerted()*cos(angle);
								float y =  rocket->getForceExerted()*sin(angle);
						
								physics->addTranslationalForce(x,y);

								//Angular Forces

								float distance = tethered->getDistance();
								float angular_force = distance *  rocket->getForceExerted() * -sin(tethered->getT());

								physics->addAngularForce(angular_force);

								//Burning fuel
								spaceship->subtractCurrentFuel(rocket->getFuelConsumption());
							}
						}
					}
				}
			}
			else
			{
				CollectionComponent* collection = (CollectionComponent*) ent->getComponent("Collection");
				vector<Entity*> attached_entities = collection->getAttachedEntities();

				//Cycling through attached entities
				for(vector<Entity*>::size_type p = 0; p != attached_entities.size(); p++) 
				{
					attached_entities[p]->setActive(false);
				}
			}
		}
	}
	return game_state_request;
}
开发者ID:TheNextGuy32,项目名称:Titus-Engine,代码行数:74,代码来源:RocketController.cpp


注:本文中的PhysicsComponent::addTranslationalForce方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。