I am using arcsynthesis' tutorial to learn modern 3D graphics programming, and while I am understanding most of it I have run into a snag with what the author calls "complex management code" I can't understand how this code works:
struct Instance
{
typedef glm::vec3(*OffsetFunc)(float);
OffsetFunc CalcOffset;
glm::mat4 ConstructMatrix(float fElapsedTime)
{
glm::mat4 theMat(1.0f);
theMat[3] = glm::vec4(CalcOffset(fElapsedTime), 1.0f);
return theMat;
}
};
Instance g_instanceList[] =
{
{StationaryOffset},
{OvalOffset},
{BottomCircleOffset},
};
I don't quite get how the function pointer is getting set inside the struct in the g_instanceList[] I don't get syntactically how this works and then how this g_instanceList is used in the next segment here:
float fElapsedTime = glutGet(GLUT_ELAPSED_TIME) / 1000.0f;
for(int iLoop = 0; iLoop < ARRAY_COUNT(g_instanceList); iLoop++)
{
Instance &currInst = g_instanceList[iLoop];
const glm::mat4 &transformMatrix =
currInst.ConstructMatrix(fElapsedTime);
glUniformMatrix4fv(modelToCameraMatrixUnif, 1, GL_FALSE, glm::value_ptr(transformMatrix));
glDrawElements(GL_TRIANGLES, ARRAY_COUNT(indexData), GL_UNSIGNED_SHORT, 0);
}
I thought I was pretty familiar with c++ by this point but this syntactic sugar is new to me. Thanks in advance :)