Home
Resume
About Me
Youtube Channel
LinkedIn
Project Archive
Game Documentation
Creative Writing

Solar System Demo


Project Info

Project Title: Solar System Demo

Development: C++ / OpenGL

My Role: Graphics / Physics Programmer

Solar System Start
Solar System Start Zoom In

Overview

This project was a challenge, not only to learn about the fundamentals of game physics, but to also implement graphics utilizing OpenGL. While I have had experience with DirectX previously, creating an OpenGL application from scratch and applying the much-needed visuals emerged as an extra hurdle during development. Therefore, after applying basic object rendering, I focused on the physics system until the planet orbiting was finalized. Afterwards, I had some additional time to examine methods for including textures on spheres, and a skybox to form the environment around the planets.

Physics Objects

All entities within the system are based on Physics Objects. Physics Objects contain information concerning an object's current position, velocity, acceleration, accumulated force, and mass. It serves as the base class for other entities, such as Particles and Planets. Planets handle the rendering process for the visualization of the sphere, radius, text information, and texture application. The Physics Object remains as the component that actively updates its forces in order to determine changes in position, velocity, and acceleration.

Solar System Start Zoom Out
Basic Orbiting

Physics System

The Physics Handler contains vectors of Force Generators and Object Force Generators. It also owns the Force Registry. Physics Objects that are owned outside of the Physics System can request to have their information registered alongside one of the Force Generators. Force Generators represent force applications that only require a single object, such as wind or drag. Object Force Generators represent Force Generators that take in multiple objects, such as gravity or springs.

When a Physics Object requests registration, a Force Registration is created containing the reference to the Force / Object Force Generator, and the possible Physics Objects involved in the force application. The Force Registry will then continuously update its Force Registrations, allowing for Physics Objects to accumulate forces through the Force Generators.

In this simulation, there is primarily only need for one type of Object Force Generator. The Gravity Generator takes into two Physics Objects, and calculates the gravitational force based on their distances and masses. This force is the applied, in opposite directions, to both Physics Objects. This is what enables all planets to orbit correctly. All planets apply forces amongst each other, but ultimately the sun's mass causes them to favor the gravitational pull toward the center of the system.

Planetary Orbits

As a result, the information regarding any planet's mass, distance, and initial velocity is crucial in terms of properly replicating the orbits for all planets. It took a while to discern the proper calculations, scaling them down to work within the application. Slight nuances between planets could ultimately cause celestial bodies to fly off in opposing directions, or simply fall into the sun. The key is typically finding the starting velocity, therefore giving the planet enough momentum to adhere to the sun's gravitational pull, while also wrapping around.

The moon ended up being the trickiest to create, and is somewhat hard to monitor due to its distance to the earth. There were several occurrences where the moon would either fly off into space, cause the earth to lose its orbit, or break the entire solar system. This likely relates to the reality that the simple application of gravitational pulls between planets not only requires precision, but there are also other factors to consider. The dampening for planets also assists in ensuring that the orbits do not widen too quickly, and eventually the combination between the moon and earth velocity allowed the moon to orbit the earth in a more believable manner.

Zoom In of Sun
Earth Orbiting

Conclusion

While far from perfect, this application conveys the basic interactions between forces through the orbiting of several planets. The distance and mass of a planet in comparison to the sun determines the speed at which it orbits around the central area, allowing for a believable representation of the cycles of the planets utilizing very simple gravitational calculations.

Physics Demo - Basic Planetary Orbit