Jump to content
  • Advertisement
Sign in to follow this  
Smigss

Dynamic Array Decleration using custom vertex structure

This topic is 2996 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

So I just got my program to use the mesh and shader to grab information from a file and properly create and texture it. Next i wanted to be able to grab the size of the array's i needed by creating a header in the file so i could allocate the memory for each individual object at creation. Below I've just put out some code that i thought would work for creating a dynamic array so i could use non constant integer values to determine how big the array should be. But i get an error saying the operator where i declare the array byte to a zero value does not take a right hand operand of type int. Any suggestions would be much appreciated.


VertexPosColorTexStruct* vertices = NULL;

vertices = new VertexPosColorTexStruct[VertexSize];
for (int q = 0; q < VertexSize; q++)
{
vertices[q] = 0;

}






P.S. I think it seems sloppy but VertexSize is just a global variable that get's changed inside a seperate function where i call upon the file.

Share this post


Link to post
Share on other sites
Advertisement
Looks to me like vertices[q] is a struct. I'm guessing inside the struct you have somewhere to store actual numerical values? so something like

verticies[q].x = 0;
verticies[q].y = 0;
verticies[q].z = 0;


but you cannot assign an int value directly to the struct itself.
Sound right?

Share this post


Link to post
Share on other sites
correct the structure stores x y z w and uv coordinates for position, color and texture. And they are float values so i can't use an int it seems like for assigning.

Share this post


Link to post
Share on other sites
Reread what PrintFDebugger posted, hes assigning to the members of array element q, vertices[q].x, vertices[q].y, vertices[q].z, etc. Youre trying assign to the entire element with 0, unless youve overloaded the assignment operator to make sense of int assignment, this wont make sense.
Has nothing to do with assigning 0 to float, that can be done, float f = 0, 0 in binary is the same as 0.0. What youre trying to do is

struct SomeStruct {
float x, y, z;
float tu, tv;
};
SomeStruct ss;
ss = 0; // whats int assignment on your new type SomeStuct mean? nothing right now.

Share this post


Link to post
Share on other sites
Yea sorry late, i got what PrintFDebugger was saying. I changed the example to assign zero to an array element and it works to an extent. The decleration of the array size still is not working properly. It's only showing 1 array slot instead of the 776 i need, even though i made VertexSize hold the correct value instead of relying on the file input for debugging purposes.

Share this post


Link to post
Share on other sites
With the size thing, the best thing I've done for myself in ages is upgrade to using vectors. Instant resizing with the same access as arrays, plus a whole heap of great member functions like push, pop, size, etc. Highly recommend you jump on the msdn and look into them.

Share this post


Link to post
Share on other sites
Here is the how the structure is set up:


struct VertexPosColorTexStruct
{
D3DXVECTOR3 Pos;
D3DXVECTOR4 Color;
D3DXVECTOR2 Tex;
};



I guess the question would be can i even reasonably create a dynamic array using this structure, because it contains so many vector elements. Or is there just a better direction to go for handling multiple objects / reading in information.

Share this post


Link to post
Share on other sites
Quote:
Original post by Smigss
The decleration of the array size still is not working properly. It's only showing 1 array slot instead of the 776


How are you seeing this?

Share this post


Link to post
Share on other sites
Quote:
Original post by Smigss
The decleration of the array size still is not working properly. It's only showing 1 array slot instead of the 776 i need, even though i made VertexSize hold the correct value instead of relying on the file input for debugging purposes.
If you're using the debugger, it'll only show 1 element because you have a pointer, not an array. If you want to view the array contents in the variable watch window, put "vertices, 776" (no quotes obviously) in the watch window.

Share this post


Link to post
Share on other sites
Ah i see what your saying Evil Steve. I see this method of creating a pointer to a new array of a custom structure and i just get an exception handle when i try and call mesh->setVertexData(0, vertices).

[Edited by - Smigss on July 6, 2010 8:52:12 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!