コード例 #1
0
    def test_should_return_a_2d_numpy_array(self):
        vectors = [
            Vec3(1, 4, 0),
            Vec3(1, 6, -5),
            Vec3(-4, 1, 7),
        ]
        result = pathing.get_fortran_array(vectors)

        assert type(result) == np.ndarray
        assert result.size == 9
        for thing in result:
            print(thing, type(thing))
            assert type(thing) == np.ndarray
コード例 #2
0
ファイル: bot.py プロジェクト: danielmoniz/rocket_league_bots
 def filter_boost(self, boost):
     speed = Vec3(self.car.physics.velocity).length()
     if self.car.is_super_sonic:
         print(f"Going supersonic! Velocity: {speed}")
         return False
     print(f"Velocity: {speed}")
     return False # for now, prevent boosting
     return boost
コード例 #3
0
    def __init__(self, rotation):
        self.yaw = float(rotation.yaw)
        self.roll = float(rotation.roll)
        self.pitch = float(rotation.pitch)

        cr = math.cos(self.roll)
        sr = math.sin(self.roll)
        cp = math.cos(self.pitch)
        sp = math.sin(self.pitch)
        cy = math.cos(self.yaw)
        sy = math.sin(self.yaw)

        self.forward = Vec3(cp * cy, cp * sy, sp)
        self.right = Vec3(cy * sp * sr - cr * sy, sy * sp * sr + cr * cy,
                          -cp * sr)
        self.up = Vec3(-cr * cy * sp - sr * sy, -cr * sy * sp + sr * cy,
                       cp * cr)
コード例 #4
0
ファイル: bot.py プロジェクト: danielmoniz/rocket_league_bots
    def set_game_info(self, packet):
        self.packet = packet
        self.car = packet.game_cars[self.index]
        self.opposing_goal = self.game_info['field_info'].goals[1 - self.car.team]
        car_orientation = Orientation(self.car.physics.rotation)
        ball_location = Vec3(packet.game_ball.physics.location)
        car_location = Vec3(self.car.physics.location)

        self.game_info.update({
            'car': self.car,
            'car_location': car_location,
            'car_orientation': car_orientation,
            'car_direction': car_orientation.forward,
            'ball_location': ball_location,
            'ball_to_goal': (Vec3(self.opposing_goal.location) - ball_location).normalized(),
            'distance_from_ball': (car_location - ball_location).length(),
        })
コード例 #5
0
def relative_location(center: Vec3, ori: Orientation, target: Vec3) -> Vec3:
    """
    Returns target as a relative location from center's point of view, using the given orientation. The components of
    the returned vector describes:

    * x: how far in front
    * y: how far right
    * z: how far above
    """
    x = (target - center).dot(ori.forward)
    y = (target - center).dot(ori.right)
    z = (target - center).dot(ori.up)
    return Vec3(x, y, z)
コード例 #6
0
 def test_should_return_five_coordinates(self):
     vec1, vec2, vec3, vec4 = (Vec3(1), Vec3(2), Vec3(3), Vec3(4))
     result = pathing.get_shooting_vectors(vec1, vec2, vec3, vec4, self.scale)
     assert len(result) == 3
コード例 #7
0
def convert_coordinate_to_vector(coord):
    return Vec3(
        coord[0][0],
        coord[1][0],
        max(coord[2][0], 25),
    )
コード例 #8
0
def draw_debug(player, renderer, car, action_display, planned_curve=None):
    car_location = player.game_info['car_location']
    ball_location = player.game_info['ball_location']
    car_direction = player.game_info['car_direction']
    renderer.begin_rendering()

    # print the action that the bot is taking
    renderer.draw_string_3d(car_location, 2, 2, action_display,
                            renderer.white())

    # output the intended curve of the bot
    if planned_curve is not None:
        segments = get_segments(planned_curve)
        final_vector = segments[-1]
        previous_distance = (car_location - final_vector).length()
        previous_vector = car_location
        for vector in segments:
            colour = renderer.white()
            new_distance = (vector - final_vector).length()
            if new_distance > previous_distance:
                colour = renderer.red()
            renderer.draw_line_3d(previous_vector, vector, colour)
            previous_vector = vector
            previous_distance = new_distance

    # draw line vertically from car's various points
    car_length = 125
    car_width = 60
    line_length = 20
    renderer.draw_line_3d(car_location, car_location + Vec3(0, 0, line_length),
                          renderer.white())
    front_of_car = car_location + 75 * car_direction
    renderer.draw_line_3d(front_of_car, front_of_car + Vec3(0, 0, line_length),
                          renderer.white())
    back_of_car = car_location - 50 * car_direction
    renderer.draw_line_3d(back_of_car, back_of_car + Vec3(0, 0, line_length),
                          renderer.white())

    left = Vec3(-car_direction.y * math.sin(-math.pi / 2),
                car_direction.x * math.sin(-math.pi / 2))
    left_of_car = car_location + (car_width / 2) * left
    renderer.draw_line_3d(left_of_car, left_of_car + Vec3(0, 0, line_length),
                          renderer.white())
    right_of_car = car_location - (car_width / 2) * left
    renderer.draw_line_3d(right_of_car, right_of_car + Vec3(0, 0, line_length),
                          renderer.white())

    # draw line vertically from ball
    renderer.draw_line_3d(ball_location,
                          ball_location + Vec3(0, 0, line_length),
                          renderer.white())

    # @TEST: draw line out of the right side of the car
    car_right = player.game_info['car_orientation'].right
    renderer.draw_line_3d(car_location, car_location + car_right * line_length,
                          renderer.blue())

    # experiment: draw lines along goal -------------------------
    # Horizontal line along center of goal:
    middle_left = Vec3(player.opposing_goal.location) + Vec3(
        -player.goal_width / 2, 0, 0)
    middle_right = middle_left + Vec3(player.goal_width, 0, 0)

    # Vertical line along left of goal:
    bottom_left = middle_left + Vec3(0, 0, -player.goal_height / 2)
    top_left = middle_left + Vec3(0, 0, player.goal_height / 2)

    # Vertical line along right of goal:
    top_right = top_left + Vec3(player.goal_width, 0, 0)
    bottom_right = bottom_left + Vec3(player.goal_width, 0, 0)

    renderer.draw_line_3d(middle_left, middle_right, renderer.white())
    renderer.draw_line_3d(bottom_left, top_left, renderer.white())
    renderer.draw_line_3d(bottom_right, top_right, renderer.white())

    renderer.end_rendering()
コード例 #9
0
 def setUp(self):
     self.vec_x = Vec3(10, 0, 0)
     self.vec1 = Vec3(1, 2, 3)
     self.vec45 = Vec3(2, -2, 0)
     self.vec_z = Vec3(0, 0, 5)
コード例 #10
0
 def test_flat(self):
     self.assertEqual(self.vec1.flat(), Vec3(1, 2, 0))
コード例 #11
0
 def test_cross(self):
     cross = self.vec_z.cross(self.vec1)
     self.assertEqual(cross, Vec3(-10, 5, 0))
コード例 #12
0
 def test_vec_add(self):
     vec_sum = self.vec1 + self.vec2
     self.assertEquals(vec_sum, Vec3(11, 22, 33))
コード例 #13
0
 def setUp(self):
     self.vec1 = Vec3(1, 2, 3)
     self.vec2 = Vec3(10, 20, 30)
コード例 #14
0
 def test_vec_add_negative(self):
     neg_vec = -self.vec1
     self.assertEqual(self.vec2 + neg_vec, Vec3(9, 18, 27))
コード例 #15
0
 def test_vec_subtract_negative(self):
     neg_vec = -self.vec1
     self.assertEquals(self.vec2 - neg_vec, Vec3(11, 22, 33))
コード例 #16
0
 def test_vec_negate(self):
     self.assertEquals(-self.vec1, Vec3(-1, -2, -3))
コード例 #17
0
 def test_vec_subtract(self):
     self.assertEqual(self.vec2 - self.vec1, Vec3(9, 18, 27))
コード例 #18
0
 def test_normalized(self):
     self.assertEqual(self.vec_x.normalized(), Vec3(1, 0, 0))
コード例 #19
0
 def test_vec_equals(self):
     self.assertEquals(self.vec1, Vec3(1, 2, 3))