Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Model
- {
- public:
- /* Model Data */
- /...
- //using default constructor
- Mesh createMesh() {
- Mesh mesh;
- meshes.push_back(mesh);
- return mesh;
- }
- void addVertex(Mesh mesh, Vertex v) {
- mesh.addVertex(v);
- }
- void addTriangle(Mesh mesh, Vertex a, Vertex b, Vertex c) {
- mesh.addTriangle(a,b,c);
- }
- /...
- class Mesh {
- public:
- /* Mesh Data */
- vector<Vertex> vertices;
- vector<unsigned int> indices;
- /...
- // constructor
- Mesh(vector<Vertex> vertices, vector<unsigned int> indices, vector<Texture> textures)
- {
- this->vertices = vertices;
- this->indices = indices;
- this->textures = textures;
- for (Vertex v: vertices) {
- pairings.insert( std::pair<Vertex,unsigned int>(v,count) );
- count++;
- }
- setupMesh();
- }
- Mesh () {
- }
- //function 1
- void addVertex(Vertex vertex) {
- vertices.push_back(vertex);
- pairings.insert( std::pair<Vertex,unsigned int>(vertex,count));
- count++;
- }
- //function 2
- void addTriangle(Vertex a, Vertex b, Vertex c) {
- unsigned int index = pairings[a];
- indices.push_back(index);
- index = pairings[b];
- indices.push_back(index);
- index = pairings[c];
- indices.push_back(index);
- setupMesh();
- }
- Model m;
- Mesh mesh = m.createMesh();
- Vertex a;
- a.Position = glm::vec3 (-1,0,0);
- m.addVertex(mesh, a);
- Vertex b;
- b.Position = glm::vec3 (0,1,0);
- m.addVertex(mesh,b);
- Vertex c;
- c.Position = glm::vec3 (1,0,0);
- m.addVertex(mesh,c);
- m.addTriangle(mesh,a,b,c);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement