c++ - Few rigidbody cause Bullet Physics slowly -
i'm doing job intergrating physics engine, bullet physics, graphics engine, before that, implemented easy collision system sap , narrowphase algorithm, cost of time 3ms sap , narrowphase 300 objects.
because of bugs of algorithm, decided change real physics engine, bullet physics. followed tutorial official articles. when thought know how implement in graphics engine, , output screen becomes 3 fps.
it seems problem on understand. make real simple example reproduce lag encountered.
btbroadphaseinterface* broadphase = new btdbvtbroadphase(); btdefaultcollisionconfiguration* collisionconfiguration = new btdefaultcollisionconfiguration(); btcollisiondispatcher* dispatcher = new btcollisiondispatcher(collisionconfiguration); btsequentialimpulseconstraintsolver* solver = new btsequentialimpulseconstraintsolver; btdiscretedynamicsworld* dynamicsworld = new btdiscretedynamicsworld(dispatcher, broadphase, solver, collisionconfiguration); dynamicsworld->setgravity(btvector3(0, -10, 0)); btcollisionshape* groundshape = new btstaticplaneshape(btvector3(0, 1, 0), 1); btcollisionshape* fallshape = new btsphereshape(1); btdefaultmotionstate* groundmotionstate = new btdefaultmotionstate(bttransform(btquaternion(0, 0, 0, 1), btvector3(0, -1, 0))); btrigidbody::btrigidbodyconstructioninfo groundrigidbodyci(0, groundmotionstate, groundshape, btvector3(0, 0, 0)); btrigidbody* groundrigidbody = new btrigidbody(groundrigidbodyci); dynamicsworld->addrigidbody(groundrigidbody); btdefaultmotionstate* fallmotionstate = new btdefaultmotionstate(bttransform(btquaternion(0, 0, 0, 1), btvector3(0, 50, 0))); btscalar mass = 1; btvector3 fallinertia(0, 0, 0); fallshape->calculatelocalinertia(mass, fallinertia); btrigidbody::btrigidbodyconstructioninfo fallrigidbodyci(mass, fallmotionstate, fallshape, fallinertia); btrigidbody* fallrigidbody = new btrigidbody(fallrigidbodyci); btrigidbody** fallrigidbodies = new btrigidbody*[300]; (int = 0; < 300; i++) { fallrigidbodies[i] = new btrigidbody(fallrigidbodyci); dynamicsworld->addrigidbody(fallrigidbodies[i]); } (int = 0; < 1000; i++) { debug::startmeasurenumber(10); // time measurement function & measurement id dynamicsworld->stepsimulation(1 / 60.f, 10); debug::endmeasurenumber(10); // report time elapsed. bttransform trans; fallrigidbody->getmotionstate()->getworldtransform(trans); //std::cout << "sphere height: " << trans.getorigin().gety() << std::endl; } dynamicsworld->removerigidbody(fallrigidbody); delete fallrigidbody->getmotionstate(); delete fallrigidbody; dynamicsworld->removerigidbody(groundrigidbody); delete groundrigidbody->getmotionstate(); delete groundrigidbody; delete fallshape; delete groundshape; delete dynamicsworld; delete solver; delete collisionconfiguration; delete dispatcher; delete broadphase;
in above code, modified hello world tutorial in last of page. code produce extremelty slow on stepsimulation. different did add 300 rigid bodies dynamicsworld. provide debug information below.
1138ms,634ms,386ms,297ms,247ms,217ms,211ms,192ms,175ms,163ms,156ms,149ms 147ms,147ms,137ms,137ms,133ms,126ms,128ms,123ms,126ms,127ms,119ms,119ms,115ms 116ms,114ms,114ms,114ms,118ms,120ms,108ms,107ms,107ms,109ms,103ms,105ms,102ms 115ms,106ms,102ms,99ms,99ms,96ms,94ms,93ms,93ms,97ms,94ms,94ms,89ms,90ms,89ms 90ms,90ms,87ms,87ms,84ms,85ms,86ms,92ms,88ms,84ms,85ms,83ms,110ms,86ms,84ms 83ms,85ms,82ms,89ms,80ms,80ms,77ms,76ms,81ms,75ms,78ms,79ms,75ms,77ms,78ms, 76ms,78ms,79ms,75ms,77ms,74ms,74ms,73ms,72ms,78ms,72ms,71ms,72ms,73ms,73ms, 77ms,77ms,71ms,70ms,71ms,68ms,71ms,71ms,73ms,69ms,68ms,67ms,67ms,66ms,68ms 71ms,74ms,66ms,66ms,65ms,65ms,66ms,67ms,64ms,65ms,63ms,66ms,64ms,65ms,63ms 67ms,64ms,63ms,62ms,66ms,63ms,61ms,63ms,62ms,64ms,61ms,63ms,61ms,61ms,64ms 65ms,61ms,63ms,65ms,63ms,62ms,61ms,60ms,61ms,63ms,60ms,61ms,61ms,62ms,60ms, 62ms,65ms,60ms,61ms
before 35th loop, extreme slow, , time being after that, going stable on 60 ms. slow graphics loop cycle handle, understand wrong in hello world tutorial? need me out :(
this question sloved bdl @ comments section. build project release version, , stepsimulation
run in 0ms!
Comments
Post a Comment