本文整理汇总了C++中BoundingSphere::overlaps方法的典型用法代码示例。如果您正苦于以下问题:C++ BoundingSphere::overlaps方法的具体用法?C++ BoundingSphere::overlaps怎么用?C++ BoundingSphere::overlaps使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BoundingSphere
的用法示例。
在下文中一共展示了BoundingSphere::overlaps方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runCollisions
void GameObjectRegistry::runCollisions(real duration)
{
// Leta efter grova kollisioner med andra RigidBody's
std::vector<PotentialContact> pcr;
for (Registry::iterator i = registrations.begin(); i != registrations.end(); ++i)
{
// testa en registration mot alla andra registrations
BoundingSphere* thisBs = new BoundingSphere(i->rb->position, .7);
for (Registry::iterator j = registrations.begin(); j != registrations.end(); ++j)
{
if (j != i)
{
BoundingSphere* thatBs = new BoundingSphere(j->rb->position, .7);
if(thisBs->overlaps(thatBs))
{
if(pcr.size() == 0)
{
PotentialContact pc;
pc.body[0] = i->rb;
pc.body[1] = j->rb;
pcr.push_back(pc);
}
else
{
bool collisionExists = false;
for (std::vector<PotentialContact>::iterator m = pcr.begin(); m != pcr.end(); ++m)
{
if( (m->body[0] == i->rb && m->body[1] == j->rb) || (m->body[0] == j->rb && m->body[1] == i->rb) )
{
collisionExists = true;
}
}
if (!collisionExists)
{
PotentialContact pc;
pc.body[0] = i->rb;
pc.body[1] = j->rb;
pcr.push_back(pc);
}
}
}
delete thatBs;
}
}
delete thisBs;
//std::cout << "Possible object-to-object collisions: " << pcr.size() << std::endl;
// Nu har vi fått en lista på potentiella kontakter.
// Kolla dessa med fine collision.
CollisionData cd;
Contact contacts[512];
cd.contactsArray = contacts;
cd.contact = contacts;
cd.contactCount = 0;
cd.contactsLeft = 512;
cd.tolerance = 0.0001;
cd.restitution = .4;
cd.friction = 0.9;
Plane flr;
flr.normal = Ogre::Vector3(0.0, 1.0, 0.0);
flr.offset = 0.0;
// kolla kollision med golvet
for (Registry::iterator i = registrations.begin(); i != registrations.end(); ++i)
{
Box b;
b.body = i->rb;
b.halfSize = Ogre::Vector3(.5, .5, .5);
CollisionDetector::boxAndHalfSpace(b, flr, &cd);
}
// Nu har vi möjligtvis kollisioner
if(cd.contactsLeft < 512)
std::cout << "Collisions: " << cd.contactCount << std::endl;
/*
for (Contact* contact=contacts; contact < (contacts + cd.contactCount); contact++)
{
std::cout << "cp: " << contact->body[0]->position << std::endl;
}
*/
//.........这里部分代码省略.........