本文整理汇总了C++中Physics::ApplyVerlet方法的典型用法代码示例。如果您正苦于以下问题:C++ Physics::ApplyVerlet方法的具体用法?C++ Physics::ApplyVerlet怎么用?C++ Physics::ApplyVerlet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Physics
的用法示例。
在下文中一共展示了Physics::ApplyVerlet方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnUpdate
void Physics::OnUpdate(IBehavior* invokingBehavior, IMessage* message)
{
Physics* pPhysics = (Physics*)invokingBehavior;
const Aabb& objLocalAabb = pPhysics->gameObject->GetLocalAabb();
for(unsigned int i = 0; i < 3; ++i)
{
if( pPhysics->localAabb.min.v[i] != objLocalAabb.min.v[i] ||
pPhysics->localAabb.max.v[i] != objLocalAabb.max.v[i] )
{
pPhysics->Initialize();
return;
}
}
if( pPhysics->physicsFlags & GRAVITY )
{
Attribute<bool>* groundedAttrib = (Attribute<bool>*)pPhysics->GetAttribute(
PhysicsAttributes::GROUNDED_ATTRIB);
if( groundedAttrib->value == false )
pPhysics->ApplyGravity();
}
Float3 com(0.0f, 0.0f, 0.0f);
for(unsigned int i = 0; i < pPhysics->m_X.size(); ++i)
com += pPhysics->m_X[i];
com *= (1.0f / pPhysics->m_X.size());
pPhysics->ApplyVerlet();
pPhysics->ApplyConstraints();
Float3 newcom(0.0f, 0.0f, 0.0f);
for(unsigned int i = 0; i < pPhysics->m_X.size(); ++i)
newcom += pPhysics->m_X[i];
newcom *= (1.0f / pPhysics->m_X.size());
Float3 delta = newcom - com;
if( delta.magnitude() > 0.25f )
{
delta.normalize();
delta *= 0.25f;
}
pPhysics->gameObject->TranslateGlobal( delta );
}