feat: bodies attract

This commit is contained in:
2025-11-19 18:45:25 +01:00
parent a5add0765f
commit b33e9b37a2
5 changed files with 79 additions and 10 deletions

View File

@@ -1,21 +1,23 @@
#ifndef SIMS_HPP
#define SIMS_HPP
#include "utils.hpp"
#include <SDL3/SDL_pixels.h>
#include <SDL3/SDL_render.h>
#include <utility>
class Body {
private:
std::pair<float, float> old_positions[200];
public:
float x;
float y;
float vx = 1;
float vy = 1;
std::pair<float, float> old_positions[200];
public:
SDL_Renderer* renderer;
SDL_Color color = {255, 255, 255, 255}; // white
long double mass = EARTH_MASS;
Body(int x_pos, int y_pos);
@@ -23,6 +25,7 @@ public:
void live();
};
void two_bodies(SDL_Renderer* r, Body &a, Body &b);
void two_bodies(SDL_Renderer* renderer, Body &a, Body &b);
Body create_random_body();
#endif

13
include/utils.hpp Normal file
View File

@@ -0,0 +1,13 @@
#ifndef UTILS_H
#define UTILS_H
#include <utility>
// constants
const long double EARTH_MASS = 5.972e24;
const long double G = 6.67430e-11L;
std::pair<int, int> get_random_position(int x_min, int x_max, int y_min, int y_max);
#endif