本文整理汇总了C++中Octree::potentialSphereWallCollisions方法的典型用法代码示例。如果您正苦于以下问题:C++ Octree::potentialSphereWallCollisions方法的具体用法?C++ Octree::potentialSphereWallCollisions怎么用?C++ Octree::potentialSphereWallCollisions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Octree
的用法示例。
在下文中一共展示了Octree::potentialSphereWallCollisions方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
//Updates the logic
void update()
{
double prevTime = currTime;
currTime = timer.getElapsedTime();
double deltaTime = currTime - prevTime;
GLfloat dfps = (GLfloat)deltaTime/1000000;
gravity = 4.0*9.8*dfps;
delta = 10*dfps;
deltaBall = 2.5*dfps;
//Checks the keyboard input
keyboard();
//Update the spheres positions, and then checks if they collide
for(unsigned int i = 0; i < spheres.size(); ++i)
{
Vector3 oldPos = spheres[i]->getPos();
spheres[i]->move(deltaBall, gravity);
octree.sphereMoved(spheres[i], oldPos);
}
//Spheres collitions
if(octr)
{
vector<SpherePair> sp;
octree.potentialSphereCollisions(sp);
for(unsigned int i = 0; i < sp.size(); ++i, calc++)
if(areColliding(sp[i].first, sp[i].second))
collision(sp[i].first, sp[i].second, inellastic);
}
else
for(unsigned int i = 0; i < spheres.size(); ++i)
for(unsigned int j = i+1; j < spheres.size(); ++j, calc++)
if(areColliding(spheres[i], spheres[j]))
collision(spheres[i], spheres[j], inellastic);
if (octr)
{
vector<SphereWallPair> sw;
octree.potentialSphereWallCollisions(sw, walls);
for(unsigned int i = 0; i < sw.size(); ++i, calc++)
if(sphereWallColliding(sw[i].first, sw[i].second))
wallCollision(sw[i].first, sw[i].second, inellastic);
}
else
//Checks if the balls collide with the walls
for(unsigned int i = 0; i < spheres.size(); ++i)
for(unsigned int j = 0; j < walls.size(); ++j, calc++)
if(sphereWallColliding(spheres[i], walls[j]))
wallCollision(spheres[i],walls[j], inellastic);
//Draws the simulation
draw();
//FPS calculation
//Happens every 1/5 of a second, more precision but flickier
if (currTime - lastTime > 1000000/5) {
stringstream ss;
int n = spheres.size();
ss << "Sphere collision " << "FPS: " << (double)fps*1000000/(currTime-lastTime);
ss << " Number of spheres: " << n << " Calculations: " << calc;
if(octr)
ss << " Octree method";
else
ss << " Slow method";
glutSetWindowTitle(ss.str().c_str());
lastTime = currTime;
//Recalculates deltas
/*GLfloat dfps = (GLfloat)1/(fps*5);
gravity = 3.0*9.8*dfps;
delta = 10*dfps;
deltaBall = 2.5*dfps;*/
//cout << gravity << "delta: "<< delta << "deltaBall: "<< deltaBall <<endl;
fps = 0;
}
fps++;
calc = 0;
}