Thursday, May 19, 2011

Pure Python physics?


Recently I tried to get pybox2d compiled and running with PyPy, but it failed for whatever reason. I had it in my head to just give up and port the whole bloody thing to pure Python and see how that would go. Not wanting to waste inspiration, I gave that a shot. Fast forwarding to today, and it's pretty much done.

So, what's in the port? (almost) All features of Box2D up to r175:
  • All shape types (polygons, circles, edges, and loops)
  • All joint types (distance, revolute, friction, prismatic, weld, rope, wheel, mouse, pulley, gear)
  • A dynamic tree class for AABBs
  • Collisions, contacts, shape distance calculations, etc.
  • A mostly Pythonic interface to all of the useful classes
  • The testbed, in simplified form

Before you jump for joy, there are many reasons to not use this:

  • It's slow.
  • It's really slow.
  • It has a bad name (pypybox2d -- changing it is on the TODO list)
  • It's still early, though almost everything has worked well enough in my tests. I'm positive there are plenty of typos and minor bugs.
  • Some source files are much too big, because I haven't gotten around to splitting them up
  • It uses __slots__ for my own debugging purposes. I have no qualms about (almost wholly) removing their usage eventually.
"Why do this, then, if it's so slow and unusable?" Do you really have to ask? Why not?

So, what of PyPy after all that hard work? Unfortunately, in my few tests, it's been slower than CPython **. Perhaps one day it will be sped up by another means. Or maybe I'll figure out a way to get Cython working with it such that it won't totally screw everything up. If you have any ideas, please do get in touch with me.

Find the source here. The testbed requires pygame, but there's a (very) simple graphic-less hello.py in examples/ if you simply must run something.

** edit May 20th: But those tests were superficial, only testing for a few iterations. Increase the number of iterations, and PyPy wins, hands-down. See Antonio Cuni's helpful comment below for more information.

Sunday, March 13, 2011

Simple examples? oh yeah, and an alpha release for you...

So, not everyone likes the testbed. It's big, C++-ish, and not so pretty. And we all hate searching around in multiple files for function definitions.

Making some simple examples has been on the back-burner since I started on pybox2d a few years back. I've finally started on some examples, but I need your input on how to make them easily digestible for everyone else:

Is it worth going down this path?

To hopefully rouse up some interest, I will provide another alpha release. This time, I'll make it available to a larger audience by including builds for the platforms I have access to (sorry, OSX users -- you might not get any installer release for 2.2 at all).

So, read the manual, download from below, and try it out. Without your help, this version will never see daylight, I assure you!


win32 2.6, 2.7, 3.0, 3.1
linux-i686 2.6, 2.7, 3.1


Edit 4/7/2011: OK, so -- not a single comment in a month, and I recently fixed a major leak affecting all versions since 2.0.x, so I just removed those versions from the svn. 2.0.x has also seen its first update in a few years.

Saturday, February 26, 2011

2.1 on the move?

test_Car.py

Hi,

So, I've moved the 2.1 branch into the trunk. I've also spent more than half my Saturday fixing and writing documentation.

Here's the 2.1 manual on the wiki! If you have some time, please read through it. It's a lot of work -- hopefully someone will appreciate it. :)

I also re-uploaded the 2.0.2 bugs-n-stuff that were on the Box2D wiki, here. A couple of other wiki entries got updated, too. Notice anything strange? Please do let me know.

There's a few changes upstream that I'll get around to including soon, but I'm a bit burnt out after the above. Nothing huge, though.

Warm wishes,

kne

Wednesday, December 15, 2010

Found in the wild: Bricks Knock Off

I just happened upon a decently polished little game called Bricks Knock Off (English translation here) that's actually using the 2.1 branch of pybox2d. Cool!


As you might have guessed, it's a game about bricks. Shooting them off some platform to get a decent enough score to continue to the next level. It features music, sound effects, a few levels, and even a scrolling background.

I only have one comment from the pybox2d-end of things, and it's that the position/velocity iterations need to be tweaked to get the bricks to stack stably. If you check it out, change main.py around line 115ish to be something like:

    vel_iters, pos_iters = 15,15 

Thursday, November 4, 2010

Progress

Yes, there has been some progress. Only a bit though. I know you love it when I make bullet points, so here you go:

  • Most importantly, I fixed up a few things thanks to issues pointed out by users. Thanks mikkelin, Fahri, dabski, and anyone else that I might have forgotten!
  • Updated to the latest Box2D SVN r141 -- there were some changes upstream, including:
    • A new RopeJoint (maximum distance constraint)
    • Allocator, joint and some other fixes and improvements
  • Working b2LoopShapes -- featuring smooth collision both inside and out (you can see these in the character collision test)
  • Added the rope joint test
  • PyQt4 framework fixes
    • Some properties are changeable now (*)
    • Fixed updated circle radii between calls
  • Epydoc documentation for the 2.1 branch was generated by using the Doxygen documentation for the C++ side (which, although it is included in the SVN, is usually not at all necessary for pybox2d users).
  • An up-to-date version of the compiled library is included on the SVN
    • It's here. For those of you who would like to help test, is this convenient enough? Or is it "give me an archive or test the damn thing yourself"? :)
I think it's almost time that the trunk from early last year to be finally overwritten. I don't think there are too many project requirements with the old library anymore. Thoughts?

(*) Any idea how to properly size a QListWidget in a QTreeWidget cell? I think sizing widgets appropriately is what most frustrates me about Qt.

Friday, October 1, 2010

Not quite what you were hoping for, but...

Recently, I haven't had much time to work on pybox2d. And when I say 'not much', I mean just about zero.

In any case, I know that there are probably a couple people out there that are anxious to try the new version but don't want to go through installing SWIG, compiling, etc. It's a pain, I realize.

The other day Fahri, creator of Mekanimo --- the only commercial product to use pybox2d that I know of -- asked me if I had a binary he could test of the new branch. I threw a simple Python 2.6 (win32) package together, and thought that the rest of you might like to give it a go also.

The library itself is contained in the archive, so there's no need to install it. The redesigned testbed examples are in there, and you can experiment with the new syntax to your heart's content. For any of the tests, simply run: python test_Web.py . You can also specify the (incomplete) pyglet or pyqt4 back-ends with: python test_Web.py --backend pyglet or '--backend pyqt4' for example.

I only ask that if you give it a try, please at least run python run_unit_tests.py and see if you get any errors. Also, please note that this is alpha-quality and does not have much documentation.

Download here.

Sunday, July 11, 2010

2.1.0 Branch Status


Hi!

How's everything? Make any games lately? Me? Oh, I'm still alive and kicking over here.

So anyway, here are some of the updates following my last post about r246 a good 6 months ago (all of those changes are still mostly true).

  • Updated to the latest Box2D svn, added loop/edge shapes (edges work, loops do not)
  • kwargs for all functions
  • Reworked the framework system to be more OO-friendly -- pyglet/pygame frameworks are derived from a base class now
  • Pyglet is basically working with the newest version 1.1.4 -- but it's got some major issues that need to be dealt with. If there are any Pyglet experts out there, let me know.
  • Added a PyQt4 framework with basic functionality. I have a few plans for it... [pictured above]
  • world.CreateCircleShape, world.CreatePolygonShape, and so on, which allow kwargs for both the shapes and the fixture, so that things like this are possible:
    world=b2World
    world.CreatePolygonFixture(box=(1, 1), friction=0.2, density=1.0)

    remember that 'box' is a property from the polygon shape, and 'friction' and 'density' are from the fixture definition.
  • Experimental 'b2' namespace:
    > from Box2D.b2 import *
    > vec2(1,1)
    b2Vec2(1,1)
  • CreateStaticBody and CreateDynamicBody, and other changes to CreateBody and CreateFixture. There's also world.Create*Joint(), body.CreateShapesFromFixtures, and probably some others
New tests:
  • Tiles
  • Pinball
  • CharacterCollision
  • Bullet
  • Most of the old ones, converted to the new style
Still needs a lot of work. But if you ever want this version to see the light of day, please do give it a try and let me know what you think (and of course if you have any issues, which you likely will):
% svn checkout http://pybox2d.googlecode.com/svn/branches/box2d_2.1/ pybox2d-svn

Also, given that the Box2D wiki has been down for ages, I guess it's a good time to find a new place to host a pybox2d wiki. Any recommendations?