class vertexStruct
{
public:
vertexStruct(int fvf);
private:
int fvf;
int stride();
// get Offset returns the offset in the 'struct' to this component. e.g. position or color
int getOffset(int fvfComponent)
{
// would do math involving the fvf member here
}
// returns true if fvf contains fvfComponent
bool contains(int fvfComponent)
{
return fvf&fvfComponent;
}
};
Then your function that builds your sphere for example:
buildSphere(float* modelData, vertexStruct vs, int vertexCount)
{
for(int i=0; i<vertexCount; i++)
{
if(vs.contains(D3DFVF_POSITION))
{
modelData[i*modelData.stride+getOffset(D3DFVF_POSITION)]=1.0f; // x position
modelData[i*modelData.stride+getOffset(D3DFVF_POSITION)]=1.0f; // y position
modelData[i*modelData.stride+getOffset(D3DFVF_POSITION)]=1.0f; // z position
}
}
}