COGS
Computer Graphics Structures library
Bone.h
1 /*
2  Copyright (C) Skeletex Research, s.r.o. - All Rights Reserved
3  Unauthorized copying of this file, via any medium is strictly prohibited
4  Proprietary and confidential
5 */
6 #ifndef COGS_BONE_H
7 #define COGS_BONE_H
8 #include <Utils/GeometryStructures.h>
9 
10 #include <COGS/API.h>
11 #include <COGS/BoneTransform.h>
12 
13 namespace cogs
14 {
15 
16  class Skeleton;
17 
18  class COGS_API Bone
19  {
20  public:
21 
23  uint32_t GetId() const;
24 
26  std::string GetName() const;
27 
29  glm::vec3 GetHead() const;
30 
32  glm::vec3 GetTail() const;
33 
35  void SetTail(glm::vec3 tail);
36 
37  enum PropertyType
38  {
39  HEAD_RADIUS, TAIL_RADIUS,
40  SEP_WEIGHT,
41  SEP_LINE_DIRX, SEP_LINE_DIRY, SEP_LINE_DIRZ,
42  IGNORED_NEIGHBOUR
43  };
44 
46  float GetProperty(const PropertyType prop) const;
47 
49  float GetProperty(const PropertyType prop, const float default_value) const;
50 
52  void SetProperty(const PropertyType prop, const float value);
53 
55  bool HasProperty(const PropertyType prop) const;
56 
58  float GetLength() const;
59 
61  void SetLength(const float new_length);
62 
64  glm::vec3 GetDirection() const;
65 
67  glm::mat4 GetBasisMat4() const;
68 
70  glm::mat3 GetBasisMat3() const;
71 
73  glm::vec3 GetBasisVector(const geom::Axis axis) const;
74 
76  glm::mat4 GetGlobalTransformHead() const;
77 
79  glm::mat4 GetGlobalTransformTail() const;
80 
82  const BoneTransform &GetTransform() const;
83 
85  void Roll(const float &angle);
86 
88  void LocalRoll(const float &angle);
89 
91  void Pitch(const float &angle);
92 
94  void Yaw(const float &angle);
95 
97  bool IsRoot() const;
98 
100  bool IsLeaf() const;
101 
103  Bone *GetParent() const;
104 
106  uint32_t GetChildrenCount() const;
107 
109  std::vector<Bone *> GetChildren() const;
110 
112  std::vector<Bone *> GetHeadNeigbours() const;
113 
115  glm::ivec4 GetHeadNeigbourIds() const;
116 
118  std::vector<Bone *> GetTailNeigbours() const;
119 
121  glm::ivec4 GetTailNeigbourIds() const;
122 
124  void Rotate(const glm::quat &rotation);
125 
127  void RotateToDirection(glm::vec3 new_bone_direction);
128 
130  glm::vec3 ToVector() const;
131 
133  geom::LineSegment3 ToLineSegment() const;
134 
136  geom::Line3 ToLine() const;
137 
139  geom::ConicalCapsule ToConicalCapsule() const;
140 
142  void SortChildrenByBone(const Bone &bone);
143 
144  protected:
145  friend Skeleton;
146 
147  explicit Bone(const uint32_t id, const std::string caption);
148 
149  uint32_t id_;
150  std::string caption_;
151 
152  Skeleton *skeleton_owner_ = nullptr;
153  Bone *parent_ = nullptr;
154  std::vector<Bone *> children_;
155 
156  std::unordered_map<PropertyType, float> properties_;
157 
158  BoneTransform transform_;
159  BoneTransform bindpose_transform_;
160 
161  struct Cache
162  {
163  glm::mat4 global_transform_head;
164  glm::mat4 global_transform_tail;
165  glm::vec3 head;
166  glm::vec3 tail;
167  glm::mat3 basis;
168  } cache_;
169 
170  glm::mat4 GetParentTransform();
171 
172  void ApplyBindpose();
173  void ApplyCurrentPoseAsBindpose();
174 
175  void UpdateTransformCache();
176 
177  void UpdateTransformCacheRecursive();
178 
179  void ResetBindposeTransform(const BoneTransform &new_transform);
180  void ResetBindposeTransformRecursive(const BoneTransform &new_transform);
181 
182  };
183 
184  std::vector<geom::LineSegment3> BonesToLines(const std::vector<cogs::Bone *> &bones);
185 }
186 #endif /* !COGS_BONE_H */
Namespace of "Computer Graphic Structures" library, which implement many core classes and structures...
Definition: AabbHierarchy.h:8