PolyBone.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * PolyBone.cpp
  3. * Poly
  4. *
  5. * Created by Ivan Safrin on 9/5/08.
  6. * Copyright 2008 __MyCompanyName__. All rights reserved.
  7. *
  8. */
  9. #include "PolyBone.h"
  10. using namespace Polycode;
  11. Bone::Bone(string boneName) : SceneEntity() {
  12. this->boneName = boneName;
  13. boneMesh = new Mesh(Mesh::QUAD_MESH);
  14. boneMesh->createBox(0.1,0.1,0.1);
  15. bBoxRadius = boneMesh->getRadius();
  16. bBox = boneMesh->calculateBBox();
  17. // color.setColor(1.0f, 0.0f, 0.0f, 1.0f);
  18. this->setDepthWrite(false);
  19. parentBone = NULL;
  20. boneMatrix.init();
  21. }
  22. Bone::~Bone() {
  23. }
  24. void Bone::setParentBone(Bone *bone) {
  25. parentBone = bone;
  26. }
  27. void Bone::addChildBone(Bone *bone) {
  28. childBones.push_back(bone);
  29. }
  30. Bone* Bone::getParentBone() {
  31. return parentBone;
  32. }
  33. int Bone::getNumChildBones() {
  34. return childBones.size();
  35. }
  36. Bone *Bone::getChildBone(unsigned int index) {
  37. if(index > childBones.size()-1)
  38. index = childBones.size()-1;
  39. return childBones[index];
  40. }
  41. Matrix4 Bone::getBoneMatrix() {
  42. if(parentBone)
  43. return boneMatrix * parentBone->getBoneMatrix();
  44. else {
  45. return boneMatrix;
  46. }
  47. }
  48. Matrix4 Bone::getFinalMatrix() {
  49. Matrix4 final = boneMatrix * restMatrix;
  50. if(parentBone) {
  51. final = final * parentBone->getFinalMatrix();
  52. }
  53. return final;
  54. }
  55. void Bone::setBoneMatrix(Matrix4 matrix) {
  56. boneMatrix = matrix;
  57. }
  58. Matrix4 Bone::getRestMatrix() {
  59. return restMatrix;
  60. }
  61. Matrix4 Bone::getParentRestMatrix() {
  62. if(parentBone)
  63. return parentBone->getFullRestMatrix();
  64. else {
  65. Matrix4 ident;
  66. ident.identity();
  67. return ident;
  68. }
  69. }
  70. Matrix4 Bone::getFullRestMatrix() {
  71. if(parentBone)
  72. return restMatrix * parentBone->getFullRestMatrix();
  73. else {
  74. return restMatrix;
  75. }
  76. }
  77. void Bone::setRestMatrix(Matrix4 matrix) {
  78. restMatrix = matrix;
  79. }
  80. string Bone::getName() {
  81. return boneName;
  82. }
  83. void Bone::enableBoneLabel(Font *font, float size, float scale) {
  84. // SceneLabel *label = new SceneLabel("", boneName, size, scale, Label::ANTIALIAS_FULL);
  85. SceneLabel *label = new SceneLabel("", L"FIX ME", size, scale, Label::ANTIALIAS_FULL);
  86. label->billboardMode = true;
  87. label->setDepthWrite(false);
  88. addEntity(label);
  89. }
  90. void Bone::Render() {
  91. CoreServices::getInstance()->getRenderer()->setTexture(NULL);
  92. // renderer->pushDataArrayForMesh(boneMesh, RenderDataArray::COLOR_DATA_ARRAY);
  93. // renderer->pushDataArrayForMesh(boneMesh, RenderDataArray::VERTEX_DATA_ARRAY);
  94. // renderer->pushDataArrayForMesh(boneMesh, RenderDataArray::TEXCOORD_DATA_ARRAY);
  95. // renderer->pushDataArrayForMesh(boneMesh, RenderDataArray::NORMAL_DATA_ARRAY);
  96. // renderer->drawArrays(boneMesh->getMeshType());
  97. }