Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  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);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement