Exemple #1
0
    def simulate_landing(self):
        dummy = Car(self.car)
        self.trajectory = [vec3(dummy.position)]
        self.landing = False
        collision_normal: Optional[vec3] = None

        dt = 1 / 60
        simulation_duration = 0.8
        for i in range(int(simulation_duration / dt)):
            dummy.step(Input(), dt)
            self.trajectory.append(vec3(dummy.position))

            collision_sphere = sphere(dummy.position, 50)
            collision_ray = Field.collide(collision_sphere)
            collision_normal = collision_ray.direction

            if (norm(collision_normal) > 0.0
                    or dummy.position[2] < 0) and i > 20:
                self.landing = True
                self.landing_pos = dummy.position
                break

        if self.landing:
            u = collision_normal
            f = normalize(dummy.velocity - dot(dummy.velocity, u) * u)
            l = normalize(cross(u, f))
            self.aerial_turn.target = mat3(f[0], l[0], u[0], f[1], l[1], u[1],
                                           f[2], l[2], u[2])
        else:
            target_direction = normalize(
                normalize(self.car.velocity) - vec3(0, 0, 3))
            self.aerial_turn.target = look_at(target_direction, vec3(0, 0, 1))
Exemple #2
0
 def set_drone_states(self, drones: List[Drone]):
     for i, drone in enumerate(drones):
         if i < len(self.shape):
             drone.position = self.origin + self.shape[i]
             drone.orientation = mat3(1, 0, 0, 0, 1, 0, 0, 0, 1)
             drone.velocity = vec3(0, 0, 0)
         else:
             drone.position = vec3(0, 0, 3000)
def roll_away_from_target(target, theta, game_info):
    '''
    Returns an orientation mat3 for an air roll shot.  Turns directly away from the dodge direction (target) by angle theta
    Target can either be RLU vec3, or CowBot Vec3.
    '''

    starting_forward = game_info.utils_game.my_car.forward()
    starting_left = game_info.utils_game.my_car.left()
    starting_up = game_info.utils_game.my_car.up()
    starting_orientation = mat3(starting_forward[0], starting_left[0],
                                starting_up[0], starting_forward[1],
                                starting_left[1], starting_up[1],
                                starting_forward[2], starting_left[2],
                                starting_up[2])
    if type(target) == vec3:
        target = vec3_to_Vec3(target, game_info.team_sign)
    car_to_target = Vec3_to_vec3((target - game_info.me.pos).normalize(),
                                 game_info.team_sign)
    axis = theta * cross(car_to_target, starting_up)
    return dot(axis_to_rotation(axis), starting_orientation)
def rot_to_mat3(rot, team_sign):
    return mat3(team_sign * rot.front.x, team_sign * rot.left.x,
                team_sign * rot.up.x, team_sign * rot.front.y,
                team_sign * rot.left.y, team_sign * rot.up.y, rot.front.z,
                rot.left.z, rot.up.z)
Exemple #5
0
def rot_to_mat3(rot):
    return mat3( rot.front.x, rot.left.x, rot.up.x,
                 rot.front.y, rot.left.y, rot.up.y,
                 rot.front.z, rot.left.z, rot.up.z )
Exemple #6
0
from rlutilities.linear_algebra import vec3, mat3
from rlutilities.simulation import Game, Car, Ball, intersect

Game.set_mode("dropshot")

c = Car()

c.location = vec3(-164.13, 0, 88.79)
c.velocity = vec3(1835.87, 0, 372.271)
c.angular_velocity = vec3(0, 3.78721, 0)
c.rotation = mat3(0.9983, -5.23521e-6, 0.0582877, 5.5498e-6, 1.0, -5.23521e-6,
                  -0.0582877, 5.5498e-6, 0.9983)

b = Ball()

b.location = vec3(0, 0, 150)
b.velocity = vec3(0, 0, 0)
b.angular_velocity = vec3(0, 0, 0)

print("before:")
print(b.location)
print(b.velocity)
print(b.angular_velocity)
print("overlapping: ", intersect(c.hitbox(), b.hitbox()))

print()

b.step(0.008333, c)

print("after:")
print(b.location)
 def to_rot_mat(self):
     return mat3(
         self.forward[0], self.right[0], self.up[0],
         self.forward[1], self.right[1], self.up[1],
         self.forward[2], self.right[2], self.up[2]
     ) 
from rlutilities.linear_algebra import vec3, vec2, mat3, mat2
from rlutilities.mechanics import Dodge
from rlutilities.simulation import Car

c = Car()

c.time = 0.0
c.location = vec3(1509.38, -686.19, 17.01)
c.velocity = vec3(-183.501, 1398., 8.321)
c.angular_velocity = vec3(0, 0, 0)
c.rotation = mat3(-0.130158, -0.991493, -0.00117062, 0.991447, -0.130163,
                  0.00948812, -0.00955977, 0.0000743404, 0.999954)
c.dodge_rotation = mat2(-0.130163, -0.991493, 0.991493, -0.130163)

c.on_ground = True
c.jumped = False
c.double_jumped = False
c.jump_timer = -1.0
c.dodge_timer = -1.0

dodge = Dodge(c)
dodge.direction = vec2(-230.03, 463.42)
dodge.duration = 0.1333
dodge.delay = 0.35

f = open("dodge_simulation.csv", "w")
for i in range(300):
    dodge.step(0.008333)
    print(c.time, dodge.controls.jump, dodge.controls.pitch,
          dodge.controls.yaw)
    c.step(dodge.controls, 0.008333)
Exemple #9
0
def three_vec3_to_mat3(f: vec3, l: vec3, u: vec3) -> mat3:
    """Create a mat3 from three vec3 by taking them as columns."""
    return mat3(f[0], l[0], u[0], f[1], l[1], u[1], f[2], l[2], u[2])