Archived

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

unebaguettesvp

multidimensional dynamic arrays or vectors?

Recommended Posts

hi- i could really use some help with this opengl demo that im creating. its not actually an opengl question but more of a c++ question. so im trying to create a class that has three two dimensional arrays and one one dimensional array as private members and i have a function as a public member that loads these arrays. here is the declaration: class cINeedHelpPlease { private: int *texCount; // 1-D Array char *texFiles; // 2-D Array float *texCoords; // 2-D Array float *vertexCoords; // 2-D Array public: void load(int texCountLOAD[], char texFilesLOAD[][12], GLfloat texCoordsLOAD[][2], GLfloat vertexCoordsLOAD[][3]); }; so that is the essential part of this class. i''m having a huge problem passing the arrays to the member function and storing those arrays in the dynamic arrays, single and mulitdimensional. so my question is how do i set up the load member function? i''ve tried it but i''ve had no luck. i don''t understand what i''m doing wrong. should i be using vectors instead of dynamic arrays to hold 3D vertices? ANY help would be appreciated. thank you for your time.

Share this post


Link to post
Share on other sites
You might try gonig this way:

Declare a structure like:

struct tTexInfo
{
char filename[255];
float *texCoords;
float *vertexCoords;
};

Then, declare some kind of a template library, for example, by using STL or any other linked list type like:

CLibrary myTexInfos;

Then, if your library class was of type, say, from STL, you can easily access its size by size() function, and access each member by using in-built function for_each or just for loop like:
for (vector::iterator it = myTexInfos.begin(); it < myTexInfos.end(); ++it);
{
// do your stuff here
}

As for the ad function, here''s a sample for it:

void AddTex(char *filename, int *texcount, float *texCoords, float *vertexCoords)
{
// etc etc
}

Well, you also can declare other variables as libraries of type in the same way as you did with myTexInfos, i.e:
CLibrary texCount
CLibrary texFiles
etc etc


Well, here you go. If you need any help with CLibrary class, reply here, and I''ll give you code.

Good luck.

" Do we need us? "


Ionware Productions - Games and Game Tools Development

Share this post


Link to post
Share on other sites
ok this is the furthest ive gotten. this code compiles and runs but not all of the vertices are loading up. i know that it is a problem with my dynamic arrays. so here is the relevant code:


this is in the main code:

cHelp SP1;

SP1.load(sp1TexCount, sp1TexFiles, sp1TexCoords, sp1Vertex);


this is in the class header:

class cHelp {
private:
int *texCount;
char (*texFiles)[12];
GLfloat (*texCoords)[2];
GLfloat (*vertexCoords)[3];

public:
void load(int texCountLOAD[], char texFilesLOAD[][12], GLfloat texCoordsLOAD[][2], GLfloat vertexCoordsLOAD[][3]);
};


this is in the class code:

void cHelp::load(int texCountLOAD[], char texFilesLOAD[][12], GLfloat texCoordsLOAD[][2], GLfloat vertexCoordsLOAD[][3]) {
texCount = new int[sizeof(texCountLOAD) / sizeof(int)];
texCount = texCountLOAD;

texFiles = new char[sizeof(texFilesLOAD) / sizeof(texFilesLOAD[0])][12];
texFiles = texFilesLOAD;

texCoords = new GLfloat[sizeof(texCoordsLOAD) / sizeof(texCoordsLOAD[0])][2];
texCoords = texCoordsLOAD;

vertexCoords = new GLfloat[sizeof(vertexCoordsLOAD) / sizeof(vertexCoordsLOAD[0])][3];
vertexCoords = vertexCoordsLOAD;
}


as i said before this compiles and runs but not all of the vertices load up. so only part of the character loads. i know that it is a problem with my dynamic arrays. so what am i doing wrong? should i even be using dynamic arrays? should i use vectors? im dont know what STL is. so if you wouldnt mind posting that code, i would appreciate it. but my main problem is with these dynamic arrays. i dont understand why im having such a tough time declaring them inside a class. ive done dynamic arrays before but not mulitdimensional ones. thanks in advance. any help would be appreciated.

Share this post


Link to post
Share on other sites
awesome. i finally figured it out. the only reason why im posting this is to help other people in the future. i hope it does.

the problem was with the sizeof() function. i ended up putting all of the vertices and texture coordinates in a .txt file because i was so sick of working on this project and i needed to try something new (i was ready to give up opengl!). anyway it still wasnt working. so i started to fool around with the sizeof function. i finally got it to work. so in conclusion, fool around with sizeof() (if you are using it) before you rip your hair out.

thank you to the people who replied to my post to try to help me. i really appreciate it.

onward.

Share this post


Link to post
Share on other sites