Python Box2D! (howto)

Discuss issues specific the Python port of Box2D
roman_m
Posts: 36
Joined: Sun Nov 25, 2007 1:43 pm

Re: Python Box2D! (howto)

Postby roman_m » Tue Apr 08, 2008 6:36 am

Yes, I understood that there is logic error after my own exploration. I fixed this.

It's a pity, but I failed to test MCSV2008 build.

Code: Select all

Traceback (most recent call last):
  File "E:\tttt\test_framework.py", line 3, in <module>
    import Box2D2
  File "E:\tttt\Box2D2.py", line 6, in <module>
    import _Box2D2
ImportError: DLL load failed: This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.

EDIT: I've downloaded VC2008 redist and after that it worked. Result was the same as for mingw build.

Also I found that the problem is not only in performance. Simulation is not as accurate as in c++ program. When I load Pyramid test in testbed with same options (enablePositionCorrection, enableWarmStarting, enableTOI, deltaT = 1/60.0, iterations = 10) it all objects begin to sleep very soon, but in python they move slightly and pyramid falls (look at the screenshot).
Attachments
test_framework.zip
(2.02 KiB) Downloaded 5710 times
bad_pyramid.png
bad_pyramid.png (29.44 KiB) Viewed 7210 times

Erin Catto
Site Admin
Posts: 2948
Joined: Thu Sep 06, 2007 12:34 am

Re: Python Box2D! (howto)

Postby Erin Catto » Tue Apr 08, 2008 9:24 am

This might the bug with needing to have a contact listener for warm starting to work. This is fixed in SVN.

roman_m
Posts: 36
Joined: Sun Nov 25, 2007 1:43 pm

Re: Python Box2D! (howto)

Postby roman_m » Wed Apr 09, 2008 1:11 am

Erin Catto wrote:This might the bug with needing to have a contact listener for warm starting to work. This is fixed in SVN.

Yes. I added contact listener and it worked.
Attachments
test_framework.zip
(1.97 KiB) Downloaded 4640 times

roman_m
Posts: 36
Joined: Sun Nov 25, 2007 1:43 pm

Re: Python Box2D! (howto)

Postby roman_m » Mon Apr 14, 2008 3:47 am

I updated my python mini TestBed.
Now it can draw everything. Also test can react on keyboard input. And test is in seperate module from framework. For now only one test at one time is supported, it should be located in 'mytest.py' file.
I'm going to improve it, but this version is already usable.
Attachments
test_framework.zip
(2.8 KiB) Downloaded 3605 times

kne
Posts: 88
Joined: Mon Feb 18, 2008 12:30 am

Re: Python Box2D! (howto)

Postby kne » Thu Apr 17, 2008 4:41 am

Nice work, roman_m. Looking good. :)

Here's the first version of the wrapper for 2.0.1:

Python Bindings 2.0.1r1 --
Usage here on the wiki: http://www.box2d.org/wiki/index.php?tit ... ith_Python
Download here: http://pybox2d.googlepages.com/

As it mentions on the page, let me know if any of you see a difference with the MSVC version -- perhaps the changes Erin made to the solution sped it up a bit? If not, the MinGW builds are faster and more convenient for me, so I'll stop making the MSVC builds.

roman_m
Posts: 36
Joined: Sun Nov 25, 2007 1:43 pm

Re: Python Box2D! (howto)

Postby roman_m » Tue Apr 22, 2008 4:39 am

I do not see any difference between mingw and MSVC build.
Performance is still bad.

In new release SetListener does not work. May be this is because of changes in box2d itself, but then, there is an error in wiki.
Also something changed with s_enablePositionCorrection, s_enableWarmStarting, s_enableTOI.

I quick updated test framework to work with new release. No other changes were made.
Attachments
test_framework.zip
(2.8 KiB) Downloaded 3750 times

kne
Posts: 88
Joined: Mon Feb 18, 2008 12:30 am

Re: Python Box2D! (howto)

Postby kne » Tue Apr 22, 2008 5:34 am

Sorry, I didn't update the wiki as completely as I should have. These changes should have been apparent if you read the Box2D 2.0.1 updates, however.

SetListener is now Set*Listener (for the contact listener, SetContactListener).
Look a bit further and you'll see that the previously static variables (s_enableTOI/etc) have now become these functions:

Code: Select all

   /// Enable/disable warm starting. For testing.
   void SetWarmStarting(bool flag) { m_warmStarting = flag; }

   /// Enable/disable position correction. For testing.
   void SetPositionCorrection(bool flag) { m_positionCorrection = flag; }

   /// Enable/disable continuous physics. For testing.
   void SetContinuousPhysics(bool flag) { m_continuousPhysics = flag; }

So, world.SetWarmStarting(True) and so on instead of your cvars.s_enableWarmStarting = True .

In my own tests, the python code hasn't been terribly slow. It's perfectly usable, in my opinion.

crazy-chris
Posts: 30
Joined: Thu Mar 13, 2008 9:27 am

Re: Python Box2D! (howto)

Postby crazy-chris » Wed Apr 23, 2008 1:28 am

hey,

here python code is actually running quite quick -- even on "lower performance machines" like the olpc xo laptop with 433 mhz and 256 mb ram.
see for example speed tests on the xo laptop and the elements project.

best,
- chris

roman_m
Posts: 36
Joined: Sun Nov 25, 2007 1:43 pm

Re: Python Box2D! (howto)

Postby roman_m » Wed Apr 23, 2008 6:01 am

kne wrote:In my own tests, the python code hasn't been terribly slow. It's perfectly usable, in my opinion.

May be the slowdown is because of DebugDraw and it's callbacks... I'll try to implement drawing without debugdraw.

kne
Posts: 88
Joined: Mon Feb 18, 2008 12:30 am

Re: Python Box2D! (howto)

Postby kne » Wed Apr 30, 2008 1:10 am

In case you haven't seen it yet, I've ported the Box2D testbed and tests to Python:
http://www.box2d.org/forum/viewtopic.php?f=6&t=791 (Game and Applications forum)

There's also what will now be the standard Win32 installer there to make the process easier.
I also moved the homepage to code.google.com and released 2.0.1b2 here:
http://code.google.com/p/pybox2d/


Return to “Python”



Who is online

Users browsing this forum: No registered users and 1 guest