Open Source Tomb Raider Engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

SkeletalModel.cpp 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. delete model;
  51. }
  52. }
  53. ////////////////////////////////////////////////////////////
  54. // Public Accessors
  55. ////////////////////////////////////////////////////////////
  56. int SkeletalModel::getAnimation()
  57. {
  58. return mAnimationFrame;
  59. }
  60. int SkeletalModel::getFrame()
  61. {
  62. return mBoneFrame;
  63. }
  64. int SkeletalModel::getIdleAnimation()
  65. {
  66. return mIdleAnimation;
  67. }
  68. ////////////////////////////////////////////////////////////
  69. // Public Mutators
  70. ////////////////////////////////////////////////////////////
  71. void SkeletalModel::setModel(skeletal_model_t *mdl)
  72. {
  73. if (mdl)
  74. model = mdl;
  75. }
  76. void SkeletalModel::setAnimation(int index)
  77. {
  78. if (!model) // index > (int)model->animation.size())
  79. return;
  80. animation_frame_t *a = model->animation[index];
  81. if (a)
  82. {
  83. mAnimationFrame = index;
  84. mBoneFrame = 0;
  85. rate = a->rate;
  86. }
  87. }
  88. void SkeletalModel::setFrame(int index)
  89. {
  90. if (!model)
  91. return;
  92. animation_frame_t *a = model->animation[mAnimationFrame];
  93. if (a) // index > (int)a->frame.size())
  94. {
  95. bone_frame_t *b = a->frame[index];
  96. if (b)
  97. {
  98. mBoneFrame = index;
  99. }
  100. }
  101. }
  102. void SkeletalModel::setIdleAnimation(int index)
  103. {
  104. if (!model)
  105. return;
  106. animation_frame_t *a = model->animation[index];
  107. if (a)
  108. {
  109. mIdleAnimation = index;
  110. }
  111. }
  112. ////////////////////////////////////////////////////////////
  113. // Private Accessors
  114. ////////////////////////////////////////////////////////////
  115. ////////////////////////////////////////////////////////////
  116. // Private Mutators
  117. ////////////////////////////////////////////////////////////