Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / SetPhysicsScale and StepPhysics Questions

Author
Message
DrT
15
Years of Service
User Offline
Joined: 10th May 2008
Location: 26.78 degrees North, -70.49 degrees West
Posted: 16th Aug 2011 22:18
Something with SetPhysicsScale and StepPhysics is not adding up.

I am assuming that Box2D is defaulting to 10 m/s^2 for the y acceleration. If this is the case, then an object released from rest will fall 5 m.

I setup a small program to do just that.



According to the program, the ball falls around 15 pixels. If 5 m corresponds to 15 pixels, then the default scale is 0.333 m/pixel. According to the help file for SetPhysicsScale, the default is 0.2.

Since the physics is done numerically, I thought it may be a problem with the step size. I called StepPhysics with progressively smaller values. Two things should have occured. 1) If the step size was too large to begin with, the result of the calculation should change and then converge to a new value. 2) The simulation should take longer and longer to run. I didn't observe either of these.

There seems to be multiple inconsistencies. Can anyone resolve these?
DrT
15
Years of Service
User Offline
Joined: 10th May 2008
Location: 26.78 degrees North, -70.49 degrees West
Posted: 16th Aug 2011 22:20
5 meters in 1 second
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 16th Aug 2011 23:37


is casting a float to an int which may be throwing off the timing. I get 25 pixels which gives a scale of 0.2
DrT
15
Years of Service
User Offline
Joined: 10th May 2008
Location: 26.78 degrees North, -70.49 degrees West
Posted: 17th Aug 2011 00:40
Thanks Paul. You are absolutely right about the casting problem. However, a problem still exists. I now get 35 pixels which gives a scale of 0.14. We run the same program but we get different results??? Do you have any suggestions for resolving this?

Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 17th Aug 2011 03:17
It may be the initial physics step is not using a well defined interval. Normally it goes off the time spent rendering the last frame, which doesn't exist for the first frame.

Try adding



at the start of your code to get the simulation started maybe that will be more reliable.
DrT
15
Years of Service
User Offline
Joined: 10th May 2008
Location: 26.78 degrees North, -70.49 degrees West
Posted: 17th Aug 2011 03:55
Thanks for following up on this Paul. I'll try your suggestion.

I also had success adding SetPhysicsScale and SetPhysicsGravity at the VERY start of the program.

1) I started with a scale of 0.2 meters/pixel (even though it supposed to be default) and a y acceleration of 50 pixels/second^2 (10 meters/second^2 - even though it supposed to be default). After 1 s, y should be approximately 5 m. I got 25 pixels which is consistent with the scale.

2) I then tried a scale of 0.05 meters/pixel and a y acceleration of 200 pixels/second^2 (10 meters/second^2). After 1 s, y should be approximately 5 m. I got 95 pixels which is consistent with the scale.

Anyway, it seems reproducible so I'm happy.

Login to post a reply

Server time is: 2024-04-20 05:37:54
Your offset time is: 2024-04-20 05:37:54