Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SkeletalModel.cpp 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*!
  2. * \file src/SkeletalModel.cpp
  3. * \brief This is the factored out skeletal model class
  4. *
  5. * \author Mongoose
  6. * \author xythobuz
  7. */
  8. #include "SkeletalModel.h"
  9. SkeletalModel::SkeletalModel() {
  10. model = NULL;
  11. flags = 0;
  12. mBoneFrame = 0;
  13. mAnimationFrame = 0;
  14. mIdleAnimation = 0;
  15. time = 0.0f;
  16. lastTime = 0.0f;
  17. rate = 0.0f;
  18. }
  19. SkeletalModel::~SkeletalModel() {
  20. //! \fixme Causes "freeing already freed pointer" exceptions or EXEC_BAD_ACCESS
  21. /* if (model) {
  22. for(std::vector<animation_frame_t>::size_type i = 0; i < model->animation.size(); i++) {
  23. animation_frame_t *af = model->animation[i];
  24. if (!af)
  25. continue;
  26. for(std::vector<bone_frame_t>::size_type j = 0; j < af->frame.size(); j++) {
  27. bone_frame_t *bf = af->frame[j];
  28. if (!bf)
  29. continue;
  30. for(std::vector<bone_tag_t>::size_type k = 0; k < bf->tag.size(); k++) {
  31. if (bf->tag[i])
  32. delete bf->tag[i];
  33. }
  34. delete bf;
  35. }
  36. delete af;
  37. }
  38. delete model;
  39. } */
  40. }
  41. int SkeletalModel::getAnimation() {
  42. return mAnimationFrame;
  43. }
  44. int SkeletalModel::getFrame() {
  45. return mBoneFrame;
  46. }
  47. int SkeletalModel::getIdleAnimation() {
  48. return mIdleAnimation;
  49. }
  50. void SkeletalModel::setModel(skeletal_model_t *mdl) {
  51. if (mdl)
  52. model = mdl;
  53. }
  54. void SkeletalModel::setAnimation(int index) {
  55. if (!model) // index > (int)model->animation.size())
  56. return;
  57. animation_frame_t *a = model->animation[index];
  58. if (a) {
  59. mAnimationFrame = index;
  60. mBoneFrame = 0;
  61. rate = a->rate;
  62. }
  63. }
  64. void SkeletalModel::setFrame(int index) {
  65. if (!model)
  66. return;
  67. animation_frame_t *a = model->animation[mAnimationFrame];
  68. if (a) { // index > (int)a->frame.size())
  69. bone_frame_t *b = a->frame[index];
  70. if (b)
  71. mBoneFrame = index;
  72. }
  73. }
  74. void SkeletalModel::setIdleAnimation(int index) {
  75. if (!model)
  76. return;
  77. if (model->animation[index])
  78. mIdleAnimation = index;
  79. }