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