Game Development Reference
In-Depth Information
Choses from Newton's law of gravity and ForceMax the minimum force from
the current force calculated
8.
9.
Adds the displacement that this force causes the grid vertex by adding this
force to the current vertex position
Listing 5-35. Calculating the Forces and Colors for a Grid Point
// F = G *( M1 * M2)/ (R*R)
// F = m * a
// F/m = a
// Force = (MassOnGravityGrid * MassVertex) / (RadiusBetweenMasses * RadiusBetweenMasses);
float Force;
float ForceMax = 0.6; //0.5;
vec3 VertexPos = NewPos;
vec3 MassSpotLightColor = vec3(0,0,0);
for (int i = 0; i < MAX_MASSES; i++)
{
// If mass value is valid then process this mass for the grid
if (MassValues[i] > 0.0)
{
vec3 Mass2Vertex = VertexPos - MassLocations[i];
vec3 DirectionToVertex = normalize(Mass2Vertex);
vec3 DirectionToMass = -DirectionToVertex;
float R = length(Mass2Vertex);
Force = (MassValues[i] * (2.0)) / (R * R);
if (R < MassEffectiveRadius[i])
{
float Intensity = IntensityCircle(R, MassEffectiveRadius[i]);
MassSpotLightColor = MassSpotLightColor + (SpotLightColor[i] * Intensity);
}
Force = min(Force, ForceMax);
VertexPos = VertexPos + (Force * DirectionToMass);
}
}
The final vertex position saved in gl_Position is calculated by multiplying the modelviewprojection
matrix by the vertex location in VertexPos .
gl_Position = uMVPMatrix * vec4(VertexPos,1);
The final color of the vertex Color is derived from the original color vColor of the vertex, added to the
sum of the spotlight colors from all the objects on the gravity grid.
Color = vColor + MassSpotLightColor;
 
Search WWH ::




Custom Search