Simple Physics Test
Language: C++, Middleware: OpenGL, Box2D
Overview of the project
Motivation
- How different forces (such as gravity, inertial force and impulse) affect the object in the world.
Problem which I had
- In real world, various forces affect on the dynamic object. Energy transition between static object like ground and dynamic object such as a car is very complex to compute.
Which features are included in this project
- Computation of Inertial force, gravity, impulse, friction and tensor force
- Understanding of angular speed, motor speed and torque.
- Procedural platform generation
- Understanding of constraints such as joints and anchors.
How to solve the problem
- Defined all possible forces and simulated them using Box2D.
Detail of the project
1.Introduction
This small project has focused on implementing physics based car controlling game. The performance of the car will be affected by randomly generated terrain and the user can observe its performance while they change motor speed, the centre of mass for car, and wheel drive system (front, rear and 4WD). Box2D has been used to build physics world and OpenGL has been utilised for rendering the scene.
2.Specification
The image below shows the entire physics in the scene. (see figure 1)
Figure 1. Entire forces and attribute in the scene
Figure 2. Defining attributes for the wheel joint
Gravity is -9.8 m/s along y axis. Car body and wheels are connect with wheel joint which includes spring frequency and hardness as own attributes. Motor speed and torque, which are other dynamic attribute for the joint, are key factor making car move (see figure 2). This angular velocity of the wheel will be translated as linear velocity of the car by friction between wheels and ground.
Users are also able to change wheel drive system of the car such as front, rear and four wheel drive (sing keyboard ←, → keys). Front wheel system is suitable for up-hill, whereas rear wheel system is stable in down-hill (Since I did not consider fuel-efficiency, 4WD is the best system and the most powerful in any type of terrain). In addition, users can change the centre of mass. The lower it is, the more stable the car drives.
The car has boosting system, which adding force along the direction to its velocity vector (length and direction). Since there is gravity force in the scene and the car drives on the terrain, boosting velocity (force in Box2D) has to be parallel to the ground (see figure 3, 4).
Terrain is created procedurally, which mean it draws only adjacent terrain for enhancing performance of the game. If it draw the entire terrain, Box2D will compute the entire bodies in the scene and OpenGL should draw all either, resulting in slow rendering speed.
Based on the position of car, the terrain
behind 6m will deleted and 6m front terrain will be generated. The height of
terrain to be created is determined by random value (see Figure 5).
Figure 5. Only adjacent terrain will be created
Figure 5. Only adjacent terrain will be created
Finally, bridges will be generate in 20% chance, which means 80% will be normal terrain. The bridge is connected with rope joint in Box2D. The structure of the bridge is equivalent to linked list. Previous and current bridge components are connected by a joint and an anchor (see Figure 6).
Figure 6. Bridge
Figure 6. Bridge