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 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*!
  2. * \file src/SkeletalModel.cpp
  3. * \brief This is the factored out skeletal model class
  4. *
  5. * \author Mongoose
  6. */
  7. #include "SkeletalModel.h"
  8. ////////////////////////////////////////////////////////////
  9. // Constructors
  10. ////////////////////////////////////////////////////////////
  11. SkeletalModel::SkeletalModel()
  12. {
  13. model = 0x0;
  14. flags = 0;
  15. mBoneFrame = 0;
  16. mAnimationFrame = 0;
  17. mIdleAnimation = 0;
  18. time = 0.0f;
  19. lastTime = 0.0f;
  20. rate = 0.0f;
  21. }
  22. SkeletalModel::~SkeletalModel()
  23. {
  24. if (model)
  25. {
  26. for (model->animation.start();
  27. model->animation.forward();
  28. model->animation.next())
  29. {
  30. animation_frame_t *af = model->animation.current();
  31. if (!af)
  32. continue;
  33. for (af->frame.start(); af->frame.forward(); af->frame.next())
  34. {
  35. bone_frame_t *bf = af->frame.current();
  36. if (!bf)
  37. continue;
  38. bf->tag.erase();
  39. //for (bf->tag.start(); bf->tag.forward(); bf->tag.next())
  40. //{
  41. // if (bf->tag.current())
  42. // delete bf->tag.current();
  43. //}
  44. delete bf;
  45. }
  46. af->frame.clear();
  47. delete af;
  48. }
  49. model->animation.clear();
  50. //! \fixme Causes "freeing already freed pointer" exception
  51. //delete model;
  52. }
  53. }
  54. ////////////////////////////////////////////////////////////
  55. // Public Accessors
  56. ////////////////////////////////////////////////////////////
  57. int SkeletalModel::getAnimation()
  58. {
  59. return mAnimationFrame;
  60. }
  61. int SkeletalModel::getFrame()
  62. {
  63. return mBoneFrame;
  64. }
  65. int SkeletalModel::getIdleAnimation()
  66. {
  67. return mIdleAnimation;
  68. }
  69. ////////////////////////////////////////////////////////////
  70. // Public Mutators
  71. ////////////////////////////////////////////////////////////
  72. void SkeletalModel::setModel(skeletal_model_t *mdl)
  73. {
  74. if (mdl)
  75. model = mdl;
  76. }
  77. void SkeletalModel::setAnimation(int index)
  78. {
  79. if (!model) // index > (int)model->animation.size())
  80. return;
  81. animation_frame_t *a = model->animation[index];
  82. if (a)
  83. {
  84. mAnimationFrame = index;
  85. mBoneFrame = 0;
  86. rate = a->rate;
  87. }
  88. }
  89. void SkeletalModel::setFrame(int index)
  90. {
  91. if (!model)
  92. return;
  93. animation_frame_t *a = model->animation[mAnimationFrame];
  94. if (a) // index > (int)a->frame.size())
  95. {
  96. bone_frame_t *b = a->frame[index];
  97. if (b)
  98. {
  99. mBoneFrame = index;
  100. }
  101. }
  102. }
  103. void SkeletalModel::setIdleAnimation(int index)
  104. {
  105. if (!model)
  106. return;
  107. animation_frame_t *a = model->animation[index];
  108. if (a)
  109. {
  110. mIdleAnimation = index;
  111. }
  112. }
  113. ////////////////////////////////////////////////////////////
  114. // Private Accessors
  115. ////////////////////////////////////////////////////////////
  116. ////////////////////////////////////////////////////////////
  117. // Private Mutators
  118. ////////////////////////////////////////////////////////////