]> git.localhorst.tv Git - blank.git/blob - src/model/CompositeInstance.hpp
send entity visual from server to client
[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         const CompositeModel &GetModel() const noexcept { return *part_model; }
25
26         const glm::vec3 &Position() const noexcept { return position; }
27         void Position(const glm::vec3 &p) noexcept { position = p; }
28
29         const glm::quat &Orientation() const noexcept { return orientation; }
30         void Orientation(const glm::quat &o) noexcept { orientation = o; }
31
32         glm::mat4 LocalTransform() const noexcept;
33         glm::mat4 GlobalTransform() const noexcept;
34
35         void Render(const glm::mat4 &, DirectionalLighting &) const;
36
37 private:
38         CompositeInstance &AddPart();
39         bool HasParent() const noexcept { return parent; }
40         CompositeInstance &Parent() const noexcept { return *parent; }
41         bool IsRoot() const noexcept { return !HasParent(); }
42
43 private:
44         const CompositeModel *part_model;
45         CompositeInstance *parent;
46
47         glm::vec3 position;
48         glm::quat orientation;
49
50         std::vector<CompositeInstance> parts;
51
52 };
53
54 }
55
56 #endif