Is it possible to fast forward simulation in Box2D

爱⌒轻易说出口 提交于 2019-12-11 11:14:10

问题


I create a box2d world, put some objects on the screen with different properties like rotation, restitution ,density. And then I start the application. Is it possible to fast forward the simulation so that I can see the result quickly? By result I mean the final state of the world objects. Just like a video clip.


回答1:


Thanks to Andrew I found that if I run the Step function multiple times, I can get the fast forwarded simulation. Here's just a little code that I guess anybody could write:

-(void)simulateWithFastForwardRate:(int)ffRate timeStep:(float32)timeStep
                    velocity:(int)velIters 
       andPositionIterations:(int)posIters{
     for(int i=0;i<ffRate;i++){
       _world->Step(timeStep,velIters,posIters);
     }
}

Just run the above method passing it the fast forward rate, velocity and position iterations.



来源:https://stackoverflow.com/questions/15208549/is-it-possible-to-fast-forward-simulation-in-box2d

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!