Node.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. *
  3. * Mathematics Subpackage (VrMath)
  4. *
  5. *
  6. * Author: Samuel R. Buss, [email protected].
  7. * Web page: http://math.ucsd.edu/~sbuss/MathCG
  8. *
  9. *
  10. This software is provided 'as-is', without any express or implied warranty.
  11. In no event will the authors be held liable for any damages arising from the use of this software.
  12. Permission is granted to anyone to use this software for any purpose,
  13. including commercial applications, and to alter it and redistribute it freely,
  14. subject to the following restrictions:
  15. 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  16. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  17. 3. This notice may not be removed or altered from any source distribution.
  18. *
  19. *
  20. */
  21. #include <math.h>
  22. #include "LinearR3.h"
  23. #include "MathMisc.h"
  24. #include "Node.h"
  25. extern int RotAxesOn;
  26. Node::Node(const VectorR3& attach, const VectorR3& v, double size, Purpose purpose, double minTheta, double maxTheta, double restAngle)
  27. {
  28. Node::freezed = false;
  29. Node::size = size;
  30. Node::purpose = purpose;
  31. seqNumJoint = -1;
  32. seqNumEffector = -1;
  33. Node::attach = attach; // Global attachment point when joints are at zero angle
  34. r.Set(0.0, 0.0, 0.0); // r will be updated when this node is inserted into tree
  35. Node::v = v; // Rotation axis when joints at zero angles
  36. theta = 0.0;
  37. Node::minTheta = minTheta;
  38. Node::maxTheta = maxTheta;
  39. Node::restAngle = restAngle;
  40. left = right = realparent = 0;
  41. }
  42. // Compute the global position of a single node
  43. void Node::ComputeS(void)
  44. {
  45. Node* y = this->realparent;
  46. Node* w = this;
  47. s = r; // Initialize to local (relative) position
  48. while ( y ) {
  49. s.Rotate( y->theta, y->v );
  50. y = y->realparent;
  51. w = w->realparent;
  52. s += w->r;
  53. }
  54. }
  55. // Compute the global rotation axis of a single node
  56. void Node::ComputeW(void)
  57. {
  58. Node* y = this->realparent;
  59. w = v; // Initialize to local rotation axis
  60. while (y) {
  61. w.Rotate(y->theta, y->v);
  62. y = y->realparent;
  63. }
  64. }
  65. void Node::PrintNode()
  66. {
  67. cerr << "Attach : (" << attach << ")\n";
  68. cerr << "r : (" << r << ")\n";
  69. cerr << "s : (" << s << ")\n";
  70. cerr << "w : (" << w << ")\n";
  71. cerr << "realparent : " << realparent->seqNumJoint << "\n";
  72. }
  73. void Node::InitNode()
  74. {
  75. theta = 0.0;
  76. }