当前位置: 首页>>代码示例>>C++>>正文


C++ Octree::potentialSphereCollisions方法代码示例

本文整理汇总了C++中Octree::potentialSphereCollisions方法的典型用法代码示例。如果您正苦于以下问题:C++ Octree::potentialSphereCollisions方法的具体用法?C++ Octree::potentialSphereCollisions怎么用?C++ Octree::potentialSphereCollisions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Octree的用法示例。


在下文中一共展示了Octree::potentialSphereCollisions方法的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;
}
开发者ID:alejopelaez,项目名称:sphere-collition,代码行数:85,代码来源:main.cpp


注:本文中的Octree::potentialSphereCollisions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。