Filling CUSTOMVERTEX structure

Started by
2 comments, last by dev578 19 years, 10 months ago
To do simple shapes, I have been manually filling my CUSTOMVERTEX structure like this: struct CUSTOMVERTEX { float x, y, z; }; CUSTOMVERTEX g_Vertices[] = { {-10.0f,-5.0f, 10.0f}, { 10.0f,-5.0f, 10.0f}, {-10.0f,-5.0f,-10.0f}, { 10.0f,-5.0f,-10.0f} }; Now I have a terrain generator, which spits out x,y,z coords in a long for loop. How would I fill out g_Vertices everytime I get an x,y,z data point? Any help is appreciated. -Dev578
Advertisement
I am not quite sure what you mean "in a long for loop".

If the generator is randomly generating them on the fly, then (although I am no expert on this) I would suppose you would have to lock your buffer, modify the values, and unlock it for every terrain change.

I believe there is another way to do it without locking, but I am not advanced enough to know exactly how.

If I misunderstood what your asking or if your asking for specific "progmatic" help, then I can probably help more.
You will need to know a priori how many vertices your generator will output (but at runtime, not neccessarily compile time). You can probaby calculate this from the size of the terrain at runtime.

Then you can utilize the dynamic allocation facilities of C++:

int           numVtxs = /* some calculation here */;CUSTOMVERTEX *vtxBuf  = new CUSTOMVERTEX[numVtxs];  for(int j = 0; j < numVtxs; ++j)  {    /* Get next vertex from your terrain generator, and: */    vtxBuf[j].x = vertex.x;    vtxBuf[j].y = vertex.y;    vtxBuf[j].z = vertex.z;  } 


vtxBuf replaces your g_Vertices in my example, so you should adjust accordingly. Once you are done using the vertices you must free them via:

delete[] vtxBuf; 


EDIT: Change of index to avoid making text italic.

[edited by - jpetrie on June 4, 2004 12:29:41 PM]
TYVM jpetrie, that was what I was trying to do. I didn''t realize that I had to do CUSTOMVERTEX*. I just ran into another problem though, and have been working at it all day. I am trying to create a function to make an x,z square (plane) with as many vertices as you specify in the function. It never turns out as a square, I have no idea how to get the vertices in the right order mathematically. Any help is appreciated.

-Dev578

This topic is closed to new replies.

Advertisement