I'm currently working with a recursive subdivision algorithm given in the opengl redbook and am trying to improve the method ( instead of it doing the calculations for the subdivision during the game loop, calculate it before and store it in an array ) the issue that i'm having at the moment is I can't get the relation between the number of subdivisions to do, the number of vertices and the number of triangles to make equations to get the required size for the array to store the subdivided mesh coordinates into, I've draw it out on paper to try get a better idea but the only thing I've learned out of this is the relations to the number of triangles after subdivision ( being 4^numsubs ) but I can't seem to figure out the relations to the number of vertices, nore can my friends... below is some figures from the first 4 subdivisions:

Triangle1: subs = 0; VertCount = 3; TriCount = 1; // 4^0 = 1 Triangle2: subs = 1; VertCount = 6; TriCount = 4; // 4^1 = 4 Triangle3: subs = 2; VertCount = 15; TriCount = 16; // 4^2 = 16 Triangle4: subs = 3; VertCount = 45; TriCount = 64; // 4^3 = 64

The Subdivisional method is as follows:

void normalize( float v[3] ) { GLfloat d = sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]); if( d == 0.0 ) { } v[0] /= d; v[1] /= d; v[2] /= d; } void normcrossprod( float v1[3], float v2[3], float out[3]) { out[0] = v1[1]*v2[2] - v1[2]*v2[1]; out[1] = v1[2]*v2[0] - v1[0]*v2[2]; out[2] = v1[0]*v2[1] - v1[1]*v2[0]; normalize(out); } void DrawTriangle( float *v1, float *v2, float *v3 ) { glBegin( GL_TRIANGLES ); glNormal3fv(v1); glVertex3fv(v1); glNormal3fv(v2); glVertex3fv(v2); glNormal3fv(v3); glVertex3fv(v3); glEnd(); } void Subdivide( float *v1, float *v2, float *v3, long depth ) { GLfloat v12[3], v23[3], v31[3]; GLint i; if( depth == 0 ) { DrawTriangle(v1, v2, v3 ); return; } for( i = 0; i < 3; ++i ) { v12[i] = (v1[i]+v2[i])/2.0; v23[i] = (v2[i]+v3[i])/2.0; v31[i] = (v3[i]+v1[i])/2.0; } normalize(v12); normalize(v23); normalize(v31); Subdivide( v1, v12, v31, depth-1 ); Subdivide( v2, v23, v12, depth-1 ); Subdivide( v3, v31, v23, depth-1 ); Subdivide( v12, v23, v31, depth-1 ); }

Please can someone help me figure our the relations between the number of subdivisions and the vertex count as I need this for getting the size of the new array storing the vertex data of the subdivided model.

Thanks in Advance.

Dave