#### Archived

This topic is now archived and is closed to further replies.

# Filling CUSTOMVERTEX structure

This topic is 5281 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
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.

##### Share on other sites
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]

##### Share on other sites
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

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

• 9
• 27
• 20
• 9
• 15
• ### Forum Statistics

• Total Topics
633392
• Total Posts
3011639
• ### Who's Online (See full list)

There are no registered users currently online

×