diff options
author | Baitinq <you@example.com> | 2022-02-11 12:10:35 +0000 |
---|---|---|
committer | Baitinq <you@example.com> | 2022-02-11 12:13:21 +0000 |
commit | dc1cc59362efe5980465cd358b9621bb13825c35 (patch) | |
tree | 5065fe57344af4b046d044c8113401d37bc08134 | |
parent | Added specific x and y drag (x drag coefficient and cross sectional area (diff) | |
download | OSLS-dc1cc59362efe5980465cd358b9621bb13825c35.tar.gz OSLS-dc1cc59362efe5980465cd358b9621bb13825c35.tar.bz2 OSLS-dc1cc59362efe5980465cd358b9621bb13825c35.zip |
Implemented proper attitude calculation (instead of just y value)
-rw-r--r-- | src/main.py | 20 | ||||
-rw-r--r-- | src/simulation.py | 16 |
2 files changed, 20 insertions, 16 deletions
diff --git a/src/main.py b/src/main.py index 08c6229..5b6f673 100644 --- a/src/main.py +++ b/src/main.py @@ -99,7 +99,7 @@ def main(argv): simulation.tick(delta=delta) #TODO: draw body sprite, rocket sprite, clouds sprites, etc. - #TODO: implement height properly (body radius) + actually implement body + #TODO: implement gravity properly (x and y) #TODO: do max load on rocket so it blows up #TODO: allow multilanguage api for landing algorithms etc @@ -135,15 +135,15 @@ def draw_simulation(simulation_display: type[pygame.Surface], simulation: type[S curr_thrust = simulation.rocket.current_stage().current_thrust(g, simulation.heading) simulation_display.blit(font.render("Simulation time: {:.0f}s".format(simulation.time), False, (255, 255, 255)),(0,0)) - simulation_display.blit(font.render("X: {:.0f}m".format(simulation.x), False, (255, 255, 255)),(0,40)) - simulation_display.blit(font.render("Y: {:.0f}m".format(simulation.y), False, (255, 255, 255)),(0,80)) - simulation_display.blit(font.render("Speed x: {:.0f}m/s".format(simulation.speed_x), False, (255, 255, 255)),(0,120)) - 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, 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.rocket_altitude()), False, (255, 255, 255)),(0,360)) + simulation_display.blit(font.render("Altitude: {:.0f}m".format(simulation.rocket_altitude()), False, (255, 255, 255)),(0,40)) + simulation_display.blit(font.render("X: {:.0f}m".format(simulation.x), False, (255, 255, 255)),(0,80)) + simulation_display.blit(font.render("Y: {:.0f}m".format(simulation.y), False, (255, 255, 255)),(0,120)) + simulation_display.blit(font.render("Speed x: {:.0f}m/s".format(simulation.speed_x), False, (255, 255, 255)),(0,160)) + simulation_display.blit(font.render("Speed y: {:.0f}m/s".format(simulation.speed_y), False, (255, 255, 255)),(0,200)) + simulation_display.blit(font.render("Acceleration x: {:.2f}m/s2".format(simulation.acceleration_x), False, (255, 255, 255)),(0,240)) + simulation_display.blit(font.render("Acceleration y: {:.2f}m/s2".format(simulation.acceleration_y), False, (255, 255, 255)),(0,280)) + 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,320)) + 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,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)) diff --git a/src/simulation.py b/src/simulation.py index 8968da5..ffcdaeb 100644 --- a/src/simulation.py +++ b/src/simulation.py @@ -19,7 +19,7 @@ class Simulation(): self.body = body self.rocket = rocket self.x = 0#TODO - self.y = 0 #TODO: we need to make it so there is height() to calc height based on x and y + self.y = self.body.radius #TODO: we need to make it so there is height() to calc height based on x and y self.speed_x = 0 self.speed_y = 0 self.acceleration_x = 0 @@ -105,11 +105,12 @@ class Simulation(): #update position based on velocity and delta self.x += self.speed_x * delta - - #in future u should be able to go negative y (y and height are different) self.y += self.speed_y * delta - if self.y < 0: - self.y = 0 + if self.rocket_altitude() < 0: + #undo positional changes + self.x -= self.speed_x * delta + self.y -= self.speed_y * delta + self.speed_x = 0 self.speed_y = 0 print("X: " + str(self.x)) @@ -122,7 +123,10 @@ class Simulation(): self.time += delta def rocket_altitude(self): - return self.y #TODO: take into account body and allow for 360 height + #take into account body and allow for 360 height + altitude = math.sqrt(self.x**2 + self.y**2) + altitude -= self.body.radius + return altitude def snapshot(self) -> Simulation_Snapshot: return Simulation_Snapshot(self.universe, self.body, self.rocket) |