SHARE
TWEET

Untitled

a guest Jun 18th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Model
  2. {
  3. public:
  4.     /*  Model Data */
  5.     /...
  6.  
  7.     //using default constructor
  8.  
  9.     Mesh createMesh() {
  10.         Mesh mesh;
  11.         meshes.push_back(mesh);
  12.         return mesh;
  13.     }
  14.  
  15.     void addVertex(Mesh mesh, Vertex v) {
  16.         mesh.addVertex(v);
  17.     }
  18.     void addTriangle(Mesh mesh, Vertex a, Vertex b, Vertex c) {
  19.         mesh.addTriangle(a,b,c);
  20.     }
  21. /...
  22.      
  23. class Mesh {
  24. public:
  25.     /*  Mesh Data  */
  26.     vector<Vertex> vertices;
  27.     vector<unsigned int> indices;
  28.     /...
  29. // constructor
  30.     Mesh(vector<Vertex> vertices, vector<unsigned int> indices, vector<Texture> textures)
  31.     {
  32.         this->vertices = vertices;
  33.         this->indices = indices;
  34.         this->textures = textures;
  35.         for (Vertex v: vertices) {
  36.             pairings.insert( std::pair<Vertex,unsigned int>(v,count) );
  37.             count++;
  38.         }
  39.         setupMesh();
  40.     }
  41.     Mesh () {
  42.  
  43.     }
  44.  
  45.     //function 1
  46.     void addVertex(Vertex vertex) {
  47.         vertices.push_back(vertex);
  48.         pairings.insert( std::pair<Vertex,unsigned int>(vertex,count));
  49.         count++;
  50.     }
  51.  
  52.     //function 2
  53.     void addTriangle(Vertex a, Vertex b, Vertex c) {
  54.         unsigned int index = pairings[a];
  55.         indices.push_back(index);
  56.         index = pairings[b];
  57.         indices.push_back(index);
  58.         index = pairings[c];
  59.         indices.push_back(index);
  60.         setupMesh();
  61.     }
  62.      
  63. Model m;
  64.     Mesh mesh = m.createMesh();
  65.     Vertex a;
  66.     a.Position = glm::vec3 (-1,0,0);
  67.     m.addVertex(mesh, a);
  68.     Vertex b;
  69.     b.Position = glm::vec3 (0,1,0);
  70.     m.addVertex(mesh,b);
  71.     Vertex c;
  72.     c.Position = glm::vec3 (1,0,0);
  73.     m.addVertex(mesh,c);
  74.     m.addTriangle(mesh,a,b,c);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top