object.hpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #pragma once
  2. #include <vector>
  3. #include <glm/glm.hpp>
  4. #include <glm/gtx/transform.hpp>
  5. #include <mesh.hpp>
  6. namespace gb
  7. {
  8. class Object
  9. {
  10. private:
  11. using mesh_list_t = std::vector<Mesh>;
  12. public:
  13. explicit Object(
  14. const mesh_list_t& meshes,
  15. const glm::vec3& pos = {0.f, 0.f, 0.f},
  16. const glm::vec3& scale = {1.f, 1.f, 1.f},
  17. const glm::vec3& rotate_axis = {0.f, 0.f, 1.f},
  18. float rotate_angle = 0.f
  19. );
  20. explicit Object(
  21. mesh_list_t&& meshes,
  22. const glm::vec3& pos = {0.f, 0.f, 0.f},
  23. const glm::vec3& scale = {1.f, 1.f, 1.f},
  24. const glm::vec3& rotate_axis = {0.f, 0.f, 1.f},
  25. float rotate_angle = 0.f
  26. );
  27. template <typename Framebuffer, typename Camera>
  28. void draw(Framebuffer& fb, const Camera& camera) const
  29. {
  30. for (const auto& mesh : m_meshes)
  31. {
  32. auto c_mesh = mesh.apply(camera.view_mat() * m_model_mat);
  33. draw_mesh(fb, c_mesh);
  34. }
  35. }
  36. private:
  37. void calc_model_mat(void);
  38. private:
  39. mesh_list_t m_meshes;
  40. glm::vec3 m_pos;
  41. float m_rotate_angle;
  42. glm::vec3 m_rotate_axis;
  43. glm::vec3 m_scale;
  44. glm::mat4 m_model_mat;
  45. };
  46. } // namespace gb