From 138db9bda373f3b55661ed061a7c21b5b5ce474d Mon Sep 17 00:00:00 2001 From: zongor Date: Thu, 24 Jul 2025 14:12:15 -0400 Subject: [PATCH] add scaling --- src/camera.h | 4 +--- src/main.cpp | 13 +++++++++---- src/simulation.cpp | 21 +++++++++------------ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/camera.h b/src/camera.h index e29be8b..0baa326 100644 --- a/src/camera.h +++ b/src/camera.h @@ -64,9 +64,7 @@ private: return 0.5 * (rec.normal + Color(1, 1, 1)); } - Vec3 unit_direction = unit_vector(r.direction()); - auto a = 0.5 * (unit_direction.y() + 1.0); - return (1.0 - a) * Color(1.0, 1.0, 1.0) + a * Color(0.5, 0.7, 1.0); + return Color(0, 0, 0); } }; diff --git a/src/main.cpp b/src/main.cpp index 1f758ae..2f5752e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,9 +19,13 @@ int main() { std::thread render(render_thread, std::ref(buffer), std::ref(canvas)); SDL_Init(SDL_INIT_VIDEO); - SDL_Window *window = - SDL_CreateWindow("Solar System", SDL_WINDOWPOS_CENTERED, - SDL_WINDOWPOS_CENTERED, canvas.width, canvas.height, 0); + int scale = 3; + SDL_Window *window = SDL_CreateWindow( + "Solar System", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, + canvas.width * scale, // window width + canvas.height * scale, // window height + SDL_WINDOW_RESIZABLE // optional, allows manual resize + ); SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB24, @@ -36,7 +40,8 @@ int main() { SDL_UnlockTexture(texture); SDL_RenderClear(renderer); - SDL_RenderCopy(renderer, texture, nullptr, nullptr); + SDL_Rect dest = {0, 0, canvas.width * scale, canvas.height * scale}; + SDL_RenderCopy(renderer, texture, nullptr, &dest); SDL_RenderPresent(renderer); SDL_Event e; diff --git a/src/simulation.cpp b/src/simulation.cpp index 7adbbcb..ea00bed 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -49,6 +49,7 @@ SimulationState initialize_solar_system() { */ void simulation_thread(RingBuffer &buffer) { SimulationState state = initialize_solar_system(); + float BIG_G = 6.67e-11; // gravitational constant float dt = 0.01; // if we didnt do this it would run too fast for render std::chrono::duration elapsed; @@ -59,10 +60,7 @@ void simulation_thread(RingBuffer &buffer) { elapsed = now - last; if (elapsed.count() >= dt) { - float t_0 = 0; - float t = t_0; - float dt = 86400; - float BIG_G = 6.67e-11; // gravitational constant + float bdt = 86400; size_t n_bodies = state.bodies.size(); for (size_t m1_idx = 0; m1_idx < n_bodies; m1_idx++) { @@ -95,21 +93,20 @@ void simulation_thread(RingBuffer &buffer) { } } - state.bodies[m1_idx].velocity.x() += a_g.x() * dt; - state.bodies[m1_idx].velocity.y() += a_g.y() * dt; - state.bodies[m1_idx].velocity.z() += a_g.z() * dt; + state.bodies[m1_idx].velocity.x() += a_g.x() * bdt; + state.bodies[m1_idx].velocity.y() += a_g.y() * bdt; + state.bodies[m1_idx].velocity.z() += a_g.z() * bdt; } for (size_t entity_idx = 0; entity_idx < n_bodies; entity_idx++) { state.bodies[entity_idx].position.x() += - state.bodies[entity_idx].velocity.x() * dt; + state.bodies[entity_idx].velocity.x() * bdt; state.bodies[entity_idx].position.y() += - state.bodies[entity_idx].velocity.y() * dt; + state.bodies[entity_idx].velocity.y() * bdt; state.bodies[entity_idx].position.z() += - state.bodies[entity_idx].velocity.z() * dt; + state.bodies[entity_idx].velocity.z() * bdt; } - t += dt; // Try to push it into the buffer while (!buffer.push(state)) { // Buffer full, drop or wait (e.g. yield or sleep) @@ -131,7 +128,7 @@ void render_thread(RingBuffer &buffer, Canvas &canvas) { Camera cam; cam.aspect_ratio = 16.0 / 9.0; cam.image_width = 400; - cam.move_to(Point3(0, 0, 100)); + cam.move_to(Point3(0, 10, 100)); while (running) { auto maybe_state = buffer.pop();