Model.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #pragma once
  2. #include <GL/freeglut.h>
  3. #include <list>
  4. #include <vector>
  5. #include <map>
  6. #include "Vector.h"
  7. #include "Vertex.h"
  8. class Model
  9. {
  10. private:
  11. class VertexIndex
  12. {
  13. public:
  14. int position;
  15. int normal;
  16. int texcoord;
  17. };
  18. class Face
  19. {
  20. public:
  21. std::list<VertexIndex> vertices;
  22. };
  23. class Texture
  24. {
  25. GLuint index;
  26. public:
  27. Texture(const std::string &fileName);
  28. void bind();
  29. };
  30. class MaterialInfo
  31. {
  32. public:
  33. MaterialInfo();
  34. std::string name;
  35. Texture* texture;
  36. bool hasTexture;
  37. bool hasDiffuse;
  38. Vec3f diffuseColor;
  39. bool hasAmbient;
  40. Vec3f ambientColor;
  41. bool hasSpecular;
  42. Vec3f specularColor;
  43. };
  44. class ObjGroup
  45. {
  46. public:
  47. std::string name;
  48. int materialIndex;
  49. std::list<Face> faces;
  50. std::vector<Vertex> VertexArray;
  51. };
  52. std::vector<Vec3f> vertices;
  53. std::vector<Vec3f> normals;
  54. std::vector<Vec2f> texcoords;
  55. std::vector<ObjGroup*> groups;
  56. std::vector<MaterialInfo*> materials;
  57. void loadMaterialFile(std::string fileName, std::string dirName);
  58. Model(std::string filename);
  59. ~Model(void);
  60. public:
  61. static std::map<std::string, std::pair<Model*, int> > cache;
  62. static Model* load(const std::string &fileName);
  63. static void unload(Model* model);
  64. void draw();
  65. void Optimise(ObjGroup *t);
  66. Vec3f minVertex;
  67. Vec3f maxVertex;
  68. Vec3f center;
  69. float radius;
  70. };