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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 "global.h"
  9. #include "Log.h"
  10. #include "SkeletalModel.h"
  11. #include "World.h"
  12. BoneTag::BoneTag(int m, float o[3], float r[3], char f) {
  13. mesh = m;
  14. flag = f;
  15. for (int i = 0; i < 3; i++) {
  16. off[i] = o[i];
  17. rot[i] = r[i];
  18. }
  19. }
  20. void BoneTag::display() {
  21. /*
  22. if (getWorld().sizeMesh() > 0)
  23. getWorld().getMesh(mesh).drawSolid(); // TODO ?
  24. else
  25. getWorld().getStaticMesh(mesh).display();
  26. */
  27. }
  28. void BoneTag::getOffset(float o[3]) {
  29. o[0] = off[0];
  30. o[1] = off[1];
  31. o[2] = off[2];
  32. }
  33. void BoneTag::getRotation(float r[3]) {
  34. r[0] = rot[0];
  35. r[1] = rot[1];
  36. r[2] = rot[2];
  37. }
  38. char BoneTag::getFlag() {
  39. return flag;
  40. }
  41. // ----------------------------------------------------------------------------
  42. BoneFrame::BoneFrame(float p[3]) {
  43. for (int i = 0; i < 3; i++)
  44. pos[i] = p[i];
  45. }
  46. BoneFrame::~BoneFrame() {
  47. for (unsigned long i = 0; i < tag.size(); i++)
  48. delete tag[i];
  49. }
  50. unsigned long BoneFrame::size() {
  51. return tag.size();
  52. }
  53. BoneTag& BoneFrame::get(unsigned long i) {
  54. assert(i < tag.size());
  55. return *tag.at(i);
  56. }
  57. void BoneFrame::add(BoneTag* t) {
  58. tag.push_back(t);
  59. }
  60. void BoneFrame::getPosition(float p[3]) {
  61. p[0] = pos[0];
  62. p[1] = pos[1];
  63. p[2] = pos[2];
  64. }
  65. // ----------------------------------------------------------------------------
  66. AnimationFrame::AnimationFrame(char r) {
  67. rate = r;
  68. }
  69. AnimationFrame::~AnimationFrame() {
  70. for (unsigned long i = 0; i < frame.size(); i++)
  71. delete frame[i];
  72. }
  73. unsigned long AnimationFrame::size() {
  74. return frame.size();
  75. }
  76. BoneFrame& AnimationFrame::get(unsigned long i) {
  77. assert(i < frame.size());
  78. return *frame.at(i);
  79. }
  80. void AnimationFrame::add(BoneFrame* f) {
  81. frame.push_back(f);
  82. }
  83. // ----------------------------------------------------------------------------
  84. SkeletalModel::~SkeletalModel() {
  85. for (unsigned long i = 0; i < animation.size(); i++)
  86. delete animation[i];
  87. }
  88. void SkeletalModel::display(unsigned long aframe, unsigned long bframe) {
  89. /*
  90. assert(aframe < size());
  91. assert(bframe < get(aframe).size());
  92. AnimationFrame& anim = get(aframe);
  93. BoneFrame& boneframe = anim.get(bframe);
  94. float pos[3];
  95. boneframe.getPosition(pos);
  96. glTranslatef(pos[0], pos[1], pos[2]);
  97. for (unsigned int a = 0; a < boneframe.size(); a++) {
  98. BoneTag& tag = boneframe.get(a);
  99. float rot[3], off[3];
  100. tag.getRotation(rot);
  101. tag.getOffset(off);
  102. if (a == 0) {
  103. glRotatef(rot[1], 0, 1, 0);
  104. glRotatef(rot[0], 1, 0, 0);
  105. glRotatef(rot[2], 0, 0, 1);
  106. } else {
  107. if (tag.getFlag() & 0x01)
  108. glPopMatrix();
  109. if (tag.getFlag() & 0x02)
  110. glPushMatrix();
  111. glTranslatef(off[0], off[1], off[2]);
  112. glRotatef(rot[1], 0, 1, 0);
  113. glRotatef(rot[0], 1, 0, 0);
  114. glRotatef(rot[2], 0, 0, 1);
  115. }
  116. tag.display();
  117. }
  118. */
  119. }
  120. unsigned long SkeletalModel::size() {
  121. return animation.size();
  122. }
  123. AnimationFrame& SkeletalModel::get(unsigned long i) {
  124. assert(i < animation.size());
  125. return *animation.at(i);
  126. }
  127. void SkeletalModel::add(AnimationFrame* f) {
  128. animation.push_back(f);
  129. }