Skeleton.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // ----------------------------------------------------------------
  2. // From Game Programming in C++ by Sanjay Madhav
  3. // Copyright (C) 2017 Sanjay Madhav. All rights reserved.
  4. //
  5. // Released under the BSD License
  6. // See LICENSE in root directory for full details.
  7. // ----------------------------------------------------------------
  8. #pragma once
  9. #include "BoneTransform.h"
  10. #include <string>
  11. #include <vector>
  12. class Skeleton
  13. {
  14. public:
  15. // Definition for each bone in the skeleton
  16. struct Bone
  17. {
  18. BoneTransform mLocalBindPose;
  19. std::string mName;
  20. int mParent;
  21. };
  22. // Load from a file
  23. bool Load(const std::string& fileName);
  24. // Getter functions
  25. size_t GetNumBones() const { return mBones.size(); }
  26. const Bone& GetBone(size_t idx) const { return mBones[idx]; }
  27. const std::vector<Bone>& GetBones() const { return mBones; }
  28. const std::vector<Matrix4>& GetGlobalInvBindPoses() const { return mGlobalInvBindPoses; }
  29. protected:
  30. // Called automatically when the skeleton is loaded
  31. // Computes the global inverse bind pose for each bone
  32. void ComputeGlobalInvBindPose();
  33. private:
  34. // The bones in the skeleton
  35. std::vector<Bone> mBones;
  36. // The global inverse bind poses for each bone
  37. std::vector<Matrix4> mGlobalInvBindPoses;
  38. };