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.2KB

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