本文整理汇总了C++中Physics::applyForce方法的典型用法代码示例。如果您正苦于以下问题:C++ Physics::applyForce方法的具体用法?C++ Physics::applyForce怎么用?C++ Physics::applyForce使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Physics
的用法示例。
在下文中一共展示了Physics::applyForce方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: apply_fun
void GravitationalForce::apply_fun(float d_t){
for (unsigned int i = 0; i < mInfluencedPhysics.size()-1; i++){
Physics* lhs = mInfluencedPhysics[i];
for (unsigned int j = i+1 ; j < mInfluencedPhysics.size(); j++){
Physics* rhs = mInfluencedPhysics[j];
Vector3 distanceVector = rhs->getPosition()-lhs->getPosition();
float distance = distanceVector.length();
//Distanz in Ordnung
if (distance < getMaxDistance() && distance >= 1.0){
if(distance < 1){
distance = 1;
}
distanceVector.normalize();
//Anziehungskraft berechnen
float force = mScale * (rhs->getMass()*lhs->getMass() / (distance*distance));
//Anziehungskraft in Ordnung
if (force > getMinForce()){
Vector3 Rhs_forceVector = distanceVector;
Rhs_forceVector *= force;
//Anziehungskraft um d_t skaliert anwenden
lhs->applyForce(Rhs_forceVector*d_t);
Vector3 Lhs_forceVector = (-1.0) * distanceVector;
Lhs_forceVector *= force;
//Anziehungskraft um d_t skaliert anwenden
rhs->applyForce(Lhs_forceVector*d_t);
}
}
}
}
}