I have two classes that represent 3D objects :
1) Mesh, which contains a single simple Mesh
2) Model, which is basically a vector of meshes
Here are my headers :
Code:#include "mesh.hpp" #include <vector> using namespace std; class Model { public: void addObject(Mesh *newObject); void draw(); void description(char * s); private: vector<Mesh*> objects; };I implement the addObject method like thisCode:class Mesh { public: /*------- public methods, getters and setters -----*/ private: unsigned int numVertex; unsigned int numFaces; GLfloat (* vertex)[3]; unsigned int (* face)[3]; unsigned int numTVertex; GLfloat (* tVertex)[2]; unsigned int numTVFaces; unsigned int (* tFace)[3]; GLfloat (* faceNormal)[3]; GLfloat (* vertexNormal)[3]; };
I initialize a Model like this :Code:void Model::addObject(Mesh *newObject) { objects.push_back(newObject); }
The Mesh initializing code works very well, I can see that for each i, newMesh is what I want it to be. But I have two problems.Code:Mesh *newMesh; for(i=0;i<objectCount;i++) { /*---- newMesh initializing code here -----*/ model->addObject ( newMesh ); }
1) The addObject only works for the first. After that I get insane values for the next objects I add.
2) the newMesh pointer is valid only in the scope of the initializing function. Once the program that function, all my vector points to NULL.
If anyone has an idea for any of the two problems, please help. Thanks everyone.



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.