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

Re: [pygame] Physics, collision detection etc?



hi,

Note, that you can find contact normals with the mask module. See mask example.

For some types of games, per pixel collision detection is fast enough.
 It uses rect bounding boxes as a first pass, so mostly it's not much
slower than rect collision detection.  Assuming you are working in 2d,
and you cache the mask(not regenerating it every frame) that is.
However the mask.from_surface routine is fairly fast, it could do with
some more optimization.

For opengl, it'd be interesting to do it in a shader too... since then
you could just reuse your drawing routines to draw your
objects(sprites) into a buffer (each with a different color), then use
a shader to find all of the contact normals.  That way your collision
could be pixel perfect, even with different methods of
drawing(cartoon, glow, and other shaders) where the polygon
representation is not correct.


cheers,




On Wed, Oct 8, 2008 at 9:46 PM, Greg Ewing <greg.ewing@xxxxxxxxxxxxxxxx> wrote:
> Nirav Patel wrote:
>
>> If the polygons are Surfaces or can be turned into Surfaces, they can
>> be turned into Masks to do pixel collision.
>>
>> On Tue, Oct 7, 2008 at 11:21 AM, Peter Gebauer
>> <peter.gebauer@xxxxxxxxxxxxxxxxxxxxx> wrote:
>>
>> > Yep, but as I said, I need to find colliding polygons, not pixels.
>
> Pixel collision isn't suitable for all purposes,
> e.g. if you need to find contact normals for
> physics calculations.
>