Game Development Reference
In-Depth Information
// Set up the Proj so that the object rotates around the Y axis
// We'll also translate it appropriately to Display
Model[0][0] = cosf(Angle);
Model[1][1] = 1.0f;
Model[2][0] = sinf(Angle);
Model[0][2] = -sinf(Angle);
Model[2][2] = cos(Angle);
Model[3][2] = -1.0f;
Model[3][3] = 1.0f;
// Constantly rotate the object as a function of time
int ticks = time;
int thisTicks = ticks - lastTicks; // note delta time
if (thisTicks > 200)
thisTicks = 200; // throttling
Angle += ((float) thisTicks) * RotationSpeed; // apply animation
lastTicks = ticks; // note for next loop
// Vertex information
float PtData[][3] = {
// see source (removed for simplicity)
};
// Face information
unsigned short FaceData[][3] = {
// see source (removed for simplicity)
};
// Draw the icosahedron
glUseProgram(Program);
glUniformMatrix4fv(iProj, 1, false, (const float *) &Proj[0][0]);
glUniformMatrix4fv(iModel, 1, false, (const float *) &Model[0][0]);
glVertexAttribPointer(0, 3, GL_FLOAT, 0, 0, &PtData[0][0]);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_TRUE, 0, &PtData[0][0]);
glDrawElements(GL_TRIANGLES, sizeof(FaceData) / sizeof(unsigned short),
GL_UNSIGNED_SHORT, &FaceData[0][0]);
}
The Display C++ function performs the following steps:
1.
It clears the screen with glClear (GL_COLOR_BUFFER_BIT); .
2.
It creates a model matrix of float Model[4][4] to set up a projection
so that the object rotates around the Y axis. It also translates it
appropriately to display.
3.
It then constantly rotates the object as a function of time.
4.
It enables the program with glUseProgram (Program); .
Search WWH ::




Custom Search