About
For my project, I built a game where you fly around a spaceship using a gamepad. You can shoot down orbiting cubes with spaceships lasers.
All resources and models were created by myself, except for the spaceship, which came from a low poly spaceship pack here: https://www.reddit.com/r/gamedev/comments/7qymqo/free_lowpoly_spaceships/
Controls:
- Right and Left (inverted) Y Axis: Pitch
- Right X Axis: Yaw
- Left X Axis: Roll
- Left Trigger: Throttle
- Right Trigger: Fire Laser
Technologies Used
Quaternion Based Orientation
The spacecraft has 3-degrees of rotation freedom using the gamepad. Initially, these were tracked through roll, pitch, and yaw variables, otherwise known as Euler angles. Euler angles suffer from an issue known as gimble lock, where one axis rotates the other two axis into the same plane. This results in the loss of one degree of freedom and awkward rotations.
Quaternions solve this problem by using a four dimensional vector to store orientation. Using quaternions also allowed me to solve the problem of a rigid camera. Having the camera rigidly track the spaceship felt unnatural. I used separate quaternions to track both the ship and camera orientation. I then used glm to linearly interpolate between the orientations.
Bloom and HDR Rendering
I applied a gaussian bloom filter to bright parts of the image. In order in take advantage of the bloom, I switched to a HDR rendering pipeline. HDR rendering allows colors brighter than the typical 1.0. Then before rendering to the screen the entire color spectrum can be remapped to 0-1.0 again.
I was noticing that in high-specular situations some unexpected parts of the scene, like the ship itself, were going over the bloom threshold, so I made bloom configurable per mesh, so only the expected objects like the two suns exhibited bloom.
I used the https://learnopengl.com/Advanced-Lighting/Bloom tutorial as a guide for implementing bloom
Dynamic Engine Trail Lighting
Bloom makes objects look emissive, but doesn’t actually apply lighting anywhere. To give the appearance of lighting from the engine I added a week directional light where the exhaust is.
Engine Throttling Up (light applied):
Engine Throttling Down (lighting not applied):
Collision
The spaceship’s lasers can destroy the small boxes in the orbit around the asteroid. Collision detection is done through a simple shperical distance calculation between the lasers and boxes.