I am looking over this piece of code, and am having trouble with the syntax:
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;
}
};
It is C++ code, related to OpenGL, but my question is not about OpenGL. The glm::vec3, vec4, mat4 are just vectors of dimension 3 and 4, and mat4 is a 4×4 square matrix. The glm library has overloaded operators so lines like:
theMat[3] = glm::vec4(CalcOffset(fElapsedTime), 1.0f);
work as you might expect, filling up the 4th column of theMat with a 4-d vector that is comprised of 1.0f and that cast or typedef or function call, I’m not exactly sure what that is, and that is my question.
What does typedef glm::vec3(*OffsetFunc)(float); and CalcOffset(fElapsedTime) mean?
I tried reading here: http://en.wikipedia.org/wiki/Typedef#Using_typedef_with_type_casts , but that explanation doesn’t really seem to make sense to me.
Edit: I know how typedefs work when it simply involves providing another alias for a type.
Edit 2: I thought that this might be doing something with a pointer to a function because it kind of looks like a pointer and has float in there like its a function parameter type, and it seems like this is the case, but I am still not sure what this kind of code precisely does.
defines
OffsetFuncto be an alias for the typeglm::vec3(*)(float), i.e. pointer to function takingfloatand returningglm::vec3.calls the function pointed to by
CalcOffsetonfElapsedTime.