Example #1
0
    def cast_ray(self, phys_space, origin, targets, single=False):
        collisions = []
        view_dist = 500
        a_offset = 0.00001
        col_group = 2
        for target in targets:
            a = -get_angle(*origin, *target)
            c1p = self.move_in_angle(a, origin, view_dist)
            c1 = phys_space.segment_query_first(
                origin, c1p, group=col_group
            )
            if c1:
                hp = c1.get_hit_point()
                collisions.append((hp.x, hp.y, a))
            else:
                collisions.append((c1p[0], c1p[1], a))
            if not single:
                a2 = a - a_offset
                c2p = self.move_in_angle(a2, origin, view_dist)
                # print(pos, mp, c2p)
                c2 = phys_space.segment_query_first(
                    origin, c2p, group=col_group
                )
                a3 = a + a_offset
                c3p = self.move_in_angle(a3, origin, view_dist)
                c3 = phys_space.segment_query_first(
                    origin, c3p, group=col_group
                )
                if c2:
                    hp = c2.get_hit_point()
                    collisions.append((hp.x, hp.y, a2))
                else:
                    collisions.append((*c2p, a2))
                if c3:
                    hp = c3.get_hit_point()
                    collisions.append((hp.x, hp.y, a3))
                else:
                    collisions.append((*c3p, a3))

        return collisions
Example #2
0
 def __init__(self, p1, p2):
     self.p1, self.p2 = p1, p2
     self.angle = get_angle(*p1, *p2)