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

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