I'm relatively new to OpenGL and have been using the GLTools library it provides. One of the classes, GLTriangleBatch, in part, deals with batches of vertexs. The class has a global attribute pointer pVerts declared as follows:
typedef float M3DVector3f[3];
M3DVector3f *pVerts;
When an initializing function is called, the above pointer is delegated a block of memory with the number of indexs being an int provided to the function as an argument(nMaxIndexes):
pVerts = new M3DVector3f[nMaxIndexes];
Another function is given an array of 3 M3DVector3fs that comprise vertex points of a triangle. This function determines which individual vertices are added to the batch or not.
For example, if the point to be added already exists in pVerts, the index of that point in pVerts is added to another array which holds the index of all points that will be drawn. Therefore pVerts contains only unique points. Therefore the actual index of pVerts will never reach nMaxIndexes.
However, in the case that it is a unique vertex, it is added to pVerts as follows:
memcpy(pVerts[nNumVerts], verts[iVertex], sizeof(M3DVector3f));
where nNumVerts is the current index of pVerts, verts[] is the array of 3 M3DVector3f's that comprise the triangle being added with iVertex being the index of the particular vertexbeing added.
Now i use another function that calculates the positions of vertex points to build a (rough) sphere. The sphere i build in my program ends up with nMaxIndexes = 2028, and when the sphere is completed nNumVerts = 378.
Now following all of this i assumed pVerts pointed to an array of index ranging 0 to 2027, but only indexes 0 to 377 being populated with data. But when i put a breakpoint directly after all the vertices are added, pVerts points only a single M3DVector3f.
I need access to each of these individual points as I plan to use this sphere as a collidible boundary. I have added a getVertices function that returns pVerts, but the returned pointer only points to a single M3DVector3f? What am i missing?
memcpy(pVerts[nNumVerts], verts[iVertex], sizeof(M3DVector3f));is not correct as it stands, aspVerts[n]dereferences a pointer with offset n to the address pVerts points to. The correct line ismemcpy(&pVerts[nNumVerts], &verts[iVertex], sizeof(M3DVector3f));ormemcpy(pVerts+nNumVerts, verts+iVertex, sizeof(M3DVector3f));&.