very low cube collision performance

BananaMama
Posts: 3
Joined: Sat Jan 17, 2009 11:18 pm

very low cube collision performance

Post by BananaMama »

Hi,

i'm making a scene, similar to the one used in BasicDemo. i have a big cube 5x5x5 built out of cubes 1x1x1. when i run the simulation as long as the cubes start to collide with themselves the animation slows down to 2-4 fps.

its definietly the collision-related problem because the more cubes are colliding, the bigger the slowdown is.

what i'm doing is:

physicsInit

Code: Select all

btTransform startTransform;
		startTransform.setIdentity();
		

		for (int i = 0; i < wallSize; i++){
			for (int j = 0; j < wallSize; j++){
				for (int k = 0; k < wallSize; k++){


					startTransform.setOrigin(btVector3(10+2*i*cubeSize,40+2*j*cubeSize,10+2*k*cubeSize));

					btDefaultMotionState* fallMotionState = new btDefaultMotionState(startTransform);

					btRigidBody::btRigidBodyConstructionInfo cubeRigidBodyCI(mass,fallMotionState,cubeShape,fallInertia);

					cubeRigidBody = new btRigidBody(cubeRigidBodyCI);

					//cubeRigidBody->setActivationState(ISLAND_SLEEPING);

					rigidBodies.push_back(cubeRigidBody); <<------VECTOR here

					dynamicsWorld->addRigidBody(cubeRigidBody);

					}
				}
			}
and in Draw:

Code: Select all

glPushMatrix();            

			btScalar m[16];

			btDefaultMotionState* myMotionState = (btDefaultMotionState*)rigidBodies[i]->getMotionState();

			myMotionState->m_graphicsWorldTrans.getOpenGLMatrix(m);

			btglMultMatrix(m);

			glCallList(box);

			glPopMatrix();
i've tried to see what is done differently in BasicDemo, but couldn't find out.

i'm a buller newbie so i don't know yet what could be the reason.

i've tried to add margins but it only gave a small increase in fps (up to 5-6 in biggest stress).
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: very low cube collision performance

Post by sparkprime »

What spec machine are you running on? What OS? Can you profile it? (valgrind callgrind / google performance tools / vtune / etc)

125 cubes is quite a lot but you should have better performance than that on a modern desktop. If your GL implementation is not hardware accelerated however you could have a problem. Can you isolate the physics from the rendering to check? Or profile?

What broadphase and solver are you using? At what frequency are you running simulation steps? Have you increased the number of solver iterations or anything like that?
BananaMama
Posts: 3
Joined: Sat Jan 17, 2009 11:18 pm

Re: very low cube collision performance

Post by BananaMama »

runs at p8400 2,2ghz ATI 3450 mobility, Vista. BasicDemo also involves 125 cubes, and this one runs smooth.

i've reduced number of rendered cubes to 5 and still no change, so the problem lies on physics side.

i'm using btDbvtBroadphase and btSequentialImpulseConstraintSolver. same like in the demo.

for simulation i use: stepSimulation(dt,7,1/17.f);, the reason for using 1/17.f is that i'm also running a camera in the update loop, and that's max that i can get from it. (i know that's lame and i should use separate thread for the camera call, but for now that's out of the question cos i'm pretty short on time.) anyways, when i turn the camera off and get back to 1/60 setting the same thing happens. when the cubes turn passive and dont move anymore fps jumps up to 300 or more.

i've tried to mess around with different step settings, but no real improvement.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: very low cube collision performance

Post by Erwin Coumans »

What are the collision shapes for ground and cubes? Do you use btBoxShape?
stepSimulation(dt,7,1/17.f);,
It is recommended to simply use 'stepSimulation(dt)', even if your camera update is different. Using more than 1 argument to stepSimulation is unsupported.

Apart from changing the stepSimulation call, can you please add the following line right after 'stepSimulation', and copy/paste a full frame timings to this thread, so we can see where performance goes?

Code: Select all

stepSimulation(dt);
CProfileManager::dumpAll();
Thanks,
Erwin
BananaMama
Posts: 3
Joined: Sat Jan 17, 2009 11:18 pm

Re: very low cube collision performance

Post by BananaMama »

first of all, changing to simple dt worked! i mean, i used that setting before with no results. but now it does work(???).

strange, cos the only thing i've done was changing to 3x3x3 cube and doing stuff not related to physics.

right now the fps stays at 17-18 level but the animation is in slowmotion. and that's no good either, but better than before :)

what can i do to increase the speed?

btw. i use btBoxShape and btStaticPlaneShape

btw2 i dont know how to use this dumpAll(); method. but i guess that now it's not that important

thanks
jack.