Jump to content
  • Advertisement


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.

If you intended to correct an error in the post then please contact us.

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 this post

Link to post
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.

If I misunderstood what your asking or if your asking for specific "progmatic" help, then I can probably help more.

Share this post

Link to post
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 */;

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 this post

Link to post
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.


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!