def test_AABBCircle(self):
        aabb = pycrcc.RectAABB(2, 3, 3, 1.8)
        aabb2 = pycrcc.RectAABB(2, 3, 3, 1.7)
        circ = pycrcc.Circle(2.5, 6, 7)

        self.assertEqual(aabb.collide(circ), 1)
        self.assertEqual(aabb2.collide(circ), 0)
Ejemplo n.º 2
0
    def build_quadtree(depth, rx, ry, x, y, params):
        max_depth = params.get('max_depth', 10)
        build_antiquads = params.get('build_antiquads', False)
        speedup = params.get('speedup', False)

        quad = pycrcc.RectAABB(rx, ry, x, y)
        if quad.collide(road):
            if depth >= max_depth or (speedup and not quad.collide(rectangles)):
                if (build_antiquads):
                    antiquads.add_shape(quad)
            else:
                depth += 1

                def recursive(x, y):
                    build_quadtree(depth, rx, ry, x, y, params)

                # expand
                rx /= 2
                ry /= 2
                recursive(x + rx, y + ry)
                recursive(x - rx, y + ry)
                recursive(x + rx, y - ry)
                recursive(x - rx, y - ry)
        else:
            quads.add_shape(quad)
    def test_OBBAABB(self):
        obb2 = pycrcc.RectOBB(1, 2, 0, 9, 14)
        aabb2 = pycrcc.RectAABB(1, 1, 11.1, 16)
        obb3 = pycrcc.RectOBB(1, 2, 0.2, 9, 14)
        obb4 = pycrcc.RectOBB(1, 2, -0.2, 9, 14)

        self.assertEqual(obb2.collide(aabb2), 0)
        self.assertEqual(obb3.collide(aabb2), 0)
        self.assertEqual(obb4.collide(aabb2), 1)
Ejemplo n.º 4
0
def create_collision_object_rectangle(rect,
                                      params=None,
                                      collision_object_func=None):
    if math.isclose(rect.orientation, 0.0):
        return pycrcc.RectAABB(0.5 * rect.length, 0.5 * rect.width,
                               rect.center[0], rect.center[1])
    else:
        return pycrcc.RectOBB(0.5 * rect.length, 0.5 * rect.width,
                              rect.orientation, rect.center[0], rect.center[1])
    def test_cc(self):

        aabb = pycrcc.RectAABB(2, 3, 3, 1.8)
        aabb2 = pycrcc.RectAABB(2, 3, 3, 1.7)
        circ = pycrcc.Circle(2.5, 6, 7)

        cc = pycrcc.CollisionChecker()
        cc.add_collision_object(aabb)
        obb1 = pycrcc.RectOBB(2, 1, 1.5, 6.0, 0)
        obb2 = pycrcc.RectOBB(2, 1, 1.5, 6.0, 20)

        self.assertEqual(cc.collide(circ), 1)

        tvo1 = pycrcc.TimeVariantCollisionObject(1)
        tvo1.append_obstacle(pycrcc.RectOBB(2, 1, 0.0, 2.0, 5))  # time step 1
        tvo1.append_obstacle(pycrcc.RectOBB(2, 1, 0.0, 2.5, 5))  # time step 2
        tvo1.append_obstacle(pycrcc.RectOBB(2, 1, 0.0, 3, 5))  # time step 3
        tvo1.append_obstacle(pycrcc.RectOBB(2, 1, 0.0, 3.5, 5))  # time step 4
        tvo1.append_obstacle(pycrcc.RectOBB(2, 1, 0.0, 4, 5))  # time step 5
        tvo1.append_obstacle(pycrcc.RectOBB(2, 1, 0.0, 4.5, 5))  # time step 6
        tvo1.append_obstacle(pycrcc.RectOBB(2, 1, 0.0, 5, 5))  # time step 7
        tvo1.append_obstacle(pycrcc.RectOBB(2, 1, 0.0, 5.5, 5))  # time step 8

        # Time variant obstacle that starts at time 4
        tvo2 = pycrcc.TimeVariantCollisionObject(4)
        tvo2.append_obstacle(pycrcc.RectOBB(2, 1, 1.5, 6.0, 0))  # time step 4
        tvo2.append_obstacle(pycrcc.RectOBB(2, 1, 1.5, 6.0, 2))  # time step 5
        tvo2.append_obstacle(pycrcc.RectOBB(2, 1, 1.5, 6.0, 3))  # time step 6
        tvo2.append_obstacle(pycrcc.RectOBB(2, 1, 1.5, 6.0, 4))  # time step 7
        tvo2.append_obstacle(pycrcc.RectOBB(2, 1, 1.5, 6.0, 5))  # time step 8
        tvo2.append_obstacle(pycrcc.RectOBB(2, 1, 1.5, 6.0, 6))  # time step 9
        tvo2.append_obstacle(pycrcc.RectOBB(2, 1, 1.5, 6.0, 7))  # time step 10

        cc = pycrcc.CollisionChecker()
        cc.add_collision_object(tvo2)
        obb1 = pycrcc.RectOBB(2, 1, 1.5, 6.0, 0)
        obb2 = pycrcc.RectOBB(2, 1, 1.5, 6.0, 20)
        self.assertEqual(tvo2.collide(obb1), 1)
        self.assertEqual(cc.collide(obb1), 1)
        self.assertEqual(cc.collide(obb2), 0)

        cc2 = pycrcc.CollisionChecker()

        cc2.add_collision_object(obb2)

        self.assertEqual(cc2.collide(tvo2), 0)

        cc2.add_collision_object(obb1)

        self.assertEqual(cc2.collide(tvo2), 1)

        cc3 = pycrcc.CollisionChecker()

        cc3.add_collision_object(tvo1)

        self.assertEqual(cc3.collide(tvo2), 1)

        tvo3 = pycrcc.TimeVariantCollisionObject(12)
        tvo3.append_obstacle(pycrcc.RectOBB(2, 1, 1.5, 6.0, 0))
        tvo3.append_obstacle(pycrcc.RectOBB(2, 1, 1.5, 6.0, 2))

        cc4 = pycrcc.CollisionChecker()
        cc4.add_collision_object(tvo2)
        cc4.add_collision_object(pycrcc.RectOBB(2, 1, 1.5, 6.0, 0))
        self.assertEqual(cc4.collide(tvo3), 1)
 def create_random_aabb(self):
     center = self.generate_random_vector()
     rad_x = abs(self.generate_random_xvalue())
     rad_y = abs(self.generate_random_yvalue())
     return pycrcc.RectAABB(rad_x, rad_y, center[0], center[1])