Model.h 1.1 KB

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