Lugdunum  0.1.0
Node.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <vector>
6 #include <lug/Math/Matrix.hpp>
8 #include <lug/Math/Vector.hpp>
9 
10 namespace lug {
11 namespace Graphics {
12 
14 public:
15  enum class TransformSpace : uint8_t {
16  Local,
17  Parent,
18  World
19  };
20 
21 public:
22  Node(const std::string& name);
23 
24  Node(const Node&) = delete;
25  Node(Node&&) = delete;
26 
27  Node& operator=(const Node&) = delete;
28  Node& operator=(Node&&) = delete;
29 
30  virtual ~Node() = default;
31 
32  void setParent(Node *parent);
33  Node* getParent() const;
34 
35  const std::string& getName() const;
36 
37  Node* getNode(const std::string& name);
38  const Node* getNode(const std::string& name) const;
39 
40  const Math::Vec3f& getAbsolutePosition();
41  const Math::Quatf& getAbsoluteRotation();
42  const Math::Vec3f& getAbsoluteScale();
43 
44  const Math::Mat4x4f& getTransform();
45 
46  const std::vector<Node*>& getChildren() const;
47 
48  void attachChild(Node& child);
49 
50  void translate(const Math::Vec3f& direction, TransformSpace space = TransformSpace::Local);
51  void rotate(float angle, const Math::Vec3f& axis, TransformSpace space = TransformSpace::Local);
52  void rotate(const Math::Quatf& quat, TransformSpace space = TransformSpace::Local);
53  void scale(const Math::Vec3f& scale);
54 
55  void setPosition(const Math::Vec3f& position, TransformSpace space = TransformSpace::Local);
56  void setRotation(float angle, const Math::Vec3f& axis, TransformSpace space = TransformSpace::Local);
57  void setRotation(const Math::Quatf& rotation, TransformSpace space = TransformSpace::Local);
58 
67  void setDirection(const Math::Vec3f& spaceTargetDirection, const Math::Vec3f& localDirectionVector, const Math::Vec3f& localUpVector, TransformSpace space = TransformSpace::Local);
68 
77  void lookAt(const Math::Vec3f& targetPosition, const Math::Vec3f& localDirectionVector, const Math::Vec3f& localUpVector, TransformSpace space = TransformSpace::Local);
78 
79  virtual void needUpdate();
80 private:
81  void update();
82 
83 protected:
84  Node* _parent{nullptr};
85 
86  std::string _name;
87  std::vector<Node*> _children;
88 
89 private:
90  Math::Vec3f _position{Math::Vec3f(0.0f)};
91  Math::Quatf _rotation{Math::Quatf::identity()};
92  Math::Vec3f _scale{Math::Vec3f(1.0f)};
93 
94  Math::Vec3f _absolutePosition{Math::Vec3f(0.0f)};
95  Math::Quatf _absoluteRotation{Math::Quatf::identity()};
96  Math::Vec3f _absoluteScale{Math::Vec3f(1.0f)};
97 
98  Math::Mat4x4f _transform{Math::Mat4x4f::identity()};
99 
100  bool _needUpdate{true};
101 };
102 
103 #include <lug/Graphics/Node.inl>
104 
105 } // Graphics
106 } // lug
std::vector< Node * > _children
Definition: Node.hpp:87
Matrix< 4, 4, T > scale(const Vector< 3, T > &factors)
Definition: Transform.inl:41
#define LUG_GRAPHICS_API
Definition: Export.hpp:11
Matrix< 4, 4, T > translate(const Vector< 3, T > &direction)
Definition: Transform.inl:2
std::string _name
Definition: Node.hpp:86
Matrix< 4, 4, T > lookAt(const Vector< 3, T > &eye, const Vector< 3, T > &center, const Vector< 3, T > &up)
Definition: Transform.inl:52
Matrix< 4, 4, T > rotate(T angle, const Vector< 3, T > &a)
Definition: Transform.inl:13
Quaternion< float > Quatf
Definition: Quaternion.hpp:75