How to make perfect collision detection with Rabbyt?

I started to study the Rabbyt library, and so far I really like to use it in combination with a picket.

One thing that doesn't seem to be implemented in the library is the perfect detection of collisions between sprites. I have two problems when implementing this.

First of all, I use pyglet to load textures for sprites, but I cannot figure out how to get bit masks from textures (very limited knowledge of OpenGL is the main problem). BufferImageMask seems to be derived from an AbstractImage instance, but not from the texture itself. What is the right way to do this?

Secondly, what are the different ways to implement a real collision detection algorithm? What interests me the most is if there are any ways / options, since everything I have read so far looks like this:

Collision Detection Algorithm @ gamedev.net

I just try not to miss any important information, the algorithm itself is robust.

Thanks in advance!

PS I am coding in Python 2.7, but I would prefer to implement a realistic pixel collision detection algorithm in C and use it as an extension.

Update

I managed to get perfect collision detection with non-rotating sprites:

    r1 = collision[entity1].aabb
    r2 = collision[entity2].aabb
    sprite1 = renderable[entity1].sprite
    sprite2 = renderable[entity2].sprite
    ri = r1.intersect(r2)


    offx1, offy1 = int(ri.left - r1.left), int(ri.top - r1.top)
    offx2, offy2 = int(ri.left - r2.left), int(ri.top - r2.top)

    d1 = sprite1.texture.get_image_data().get_data('A', sprite1.texture.width)
    d2 = sprite2.texture.get_image_data().get_data('A', sprite2.texture.width)

    p1 = cast(d1, POINTER(c_ubyte))
    p2 = cast(d2, POINTER(c_ubyte))

    for i in range(0, int(ri.width)):
        for j in range(0, int(ri.height)):
            c1, c2 = 0, 0
            x1 = offx1+i
            y1 = (j+offy1)*sprite1.texture.width
            x2 = offx2+i
            y2 = (offy2+j)*sprite2.texture.width

            if x1 >= 0 and y1 >= 0:
                c1 = p1[x1 + y1]

            if x2 >= 0 and y2 >= 0:
                c2 = p2[x2 + y2]

            if c1>0 and c2 >0:
                pairs.add(pair)
                break

collision and renderable are simply dicts of objects that are associated with this object. The algorithm is a modified version of this: Optimal Piglet Pixel Collision

( , ), ( , 100 ) .

+3
2

:

...

middleX1 = sprite1.texture.width/2
middleY1 = sprite1.texture.height/2

middleX2 = sprite2.texture.width/2
middleY2 = sprite2.texture.height/2

angle1 = ?   #Radians.
vX11 = -cos(angle1)
vY11 = -sin(angle1)
vX12 = -cos(angle1 + math.pi/2)
vY12 = -sin(angle1 + math.pi/2)

angle2 = ?   #Radians.
vX21 = -cos(angle2)
vY21 = -sin(angle2)
vX22 = -cos(angle2 + math.pi/2)
vY22 = -sin(angle2 + math.pi/2)

for ...
    for ...

        ...

        aX1 = x1 - middleX1
        aY1 = j+offy1 - middleY1
        aX2 = x2 - middleX2
        aY2 = j+offy2 - middleY2

        tX1 = vX11*aX1 + vY11*aY1 + middleX1
        tY1 = vX12*aX1 + vY12*aX1 + middleY1

        tX2 = vX21*aX2 + vY21*aY2 + middleX2
        tY2 = vX22*aX2 + vY22*aX2 + middleY2

        #Use tX* and tY* for indexing. Remember to multiply tY* with width.

        ...

, , . , . , Python, .

, , , , , , .

+1

, , ( , "get_image_data" Texture -API, , ?), .

, , , , : OpenGL, , . , , , . .

, ; , , . , , - , , . , , , , .

, ; PoxelColl. , , . , Python; Scala -, Jython ++, Python, . , , , , , .

+1

All Articles