Box2D Forums

It is currently Thu May 23, 2013 9:46 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sat Jul 14, 2012 3:36 am 
Offline

Joined: Fri Jul 13, 2012 10:59 am
Posts: 1
Hi all.
I'm building some stuff with Qt and Box2D. I just follow the Hello Box2D with some of my customization, here is the screen:
Image
The application hase the timer, each time the timer tick , I call world->Step(B2_TIMESTEP, B2_VELOCITY_ITERATIONS, B2_POSITION_ITERATIONS);
Code:
static const float32 B2_TIMESTEP = 1.0f / 60.0f;
static const int B2_VELOCITY_ITERATIONS = 8;
static const int B2_POSITION_ITERATIONS = 3;
static const int TIMER_INTERVAL = 16;//in milisecon

I get some trouble with set the value for TIMER_INTERVAL and B2_TIMESTEP.
About: B2_TIMESTEP, if I increase it let say 1000 times the movement of the green-box is different. When B2_TIMESTEP = 1.0f / 60.0f the small box jump out of the second ground-box, and when B2_TIMESTEP = 1000.0f / 60.0f the green-box land on the second ground-box. Why?

I think TIMER_INTERVAL around 16-20 is ok, right?
Thanks for your time.


Attachments:
File comment: Qt and Box2D example
qt-box2d-ex01.png
qt-box2d-ex01.png [ 2.21 KiB | Viewed 366 times ]
Top
 Profile  
 
PostPosted: Sat Jul 14, 2012 7:55 pm 
Offline

Joined: Fri Jul 06, 2012 9:33 pm
Posts: 5
The timeStep argument you supply to the Step function uses seconds as a unit (most values in Box2D use meters, kilograms, seconds, or radians for units). The timeStep value basically tells Box2D how long a single "frame" in your application is, and it should not vary as your program runs.

16-17 milliseconds is roughly 1/60th of a second (60Hz), which is appropriate. 60Hz is a typical frame rate.

Note that I don't know much about Qt, but there's a possibility that its timer does not have a very good resolution, which may make the Box2D simulation appear jittery. But it is my understanding that timing and timer APIs is outside of the scope of the Box2D library, so I'm not sure if you can get help with that here.

Hope I've been of help!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group