X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmodel%2FCompositeInstance.hpp;fp=src%2Fmodel%2FCompositeInstance.hpp;h=7d48b76e73fffe7c837c2184b92aff1bed5e471c;hb=2ea26d9ca5eaeae65daa0edbbaeada8c1f23670e;hp=0000000000000000000000000000000000000000;hpb=5304d1e3c1a1e90d474307f4f7eea812a61e483c;p=blank.git diff --git a/src/model/CompositeInstance.hpp b/src/model/CompositeInstance.hpp new file mode 100644 index 0000000..7d48b76 --- /dev/null +++ b/src/model/CompositeInstance.hpp @@ -0,0 +1,55 @@ +#ifndef BLANK_MODEL_COMPOSITEINSTANCE_HPP_ +#define BLANK_MODEL_COMPOSITEINSTANCE_HPP_ + +#include +#include +#include + + +namespace blank { + +class CompositeModel; +class DirectionalLighting; + +// TODO: this doesn't have to be a tree, actually +// linearizing might be a good opportunity to optimize +class CompositeInstance { + + friend class CompositeModel; + +public: + CompositeInstance(); + + operator bool() const noexcept { return part_model; } + + const glm::vec3 &Position() const noexcept { return position; } + void Position(const glm::vec3 &p) noexcept { position = p; } + + const glm::quat &Orientation() const noexcept { return orientation; } + void Orientation(const glm::quat &o) noexcept { orientation = o; } + + glm::mat4 LocalTransform() const noexcept; + glm::mat4 GlobalTransform() const noexcept; + + void Render(const glm::mat4 &, DirectionalLighting &) const; + +private: + CompositeInstance &AddPart(); + bool HasParent() const noexcept { return parent; } + CompositeInstance &Parent() const noexcept { return *parent; } + bool IsRoot() const noexcept { return !HasParent(); } + +private: + const CompositeModel *part_model; + CompositeInstance *parent; + + glm::vec3 position; + glm::quat orientation; + + std::vector parts; + +}; + +} + +#endif