I've got a few questions related with class storing models (meshes) data.
I started with something like this:
class cModel : public cObject {
struct sMesh {
/// number of different vertexes
int diffVertexNum;
float *vertex; // *3
float *normal; // *3
// texture coordinates etc will be here
int realVertexNum;
int *index;
};
int meshNum;
sMesh *mesh;
public:
cModel();
int load(const char *file);
void free();
void draw();
};
And after this part of code I started to think and wonder ;p My problem is not loading or free'ing models, but drawing with high performance and not using too much memo.
1) I want to use indexed vertex arrays - and here the first question - is this the best way ? I want my models to be modifiable, so display lists are not good enough for me, begin/end is slow (but easy to use, this is my other problem (2)). Are there any other (better) methods of drawing geometry?
2) In each tutorial I found model was stored like this:
// pseudocode
struct vertex {
...
};
struct triangle {
int *vertexIndexes;
int normalNum;
vector3 *normal;
...
};
struct mesh {
int triangleNum;
triangle *triArray;
...
};
class model {
int vertexNum;
vertex *vertArray;
int meshNum;
mesh *meshArray;
...
};
Something similar I is in nehe #31, in many net resources, even in Hugi. Is there a method to draw something organized like this really fast (not using glVertex3f / glNormal3f ... in a loop?
3) I think that my model class problem is memory needed to store it. For example - if the model is a cube - each vertex has to be stored three times due to different normal values. (cube isn't smooth). In such not-smooth cases I loose memo on storing vertexes and the NeHe-like model is much better (but still question of drawing it). Is there a way to connect this to styles?
I'll be happy to receive any suggestions, any advice.