本文整理汇总了C++中PhysicsContact::CalculateData方法的典型用法代码示例。如果您正苦于以下问题:C++ PhysicsContact::CalculateData方法的具体用法?C++ PhysicsContact::CalculateData怎么用?C++ PhysicsContact::CalculateData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhysicsContact
的用法示例。
在下文中一共展示了PhysicsContact::CalculateData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: privCheckCollisions
// Check our collisions and handle them accordingly
void Demo::privCheckCollisions(const float timeIn)
{
PhysicsContact contact;
contact.Reset();
// Check bullet and ground
if (CheckColliding(ground, bullet, contact))
{
// Handle collision
contact.CalculateData(timeIn);
contact.ChangeVelocity();
contact.ChangePosition();
contact.Reset();
}
// Check all bricks against ground
for (int i = 0; i < NUM_BRICKS; i++)
{
if (CheckColliding(bricks[i], ground, contact))
{
// Handle collision
contact.CalculateData(timeIn);
contact.ChangeVelocity();
contact.ChangePosition();
contact.Reset();
}
}
// Check all bricks against bullet
for (int i = 0; i < NUM_BRICKS; i++)
{
if (CheckColliding(bullet, bricks[i], contact))
{
contact.CalculateData(timeIn);
// Time to have some fun with all blocks within certain distance of this collision
// Launch those bricks upward with random angular velocity
for (int k = 0; k < NUM_BRICKS; k++)
{
// use mag squared to avoid square root
Vect diffPos = bricks[k].position - contact.contactPoint;
float magSquared = diffPos.magSqr();
if (magSquared < 1500.0f && bricks[k].position[1] >= bricks[i].position[1])
{
Vect velocityChange(diffPos[0] > 0 ? 30.0f : -30.0f, 200.0f, 0.0f);
bricks[k].velocity += velocityChange;
static int x = 987444303;
srand(x);
x += 5134;
// Random angular velocity
Vect angVelocityChange(0.0f, 0.0f, 0.0f);
angVelocityChange[0] = (float)(rand() % 60 - 30);
angVelocityChange[1] = (float)(rand() % 60 - 30);
angVelocityChange[2] = (float)(rand() % 60 - 30);
bricks[k].angVelocity += angVelocityChange;
}
}
// Slow time on this collision
if (!this->timeSlowed)
{
this->slowTimer = 0.0f;
this->timeSlowed = true;
this->motionBlur.blurOn = true;
}
contact.Reset();
bullet.active = false;
break;
}
}
// Now check all bricks with each other
for (int i = 0; i < NUM_BRICKS; i++)
{
for (int j = i + 1; j < NUM_BRICKS; j++)
{
if (CheckColliding(bricks[i], bricks[j], contact))
{
// Handle collision accordingly
contact.CalculateData(timeIn);
contact.ChangeVelocity();
contact.ChangePosition();
contact.Reset();
}
}
}
return;
};