]> git.localhorst.tv Git - blank.git/blob - src/model/CompositeInstance.hpp
split composite model in template and instance
[blank.git] / src / model / CompositeInstance.hpp
1 #ifndef BLANK_MODEL_COMPOSITEINSTANCE_HPP_
2 #define BLANK_MODEL_COMPOSITEINSTANCE_HPP_
3
4 #include <vector>
5 #include <glm/glm.hpp>
6 #include <glm/gtc/quaternion.hpp>
7
8
9 namespace blank {
10
11 class CompositeModel;
12 class DirectionalLighting;
13
14 // TODO: this doesn't have to be a tree, actually
15 //       linearizing might be a good opportunity to optimize
16 class CompositeInstance {
17
18         friend class CompositeModel;
19
20 public:
21         CompositeInstance();
22
23         operator bool() const noexcept { return part_model; }
24
25         const glm::vec3 &Position() const noexcept { return position; }
26         void Position(const glm::vec3 &p) noexcept { position = p; }
27
28         const glm::quat &Orientation() const noexcept { return orientation; }
29         void Orientation(const glm::quat &o) noexcept { orientation = o; }
30
31         glm::mat4 LocalTransform() const noexcept;
32         glm::mat4 GlobalTransform() const noexcept;
33
34         void Render(const glm::mat4 &, DirectionalLighting &) const;
35
36 private:
37         CompositeInstance &AddPart();
38         bool HasParent() const noexcept { return parent; }
39         CompositeInstance &Parent() const noexcept { return *parent; }
40         bool IsRoot() const noexcept { return !HasParent(); }
41
42 private:
43         const CompositeModel *part_model;
44         CompositeInstance *parent;
45
46         glm::vec3 position;
47         glm::quat orientation;
48
49         std::vector<CompositeInstance> parts;
50
51 };
52
53 }
54
55 #endif