-
Notifications
You must be signed in to change notification settings - Fork 1
Overview
The following document is meant to describe the development of “OpenGL Car Physics Demo”, a 3D driving simulation project related to the course “Real-Time Graphics Programming”.
The main goal of this application is to simulate a vehicle which the user can control via keyboard, in an environment featuring different terrain types; in addition, the user can interact via a GUI to change the value of different physical properties resembling the car’s capabilities, such as friction and acceleration.
This chapter deals with the scope of this project and provides some development information; Chapter 2 describes the main application, its components, and how they work; Chapter 3 examines the implementation in depth, illustrating the main challenges encountered and the related solutions adopted, both graphical and programming; Chapter 4 provides a brief comparison between this solution and other common implementations.
The main purpose of this project is to implement a physical simulation of a car, whose acceleration and steering are controlled by the user, and render the simulation on the screen in three-dimensional graphics. The intended result is to define only basic actions and constraints, in order to get more complex emerging behaviours.
The physical simulation is realised using the Bullet 3D open-source library. The car features five rigid bodies and appropriate constraints, and is modelled as follow:
- The car is made up of 5 rigid bodies, resembling the chassis and the wheels:
- The car body is modelled as a cuboid;
- The wheels are modelled as cylinders;
- The wheels are attached to the chassis using physical constraints on appropriate degrees of freedom, so that:
- They maintain their position relative to the chassis;
- They cannot rotate around any axis but relative X, in order to allow the car to move forth and back
- Front wheels are also allowed to rotate around the Y-axis to allow left and right steering;
- While the relative movement is locked on the relative XZ-plane (horizontal plane), each wheel can move along the Y-axis influenced by a spring constraint in order to simulate suspensions;
- Engine and brake acceleration is achieved by applying torques to the wheels;
- The car movement occurs due to the friction between the wheels and the terrain;
- There are two different types of terrain, asphalt and grass, each with different properties affecting the car’s movement. In addition, a practical GUI allows the user to change the value of parameters affecting constraints and rigid bodies, such as mass, stiffness and damping. Presets are also available to apply pre-made setups to the car. The adopted physical setup is explained in detail in Chapter 3, paragraph 3.3. The GUI functionalities are discussed in-depth in Chapter 2, paragraph 2.2.
The graphic rendering is achieved via OpenGL, drawing 3D models at the end of each simulation iteration:
- The chassis and the wheels have separate models each, in order to reflect their rigid body counterpart movement in the world;
- Each texture is assigned material properties, that create different effects when rendered;
- A cube map is used with the dual purpose of drawing a skybox in the background, and applying an environment map onto the car chassis to emulate reflection;
- The lighting system consists of ambient light, and a directional light resembling the sunlight in the distance. Vertex and fragment shaders are written on purpose for each main render object in the application and are discussed in Chapter 3 paragraph 3.2.
The application was developed in the C++ language on Linux environment; additional libraries used by the application are OpenGL for the rendering, Bullet 3D for the physics, and GTK for the interactive user interface under Linux.
- OS: Fedora Linux 29 64-bit
- Processor: Intel® Core™ i5-5300U CPU @ 2.30GHz × 4
- Graphics: Intel® HD Graphics 5500 (Broadwell GT2)
- Rendering: OpenGL 3.3 Core
- Physics: Bullet Physics 2.83 (source)
- GUI: GTK+ 3.24
- 3D model loader: Assimp - Open Asset Importer Library
- Image loader: stb_image.h open-source library
- Assets: resources from OpenGameArt.Org