本文整理汇总了C++中PhysicsObject::getHitFraction方法的典型用法代码示例。如果您正苦于以下问题:C++ PhysicsObject::getHitFraction方法的具体用法?C++ PhysicsObject::getHitFraction怎么用?C++ PhysicsObject::getHitFraction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhysicsObject
的用法示例。
在下文中一共展示了PhysicsObject::getHitFraction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Work
void Physics::Work(Window *W, EventParams *E)
{
if (E->Param1 != TimerID) return;
PhysicsObject *curObj;
while (curObj = env->GetNextObject())
{
if (curObj->FixedObject) continue;
Coord3D Force(0, nDim == 2 ? curObj->mass * env->gravity : 0, nDim == 3 ? curObj->mass * env->gravity : 0);
int nHits = 0;
int i = 0;
for (PhysicsObject *chkObj = env->GetNextObject(0); chkObj != 0; chkObj=env->GetNextObject(++i))
{
if (curObj == chkObj) continue;
if (curObj->CheckHit(chkObj, nDim))
{
nHits++;
Coord3D Fraction = curObj->getHitFraction(chkObj, nDim);
if (!chkObj->FixedObject) curObj->NewVelocity = (chkObj->Velocity / chkObj->mass) * curObj->mass;
else curObj->NewVelocity = curObj->NewVelocity - Fraction * curObj->Velocity * 2;
}
}
if (nHits == 0) curObj->NewVelocity = curObj->Velocity;
curObj->NewPosition = curObj->Position + curObj->Velocity;
}
env->update();
}