A 2D simulation of a planetary system built in C++ and SFML. This project is a practical study in managing multiple, independent game objects, each following its own distinct orbital path based on a set of simple rules.
The primary goal of this project was to create a dynamic system of several independently moving objects. I aimed to model a simple solar system where each planet follows its own unique orbit around a central star. This served as a fundamental exercise in object-oriented design, state management for multiple entities, and the application of mathematical principles to create predictable, elegant motion.
- Independent Orbital Mechanics: Each planet orbits the central star at its own unique speed and distance.
- Object-Oriented Design: A
Planetclass encapsulates all the necessary properties (size, orbital radius, color, angular velocity), allowing for easy creation and management of new celestial bodies. - State Management: The simulation manages a collection of
Planetobjects in astd::vector, updating and drawing each one every frame. - Parametric Motion: Each planet's position is calculated parametrically using its angle, which is updated over time to create smooth, continuous animation.
- Polar to Cartesian Conversion: Core mathematical functions (
sin(),cos()) are used to convert each planet's polar coordinates (its radius and angle) into Cartesian coordinates (x,y) for rendering on the screen.
This project was a critical lesson in moving from single-object simulations to managing a collection of independent entities.
-
Data-Driven Design: My main takeaway was how to design a system driven by data. By creating a flexible
Planetclass, I could easily expand the solar system by simply adding a new object with different parameters to my vector, without changing the core update and render logic. -
Managing Collections in Real-Time: I gained practical C++ experience in iterating over a vector of objects within a game loop. This reinforced the fundamental pattern of updating the state of every object, and then drawing every object, in separate passes each frame.
-
Applied Mathematics at Scale: While my "Trigonometry" project focused on a single object, this simulation required applying those same mathematical principles to an entire collection of objects simultaneously. It solidified my understanding of how to use simple formulas to create a complex and dynamic scene.
This project provides a strong foundation for a more complex simulation. The planned next steps demonstrate a clear path for growth:
- Hierarchical Orbits (Moons): The most important next feature is to implement moons orbiting planets. This will be a great challenge in learning hierarchical transformations.
- Camera System: Implementing pan and zoom controls to allow the user to explore the solar system.
- Texturing: Replacing the simple colored circles with planet textures.
- UI / Info Display: Adding on-screen text to display the names of the planets.
- Atmosphere: Creating a starfield background to give the scene more depth.
This project was developed on Windows using Visual Studio.
- Clone the Repository:
git clone https://github.com/tuananohut/2D-Solar-System-Simulation.git
- Run from Visual Studio:
- Open the
.slnsolution file in Visual Studio. - The necessary SFML library files are included.
- Set the solution configuration to Release and platform to x64.
- Build and run the project (F5).
- Open the