]> git.localhorst.tv Git - blank.git/blob - src/model/Part.hpp
apply pitch to head instead of body
[blank.git] / src / model / Part.hpp
1 #ifndef BLAMK_MODEL_PART_HPP_
2 #define BLAMK_MODEL_PART_HPP_
3
4 #include "geometry.hpp"
5
6 #include <cstdint>
7 #include <list>
8 #include <memory>
9 #include <vector>
10 #include <glm/glm.hpp>
11 #include <glm/gtc/quaternion.hpp>
12
13
14 namespace blank {
15
16 class DirectionalLighting;
17 class EntityMesh;
18 class Instance;
19 class Model;
20 class ResourceIndex;
21 class Shape;
22 class ShapeRegistry;
23 class TokenStreamReader;
24
25 struct Part {
26
27 public:
28         struct State {
29                 glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f);
30                 glm::quat orientation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f);
31         };
32
33         Part();
34         ~Part();
35
36         void Read(TokenStreamReader &, ResourceIndex &, const ShapeRegistry &);
37
38         Part &AddChild();
39         const std::list<Part> &Children() const noexcept { return children; }
40
41         std::uint16_t Enumerate(std::uint16_t) noexcept;
42         void Index(std::vector<Part *> &) noexcept;
43
44         std::uint16_t ID() const noexcept { return id; }
45
46         glm::mat4 LocalTransform(const Instance &) const noexcept;
47         glm::mat4 GlobalTransform(const Instance &) const noexcept;
48
49         void Render(
50                 const glm::mat4 &,
51                 const Instance &,
52                 DirectionalLighting &) const;
53
54 private:
55         const Part *parent;
56         const Shape *shape;
57         std::list<Part> children;
58         std::vector<float> tex_map;
59         mutable std::unique_ptr<EntityMesh> mesh;
60         State initial;
61         glm::vec3 hsl_mod;
62         glm::vec3 rgb_mod;
63         std::uint16_t id;
64
65 };
66
67 }
68
69 #endif