ModelLoader.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include "Header.h"
  2. using namespace std;
  3. #pragma once
  4. class ModelLoader
  5. {
  6. public:
  7. ModelLoader();
  8. ~ModelLoader();
  9. };
  10. class Vec3f
  11. {
  12. public:
  13. union
  14. {
  15. struct
  16. {
  17. float x, y, z;
  18. };
  19. float v[3];
  20. };
  21. Vec3f();
  22. Vec3f(Vec3f &other);
  23. Vec3f(float x, float y, float z);
  24. float& operator [](int);
  25. };
  26. class Vec2f
  27. {
  28. public:
  29. union
  30. {
  31. struct
  32. {
  33. float x, y;
  34. };
  35. float v[2];
  36. };
  37. Vec2f();
  38. Vec2f(float x, float y);
  39. Vec2f(Vec2f &other);
  40. float& operator [](int);
  41. };
  42. class ObjModel
  43. {
  44. private:
  45. class Vertex
  46. {
  47. public:
  48. int position;
  49. int normal;
  50. int texcoord;
  51. };
  52. class Face
  53. {
  54. public:
  55. list<Vertex> vertices;
  56. };
  57. class Texture
  58. {
  59. GLuint index;
  60. public:
  61. Texture(const std::string &fileName);
  62. void bind();
  63. };
  64. class MaterialInfo
  65. {
  66. public:
  67. MaterialInfo();
  68. std::string name;
  69. Texture* texture;
  70. bool hasTexture;
  71. };
  72. class ObjGroup
  73. {
  74. public:
  75. std::string name;
  76. int materialIndex;
  77. list<Face> faces;
  78. };
  79. std::vector<Vec3f> vertices;
  80. std::vector<Vec3f> normals;
  81. std::vector<Vec2f> texcoords;
  82. std::vector<ObjGroup*> groups;
  83. std::vector<MaterialInfo*> materials;
  84. void loadMaterialFile(std::string fileName, std::string dirName);
  85. public:
  86. ObjModel(std::string filename);
  87. ~ObjModel(void);
  88. void draw();
  89. };