[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] pixel-perfect physics?



Certainly not an easy problem, especially if the shapes are convex.  A
sort of hackish way to do this in PyBox2D, if the shapes aren't
already known polygons, is to use Mask.outline() to get some points on
the outline of your object and create a Box2D Poly out of a bunch of
thin connected rects shaped like your object.  This is a really bad
description, but check out this thread:
http://www.box2d.org/forum/viewtopic.php?f=8&t=563 .

Elements, a wrapper for PyBox2D, has functions similar to this written
that you may also want to look at.  Take a look at complexPoly and
concavePoly in http://dev.laptop.org/git?p=activities/physics;a=blob;f=elements/add_objects.py;h=3842b750a8dfe46d9400bab1c6ff5d6206dc718f;hb=HEAD

This still isn't pixel perfect, but accurate physics and pixel perfect
collision do not go together.

Nirav

On Fri, Oct 24, 2008 at 4:50 PM, Michael George <mdgeorge@xxxxxxxxxxxxxx> wrote:
> Has anyone had experience using pixel-perfect collision detection with a 2d
> physics engine?  I've looked into pymunk, but that seems to have baked-in
> collision detection so I don't see how to do it.  ODE has rudimentary python
> bindings and has separate collision detection, but it's intended for 3d and
> the 2d support hasn't been added to the python port yet.  There's the GSOC
> pygame physics project, but I don't see docs for that and can't tell if it
> would be suitable.
>
> Also, as far as doing the collision detection, AFAICT there isn't a way to
> rotate a mask, or to do collision detection on rotated objects.  Are there
> plans for something like this, or am I stuck with using an image, rotating
> it with the transform package and then using Mask.from_surface?
>
> Thanks.
>
> --Mike
>