diff options
author | Baitinq <you@example.com> | 2022-02-09 19:46:22 +0000 |
---|---|---|
committer | Baitinq <you@example.com> | 2022-02-09 19:46:22 +0000 |
commit | b1e21900e24d88e13e9a0e416e737f6f101583fa (patch) | |
tree | 3f31baccd1234a31fc141ff1ea761a393373a804 | |
parent | Implemented basic version of x movement (diff) | |
download | OSLS-b1e21900e24d88e13e9a0e416e737f6f101583fa.tar.gz OSLS-b1e21900e24d88e13e9a0e416e737f6f101583fa.tar.bz2 OSLS-b1e21900e24d88e13e9a0e416e737f6f101583fa.zip |
Add heading component to the x movement
-rw-r--r-- | main.py | 9 | ||||
-rw-r--r-- | rocket.py | 2 | ||||
-rw-r--r-- | simulation.py | 13 | ||||
-rw-r--r-- | stage.py | 8 |
4 files changed, 22 insertions, 10 deletions
diff --git a/main.py b/main.py index c369814..125caa4 100644 --- a/main.py +++ b/main.py @@ -128,7 +128,7 @@ def draw_simulation(simulation_display: type[pygame.Surface], simulation: type[S #draw stats text font = pygame.font.SysFont("Comic Sans MS", 30) - curr_thrust = simulation.rocket.current_stage().current_thrust(simulation.body.g(simulation.universe.G, simulation.y)) + curr_thrust = simulation.rocket.current_stage().current_thrust(simulation.body.g(simulation.universe.G, simulation.y), simulation.heading) g = simulation.body.g(simulation.universe.G, simulation.y) simulation_display.blit(font.render("Simulation time: {:.0f}s".format(simulation.time), False, (255, 255, 255)),(0,0)) @@ -138,15 +138,16 @@ def draw_simulation(simulation_display: type[pygame.Surface], simulation: type[S simulation_display.blit(font.render("Speed y: {:.0f}m/s".format(simulation.speed_y), False, (255, 255, 255)),(0,160)) simulation_display.blit(font.render("Acceleration x: {:.2f}m/s2".format(simulation.acceleration_x), False, (255, 255, 255)),(0,200)) simulation_display.blit(font.render("Acceleration y: {:.2f}m/s2".format(simulation.acceleration_y), False, (255, 255, 255)),(0,240)) - simulation_display.blit(font.render("Thrust x: {:.0f}N".format(simulation.rocket.current_stage().current_thrust(g)[0]), False, (255, 255, 255)),(0,280)) - simulation_display.blit(font.render("Thrust y: {:.0f}N".format(simulation.rocket.current_stage().current_thrust(g)[1]), False, (255, 255, 255)),(0,320)) + simulation_display.blit(font.render("Thrust x: {:.0f}N".format(simulation.rocket.current_stage().current_thrust(g, simulation.heading)[0]), False, (255, 255, 255)),(0,280)) + simulation_display.blit(font.render("Thrust y: {:.0f}N".format(simulation.rocket.current_stage().current_thrust(g, simulation.heading)[1]), False, (255, 255, 255)),(0,320)) simulation_display.blit(font.render("Altitude: {:.0f}m".format(simulation.y), False, (255, 255, 255)),(0,360)) simulation_display.blit(font.render("Fuel in stage: {:.0f}kg".format(simulation.rocket.current_stage().fuel_mass), False, (255, 255, 255)),(0,400)) simulation_display.blit(font.render("Stage mass: {:.0f}kg".format(simulation.rocket.current_stage().total_mass()), False, (255, 255, 255)),(0,440)) simulation_display.blit(font.render("Rocket mass: {:.0f}kg".format(simulation.rocket.total_mass()), False, (255, 255, 255)),(0,480)) simulation_display.blit(font.render("Stage number: {:.0f}".format(simulation.rocket.stages_spent), False, (255, 255, 255)),(0,520)) simulation_display.blit(font.render("Throttle: {:.0f}%".format(simulation.rocket.current_stage().throttle), False, (255, 255, 255)),(0,560)) - simulation_display.blit(font.render("Gimbal: {:.0f}deg".format(simulation.rocket.current_stage().gimbal), False, (255, 255, 255)),(0,600)) + simulation_display.blit(font.render("Gimbal: {:.2f}deg".format(simulation.rocket.current_stage().gimbal), False, (255, 255, 255)),(0,600)) + simulation_display.blit(font.render("Heading: {:.2f}deg".format(simulation.heading), False, (255, 255, 255)),(0,640)) #draw rocket first_stage_height = 90 #TODO diff --git a/rocket.py b/rocket.py index de17812..962678b 100644 --- a/rocket.py +++ b/rocket.py @@ -7,8 +7,6 @@ class Rocket(): self.stages_spent = 0 self.payload_mass = payload_mass - self.heading_angle = 0 #TODO: TODOODODODODODODODODODOOD - def current_stage(self) -> type[Stage]: return self.stages[0] diff --git a/simulation.py b/simulation.py index a4a7aa6..70ea171 100644 --- a/simulation.py +++ b/simulation.py @@ -1,3 +1,4 @@ +import math from dataclasses import dataclass from universe import Universe @@ -24,6 +25,8 @@ class Simulation(): self.acceleration_x = 0 self.acceleration_y = 0 + self.heading = 0 + #simulation logic def tick(self, delta: int) -> None: current_stage = self.rocket.current_stage() @@ -37,7 +40,7 @@ class Simulation(): force_x = 0 force_y = 0 if fuel_used > 0: - total_thrust = current_stage.current_thrust(self.body.g(self.universe.G, self.y)) + total_thrust = current_stage.current_thrust(self.body.g(self.universe.G, self.y), self.heading) force_x = total_thrust[0] force_y = total_thrust[1] @@ -90,6 +93,14 @@ class Simulation(): print("Speed x: " + str(self.speed_x)) print("Speed y: " + str(self.speed_y)) + #TODO: HEADING behaves a bit weird, just a bit and it goes forever and hard to cancel. WELL CALCULATED OR IMPLEMENTED? + #speedx / speedy + #1 = 45 + #-1 = -45 + #0 = 90 + self.heading = math.degrees(self.speed_x / self.speed_y) #TODO? con speed, y luego heading influences thrust (gimbal), so pass as a parameter to func + print("Heading: " + str(self.heading)) + #update position based on velocity and delta self.x += self.speed_x * delta diff --git a/stage.py b/stage.py index e2c32d1..bb05eaf 100644 --- a/stage.py +++ b/stage.py @@ -22,11 +22,13 @@ class Stage(): def total_mass(self): return (self.stage_mass + self.fuel_mass) - def current_thrust(self, g: float) -> (float, float): + def current_thrust(self, g: float, heading: int) -> (float, float): if(self.engines_on and self.fuel_mass > 0): total_thrust = self.engine.thrust(self.throttle, g) * self.engine_number - thrust_x = (math.sin(math.radians(self.gimbal)) * total_thrust) - thrust_y = (math.cos(math.radians(self.gimbal)) * total_thrust) + #gimbal and heading components + thrust_x = (math.sin(math.radians(self.gimbal + heading)) * total_thrust) + thrust_y = (math.cos(math.radians(self.gimbal + heading)) * total_thrust) + return (thrust_x, thrust_y) else: return (0, 0) |