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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. if (getWorld().sizeMesh() > 0)
  22. getWorld().getMesh(mesh).drawSolid(); // TODO ?
  23. else
  24. getWorld().getStaticMesh(mesh).display();
  25. }
  26. void BoneTag::getOffset(float o[3]) {
  27. o[0] = off[0];
  28. o[1] = off[1];
  29. o[2] = off[2];
  30. }
  31. void BoneTag::getRotation(float r[3]) {
  32. r[0] = rot[0];
  33. r[1] = rot[1];
  34. r[2] = rot[2];
  35. }
  36. char BoneTag::getFlag() {
  37. return flag;
  38. }
  39. // ----------------------------------------------------------------------------
  40. BoneFrame::BoneFrame(float p[3]) {
  41. for (int i = 0; i < 3; i++)
  42. pos[i] = p[i];
  43. }
  44. BoneFrame::~BoneFrame() {
  45. for (unsigned long i = 0; i < tag.size(); i++)
  46. delete tag[i];
  47. }
  48. unsigned long BoneFrame::size() {
  49. return tag.size();
  50. }
  51. BoneTag& BoneFrame::get(unsigned long i) {
  52. assert(i < tag.size());
  53. return *tag.at(i);
  54. }
  55. void BoneFrame::add(BoneTag* t) {
  56. tag.push_back(t);
  57. }
  58. void BoneFrame::getPosition(float p[3]) {
  59. p[0] = pos[0];
  60. p[1] = pos[1];
  61. p[2] = pos[2];
  62. }
  63. // ----------------------------------------------------------------------------
  64. AnimationFrame::AnimationFrame(char r) {
  65. rate = r;
  66. }
  67. AnimationFrame::~AnimationFrame() {
  68. for (unsigned long i = 0; i < frame.size(); i++)
  69. delete frame[i];
  70. }
  71. unsigned long AnimationFrame::size() {
  72. return frame.size();
  73. }
  74. BoneFrame& AnimationFrame::get(unsigned long i) {
  75. assert(i < frame.size());
  76. return *frame.at(i);
  77. }
  78. void AnimationFrame::add(BoneFrame* f) {
  79. frame.push_back(f);
  80. }
  81. // ----------------------------------------------------------------------------
  82. SkeletalModel::SkeletalModel(int i) {
  83. id = i;
  84. }
  85. SkeletalModel::~SkeletalModel() {
  86. for (unsigned long i = 0; i < animation.size(); i++)
  87. delete animation[i];
  88. }
  89. void SkeletalModel::display(unsigned long aframe, unsigned long bframe) {
  90. /*
  91. assert(aframe < size());
  92. assert(bframe < get(aframe).size());
  93. AnimationFrame& anim = get(aframe);
  94. BoneFrame& boneframe = anim.get(bframe);
  95. float pos[3];
  96. boneframe.getPosition(pos);
  97. glTranslatef(pos[0], pos[1], pos[2]);
  98. for (unsigned int a = 0; a < boneframe.size(); a++) {
  99. BoneTag& tag = boneframe.get(a);
  100. float rot[3], off[3];
  101. tag.getRotation(rot);
  102. tag.getOffset(off);
  103. if (a == 0) {
  104. glRotatef(rot[1], 0, 1, 0);
  105. glRotatef(rot[0], 1, 0, 0);
  106. glRotatef(rot[2], 0, 0, 1);
  107. } else {
  108. if (tag.getFlag() & 0x01)
  109. glPopMatrix();
  110. if (tag.getFlag() & 0x02)
  111. glPushMatrix();
  112. glTranslatef(off[0], off[1], off[2]);
  113. glRotatef(rot[1], 0, 1, 0);
  114. glRotatef(rot[0], 1, 0, 0);
  115. glRotatef(rot[2], 0, 0, 1);
  116. }
  117. tag.display();
  118. }
  119. */
  120. }
  121. int SkeletalModel::getId() {
  122. return id;
  123. }
  124. void SkeletalModel::setPigTail(bool b) {
  125. pigtails = b;
  126. if (b) {
  127. ponyOff -= 20;
  128. ponytail[1] -= 32;
  129. } else {
  130. ponyOff += 20;
  131. ponytail[1] += 32;
  132. }
  133. }
  134. void SkeletalModel::setPonyPos(float x, float y, float z, float angle) {
  135. ponytail[0] = x;
  136. ponytail[1] = y;
  137. ponytail[2] = z;
  138. ponytailAngle = angle;
  139. }
  140. unsigned long SkeletalModel::size() {
  141. return animation.size();
  142. }
  143. AnimationFrame& SkeletalModel::get(unsigned long i) {
  144. assert(i < animation.size());
  145. return *animation.at(i);
  146. }
  147. void SkeletalModel::add(AnimationFrame* f) {
  148. animation.push_back(f);
  149. }