Physics Engine

Physics Engine

A physics engine framework is created in this section and integration into a game engine is demonstrated. These VMK build on top of the 3D OpenGL Game Engine series. Topics covered include game timing and motion, simulating gravity, wind, and friction.

Looking for server...

0: Introduction
Welcome to network programming in Visual Studio 2010 using C++. This VMK describes what will be covered in the series.
VMK 0: Introduction
1a: Disable Vertical Synchronization
Disable Vertical Synchronization
I explain the inner workings of the vertical synchronization feature built into a computer''s video card and monitor. I then show you how to disable it so that we can get the game engine running at more than the standard 60 fps.
VMK 1a: Disable Vertical Synchronization Download VMK 1a Resources
1b: VSync GUI Checkbox
VSync GUI Checkbox
I demonstrate how to add a check box to the Options Menu that will allow you to turn vertical synchronization on and off, while the game engine is running.
VMK 1b: VSync GUI Checkbox
2ab: Sphere Geometry
Sphere Geometry
I show you how to generate the vertices and normals for a general sphere shape. The sphere object builds on top of the existing game engine framework.
VMK 2ab: Sphere Geometry
2c: Texturing Sphere
Texturing Sphere
I add texture coordinates to the GeometrySphere class so that we will be able to apply a texture over top of the shape.
VMK 2c: Texturing Sphere Download VMK 2c Resources
3: Position, Velocity, Acceleration
Position, Velocity, Acceleration
I go through the process of showing how position, velocity and acceleration are related to one another. You will see how to use the derivative to get the velocity and acceleation from a position graph. I will also go backwards and integrate acceleration to get velocity and position.
VMK 3: Position, Velocity, Acceleration
4a: Cannon Control
Cannon Control
I add a cannon to the scene and assign some keyboard control keys to allow us to change the direction and pitch of the cannon. A bug fix in the texture manager is also shown.
VMK 4a: Cannon Control Download VMK 4a Resources
4bc: Cannon Ball
Cannon Ball
A cannon ball is added to the scene which we can load into the cannon, aim and fire! No gravity in the simulation .... that's coming next.
VMK 4bc: Cannon Ball Download VMK 4bc Resources
4d: Gravity
Gravity
I add gravity to the motion of the cannon ball so that it falls back down to the ground after we shoot it. I also show you how to implement simple collision detection with the ground.
VMK 4d: Gravity Download VMK 4d Resources
5a: Laws of Motion
Laws of Motion
There are three laws of motion developed by Newton that we take a look at in this VMK.
VMK 5a: Laws of Motion
5bc: Types Of Forces
Types Of Forces
I describe how to calculate six types of forces in this VMK. Gravitational, Spring, Damper, Friction, Buoyancy and Drag forces.
VMK 5bc: Types Of Forces
5d: Wind Force
Wind Force
In this VMK I show you how to derive the equations of motion for the cannon ball when wind is blowing in our scene.
VMK 5d: Wind Force
5ef: Wind Code
Wind Code
A 3D model of a chicken is loaded into our scene to represent the direction of the wind and the cannon ball properties are all grouped into a separate class.

Keyboard input from the number pad is added to allow us to change the direction of the wind, change the speed of the wind and the mass of the cannon ball. Finally the equations of motion are also implemented.
VMK 5ef: Wind Code Download VMK 5ef Resources
5g: Drag Force
Drag Force
I show you how to derive the equations of motion when the forces due to gravity, wind and drag are acting on the cannon ball.
VMK 5g: Drag Force
5h: Drag Code
Drag Code
The equations of motion for the cannon ball are implemented in C++. We can now see how Gravity, Wind and Drag forces can cause the cannon ball to change direction.
VMK 5h: Drag Code
6a: Integrator Equations
Integrator Equations
We will be implementing a numerical integrator into the physics engine so that we do not have to calculate the double integration of acceleration ourselves. The equations for the Euler and Improved Euler integrator are shown in this VMK.
VMK 6a: Integrator Equations
6b: Comparing Integrators
Comparing Integrators
The Euler and Improved Euler Integrators are compared using Microsoft Excel. Use the attached spreadsheet to become familiar with how the integrator works.
VMK 6b: Comparing Integrators Download VMK 6b Resources
6c: Using Euler Integrator
Using Euler Integrator
I clean up the code by removing the cannon and I add a new Particle class to the Scene. The Euler Integration equations are added to the Particle class to cause each particle to move independently under the influence of gravity and wind. I then show how to add a few more effects to the Particle class to cause the particles to bounce off the ground and randomly shoot out in different directions.
VMK 6c: Using Euler Integrator Download VMK 6c Resources
7: Preparation Work
Preparation Work
This video explains the inner workings of the physics engine that I'll be adding to the game engine. Near the end I clean up some code to get ready to implement the new algorithm in C++.
VMK 7: Preparation Work
8: Render Ship
Render Ship
I will be using the physics engine to control a space ship on the screen. In this video the game engine is updated to house the new physics engine algorithm.
VMK 8: Render Ship Download VMK 8 Resources
9: Space Ship Motion
Space Ship Motion
I show how to use keyboard input to control the space ship's motion. Pressing the up and down arrow keys will activate the engines to move forward and back, and pressing the left and right arrow keys will steer the ship left and right.
VMK 9: Space Ship Motion
10: Tuning Space Ship
Tuning Space Ship
Three things are modified in this video to make the space ship fly better.
1) Angle of space ship is limited to be between +/- 360 degrees
2) Space ship is constrained to always be in the confines of the window
3) Limit the maximum speed of the ship
VMK 10: Tuning Space Ship
11: Integrator Classes
Integrator Classes
In this VMK I develop two new classes called Integrator1 and Integrator2. These classes will be used to integrate all our 1D and 2D variables in the videos to come.
VMK 11: Integrator Classes
12: Improved Space Ship Class
Improved Space Ship Class
Using the newly created integrator classes from the previous VMK we can now create a better Space Ship class. The new Space Ship class is inherited from ObjectDynamic2D. All objects moving in 2D will be derived from this new class.
VMK 12: Improved Space Ship Class
13: Interpolation
Interpolation
In this video I explain why we need to use interpolation with the physics engine. I then go into the code to implement the technique described and show how you can test the effectiveness of the interpolation. You'll need to do this on your own computer to see the results, since the frame rate of the video is only 10fps which is too slow to really notice the difference.
VMK 13: Interpolation
14: Bullets
Bullets
I show how to construct the SpaceShipBullet class which is used to control all the bullets that the ship fires. Each bullet is rendered as a red triangle on the screen. To rotate each bullet to face the correct direction a generic Matrix2 class is created.
I then take the new SpaceShipBullet class and integrate it with the SpaceShip class. If you press the spacebar you will shoot one bullet. If you hold down the spacebar, then a row of bullets will be fired.
VMK 14: Bullets

Continue learning more by doing the Ghost Toast VMK series next.

X