Dynamic Array Decleration using custom vertex structure

Started by
9 comments, last by Smigss 13 years, 9 months ago
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.
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?
The high cost of living hasn't affected its popularity.
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.
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.
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.
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.
The high cost of living hasn't affected its popularity.
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.
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?
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.
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]

This topic is closed to new replies.

Advertisement