本文整理汇总了C++中Solid::addForce方法的典型用法代码示例。如果您正苦于以下问题:C++ Solid::addForce方法的具体用法?C++ Solid::addForce怎么用?C++ Solid::addForce使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Solid
的用法示例。
在下文中一共展示了Solid::addForce方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: internal_update
void VelocityMotor::internal_update()
{
// check if we have a solid
if (mData.solid == NULL || isEnabled() == false) return ;
Vec3r targetVelocity = mData.velocity;
Solid * solid = mData.solid;
Vec3r currentAchievedVelocity = solid->getGlobalLinearVel();
if (doesGravityAffectSolid())
{
Vec3r gravity = mSimulator->getGravity();
if (gravity.length() > 0)
{
Vec3r gravity_velocity = project(gravity, currentAchievedVelocity);
currentAchievedVelocity -= gravity_velocity;
}
}
Vec3r deltaVelocity = targetVelocity - currentAchievedVelocity;
Vec3r forceVector = deltaVelocity / mSimulator->getStepSize() * solid->getMass();
if (!doesGravityAffectSolid())
forceVector -= mSimulator->getGravity() * solid->getMass();
if (forceVector.length() > getMaximumForce())
{
forceVector.normalize();
forceVector *= getMaximumForce();
}
Force controllingForce;
controllingForce.duration = 0;
controllingForce.singleStep = true;
controllingForce.type = GLOBAL_FORCE;
controllingForce.vec = forceVector;
solid->addForce(controllingForce);
}