Game Development Reference
In-Depth Information
Figure 5-26. Newton's law of gravity
For the purposes of this topic, we will use a general modified form of the equation in Figure 5-26 for
a gravity grid that will react in a similar way according to that of Newton's law of gravity. The main
purpose of the gravity grid will be to produce some visually impressive effects.
Drone Grid Case Study: Creating a Gravity Grid Using a
Vertex Shader
In this case study, we will add a gravity grid to the previous hands-on example of the two colliding
cubes bouncing on top of each other. The gravity grid consists of a grid of points that behave
according to Newton's law of gravity. That is, the grid points are simulated as masses that are
attracted to other masses that are placed on the grid. The purpose of our gravity grid in this example
will be to illustrate how the movement of the cubes can change the shape of the gravity grid to
produce some visually interesting effects. In addition, a spotlight will be placed on the grid under
the masses that are added onto it. The purpose of the spotlight is to highlight and enhance the
deformations caused by the masses on the gravity grid.
Modifying the Physics Class
The Physics class needs to be modified to hold the radius of the spotlight that is shown on the grid
below an object that is added on to the grid. The variable m_MassEffectiveRadius is the radius for
the spotlight on the grid.
private float m_MassEffectiveRadius = 10; // Radius for mass effect on gravity grid
The functions GetMassEffectiveRadius() and SetMassEffectiveRadius() retrieve and set the radius
for the spotlight.
float GetMassEffectiveRadius() {return m_MassEffectiveRadius;}
void SetMassEffectiveRadius(float value) { m_MassEffectiveRadius = value;}
Modifying the MeshEx Class
Next, we have to add some code to the MeshEx class. This new code will be used to draw lines
instead of triangles.
MeshType is a new enumeration that has the values of Triangles and Lines.
enum MeshType
{
Triangles,
Lines
}
 
Search WWH ::




Custom Search