PolyBone.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. Copyright (C) 2011 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include "PolyGlobals.h"
  21. #include "PolyString.h"
  22. #include "PolyMatrix4.h"
  23. #include "PolySceneEntity.h"
  24. namespace Polycode {
  25. class Mesh;
  26. /**
  27. * Skeleton bone. Bones are bound to vertices of a mesh and when transformed, move the bound vertices of the mesh along with them. Bones are subclassed from SceneEntity, but have their own hierarchy system.
  28. * @see Skeleton
  29. */
  30. class _PolyExport Bone : public SceneEntity {
  31. public:
  32. /**
  33. * Constructor.
  34. * @param boneName Name of the bone.
  35. */
  36. Bone(const String& boneName);
  37. virtual ~Bone();
  38. void enableBoneLabel(const String& labelFont, Number size, Number scale, Color labelColor);
  39. /**
  40. * Returns the name of the bone.
  41. * @return Name of the bone.
  42. */
  43. const String& getName() const;
  44. void Render();
  45. /**
  46. * Sets the parent bone of this bone.
  47. * @param bone New parent bone.
  48. */
  49. void setParentBone(Bone *bone);
  50. /**
  51. * Adds another bone as the child of this bone.
  52. * @param bone New parent bone.
  53. */
  54. void addChildBone(Bone *bone);
  55. /**
  56. * Returns the parent bone of this bone.
  57. * @return Parent bone of this bone.
  58. */
  59. Bone* getParentBone();
  60. /**
  61. * Returns the number of child bones of this bone.
  62. * @return Number of child bones.
  63. */
  64. int getNumChildBones();
  65. /**
  66. * Returns the child bone of this bone at the specified index.
  67. * @param index Index of the child bone to return.
  68. * @return Parent bone of this bone.
  69. */
  70. Bone *getChildBone(unsigned int index);
  71. /**
  72. * Returns the bone matrix
  73. * @return Bone matrix.
  74. */
  75. Matrix4 getBoneMatrix() const;
  76. /**
  77. * Sets the bone matrix.
  78. * @return Bone matrix.
  79. */
  80. void setBoneMatrix(const Matrix4& matrix);
  81. /**
  82. * Returns the rest matrix of this bone.
  83. * @return Rest matrix.
  84. */
  85. Matrix4 getRestMatrix() const;
  86. /**
  87. * Returns the full rest matrix of this bone.
  88. * @return Full rest matrix.
  89. */
  90. Matrix4 getFullRestMatrix() const;
  91. /**
  92. * Returns the rest matrix of this bone's parent.
  93. * @return Rest matrix of the bone's parent.
  94. */
  95. Matrix4 getParentRestMatrix() const;
  96. /**
  97. * @see getBoneMatrix()
  98. */
  99. Matrix4 getFinalMatrix() const;
  100. /**
  101. * Sets the rest matrix for this bone.
  102. * @param matrix New rest matrix.
  103. */
  104. void setRestMatrix(const Matrix4& matrix);
  105. /**
  106. * Sets the base matrix for this bone.
  107. * @param matrix New base matrix.
  108. */
  109. void setBaseMatrix(const Matrix4& matrix);
  110. /**
  111. * Returns the base matrix of this bone.
  112. * @return Base matrix.
  113. */
  114. const Matrix4& getBaseMatrix() const { return baseMatrix; }
  115. /**
  116. * Returns the full base matrix of this bone.
  117. * @return Full base matrix.
  118. */
  119. Matrix4 getFullBaseMatrix() const;
  120. /**
  121. * Id of the bone.
  122. */
  123. int parentBoneId;
  124. Matrix4 boneMatrix;
  125. Matrix4 restMatrix;
  126. Matrix4 baseMatrix;
  127. protected:
  128. Mesh *boneMesh;
  129. Bone* parentBone;
  130. std::vector<Bone*> childBones;
  131. String boneName;
  132. };
  133. }