-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.hpp
71 lines (54 loc) · 1.7 KB
/
model.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef MODEL_HPP_
#define MODEL_HPP_
#include <string_view>
#include "abcg.hpp"
struct Vertex {
glm::vec3 position{};
glm::vec3 normal{};
glm::vec2 texCoord{};
bool operator==(const Vertex& other) const noexcept {
static const auto epsilon{std::numeric_limits<float>::epsilon()};
return glm::all(glm::epsilonEqual(position, other.position, epsilon)) &&
glm::all(glm::epsilonEqual(normal, other.normal, epsilon)) &&
glm::all(glm::epsilonEqual(texCoord, other.texCoord, epsilon));
}
};
class Model {
public:
Model() = default;
virtual ~Model();
Model(const Model&) = delete;
Model(Model&&) = default;
Model& operator=(const Model&) = delete;
Model& operator=(Model&&) = default;
void loadDiffuseTexture(std::string_view path);
void loadFromFile(std::string_view path, bool standardize = true);
void render() const;
void setupVAO(GLuint program);
[[nodiscard]] int getNumTriangles() const {
return static_cast<int>(m_indices.size()) / 3;
}
[[nodiscard]] glm::vec4 getKa() const { return m_Ka; }
[[nodiscard]] glm::vec4 getKd() const { return m_Kd; }
[[nodiscard]] glm::vec4 getKs() const { return m_Ks; }
[[nodiscard]] float getShininess() const { return m_shininess; }
[[nodiscard]] bool isUVMapped() const { return m_hasTexCoords; }
glm::mat4 m_modelMatrix{1.0f};
private:
GLuint m_VAO{};
GLuint m_VBO{};
GLuint m_EBO{};
glm::vec4 m_Ka;
glm::vec4 m_Kd;
glm::vec4 m_Ks;
float m_shininess;
GLuint m_diffuseTexture{};
std::vector<Vertex> m_vertices;
std::vector<GLuint> m_indices;
bool m_hasNormals{false};
bool m_hasTexCoords{false};
void computeNormals();
void createBuffers();
void standardize();
};
#endif