Orbital



a Two-dimensional N-Body Simulator

Languages /  Libraries Used: C++, OpenGL
Team Size: Individual
Personal Role: Everything
Development Time: 2-3 weeks

Description: Orbital is a simulation I wrote over the break from fall to winter quarter at RIT in 2010. The initial goal was to learn the OpenGL API, as I was entering into Computer Graphics I a few weeks later and also had had interest in the area for a while. The project started as just a simple way to click on the screen and have circles appear under the mouse...but that wasn't much fun so I added the ability to click and drag an initial "velocity vector" for the circle, and when the mouse was released the circle would fly off in that direction at the correct speed... well that got old as well. So I added gravitational pull between circles on the screen, and the ability for larger circles to consume smaller circles upon contact.

Fast-forward a few days and I'd upgraded my very rudimentary gravitational pull equations to fixed-delta vector verlet integration  and had the beginnings of orbit prediction done as well based on elliptical equations. The start of winter quarter came and went, and while I was beginning Computer Graphics 1 I was also finishing up a full redesigned orbital path prediction model based entirely on Kepler's orbital elements, as well as the theory behind gravitational spheres of influence and Isaac Newton's classic N-Body problem. I even got so obsessed with modeling the physics as to re-implement my gravitational motion code around sixth-order symplectic integrators.


I'd be lying to myself if I said that I could have done this alone, however. While the code and implementation was entirely my own, and the math was within my grasp, the sheer amount of physics involved in creating a physical simulation this accurate is humbling to say the least. Even when restricted to a 2-dimensional plane, "accurate" n-body simulations (if there is such a thing outside of CERN) are daunting to get right. Fortunately, the incredibly knowledgeable and encouraging individuals over at GameDev.net's Math and Physics forum live and breath this kind of chit-chat, and helped me tremendously throughout this project by pointing me in the right direction toward the things I needed to research and learn to do it right. I was fortunate enough to have a rather long-running thread on the site which serves as the running documentation of my development from near-start to absolute finish. For those interested, here is the address. (Yes, my name on the forum is, in fact, ChugginWindex...)

I've talked about it enough without even showing the damn thing! Here's an example of the application in action.




My only regret of this project is that I didn't keep a personal record of it's development. Not only do I not have incremental development releases that I could run to show the progress I made at each step, but I had next to no screenshots of those stages either. In fact the screenshot that most likely lead you to this page, taken near the end of development, is literally the only one I found of the application. There are download links in the thread mentioned above that I scattered throughout my posts to show the guys helping me as I went, but they have all since expired. What I do have, however, is the final build I created in Visual Studio.

The picture above really does not do the application justice. I encourage anyone stumbling upon this page who is running windows to give it a try, I'm very proud of it and think it's quite fun to play with.

Controls: 
Left click spawns star with current mass.
Click and hold to drag initial velocity vector.
Hold right click and move mouse to pan around universe.
Scroll mouse wheel to zoom in and out.
Hold Control and scroll mouse wheel to decrease / increase starting mass.

The code is a bit ugly at the moment. I was working on UI design when I finally called it quits (classes ramped up for the quarter as I recall...damn you RIT!) and there's some leftover debugging artifacts and random transparent squares all over the place. I hope to clean it up some day soon and post the code but I haven't built this project since before I reinstalled Windows so I have to go hunting for the right libraries and whatnot first.