You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.3 KiB

  1. #pragma once
  2. #include "ggl.h"
  3. #include "vertexbuffer.h"
  4. #include "shader.h"
  5. #include <vector>
  6. #include "Glm/glm.hpp"
  7. #include "Glm/ext.hpp"
  8. struct VertexIndex
  9. {
  10. int position;
  11. int texcoord;
  12. int normal;
  13. };
  14. class Model {
  15. public:
  16. VertexBuffer* mVertexBuffer;
  17. Shader* mShader;
  18. public:
  19. glm::mat4 mModelMatrix;
  20. float *mLightViewMatrix, *mLightProjectionMatrix;
  21. Model();
  22. void Init(const char *modelPath);
  23. void Draw(glm::mat4 &viewMatrix, glm::mat4 projectionMatrix, float x, float y, float z);
  24. void SetPosition(float x, float y, float z);
  25. void SetAmbientMaterial(float r, float g, float b, float a);
  26. void SetDiffuseMaterial(float r, float g, float b, float a);
  27. void SetSpecularMaterial(float r, float g, float b, float a);
  28. void SetTexture(const char*imagePath);
  29. private:
  30. unsigned char* fileContent = nullptr;
  31. std::vector<glm::float3> position;
  32. std::vector<glm::float3> texcoord;
  33. std::vector<glm::float3> normal;
  34. std::vector<VertexIndex> vertices;
  35. void parseModel();
  36. void parseLine(const char* line);
  37. glm::float3 parseFloat(const char* line);
  38. VertexIndex parseVertexIndex(std::string pointStr);
  39. int addVertices(VertexIndex indexes);
  40. void parseTexcoord(const char* line);
  41. void parseNormal(const char* line);
  42. void parsePosition(const char* line);
  43. void parseFace(const char* line);
  44. void createVertexBuffer();
  45. };