forceNode.cxx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Filename: forceNode.cxx
  2. // Created by: charles (02Aug00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://www.panda3d.org/license.txt .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #include "forceNode.h"
  19. #include "config_physics.h"
  20. TypeHandle ForceNode::_type_handle;
  21. ////////////////////////////////////////////////////////////////////
  22. // Function : ForceNode
  23. // Access : public
  24. // Description : default constructor
  25. ////////////////////////////////////////////////////////////////////
  26. ForceNode::
  27. ForceNode(const string &name) :
  28. NamedNode(name) {
  29. }
  30. ////////////////////////////////////////////////////////////////////
  31. // Function : ForceNode
  32. // Access : public
  33. // Description : copy constructor
  34. ////////////////////////////////////////////////////////////////////
  35. ForceNode::
  36. ForceNode(const ForceNode &copy) :
  37. NamedNode(copy), _forces(copy._forces) {
  38. }
  39. ////////////////////////////////////////////////////////////////////
  40. // Function : ~ForceNode
  41. // Access : public, virtual
  42. // Description : destructor
  43. ////////////////////////////////////////////////////////////////////
  44. ForceNode::
  45. ~ForceNode(void) {
  46. }
  47. ////////////////////////////////////////////////////////////////////
  48. // Function : operator =
  49. // Access : public
  50. // Description : assignment operator
  51. ////////////////////////////////////////////////////////////////////
  52. ForceNode &ForceNode::
  53. operator =(const ForceNode &copy) {
  54. NamedNode::operator =(copy);
  55. _forces = copy._forces;
  56. return *this;
  57. }
  58. ////////////////////////////////////////////////////////////////////
  59. // Function : make_copy
  60. // Access : public, virtual
  61. // Description : dynamic child copy
  62. ////////////////////////////////////////////////////////////////////
  63. Node *ForceNode::
  64. make_copy(void) const {
  65. return new ForceNode(*this);
  66. }
  67. ////////////////////////////////////////////////////////////////////
  68. // Function : add_forces_from
  69. // Access : public
  70. // Description : append operation
  71. ////////////////////////////////////////////////////////////////////
  72. void ForceNode::
  73. add_forces_from(const ForceNode &other) {
  74. pvector< PT(BaseForce) >::iterator last = _forces.end() - 1;
  75. _forces.insert(_forces.end(),
  76. other._forces.begin(), other._forces.end());
  77. for (; last != _forces.end(); last++)
  78. (*last)->_force_node = this;
  79. }
  80. ////////////////////////////////////////////////////////////////////
  81. // Function : remove_force
  82. // Access : public
  83. // Description : remove operation
  84. ////////////////////////////////////////////////////////////////////
  85. void ForceNode::
  86. remove_force(BaseForce *f) {
  87. pvector< PT(BaseForce) >::iterator found;
  88. PT(BaseForce) ptbf = f;
  89. found = find(_forces.begin(), _forces.end(), ptbf);
  90. if (found == _forces.end())
  91. return;
  92. _forces.erase(found);
  93. }
  94. ////////////////////////////////////////////////////////////////////
  95. // Function : remove_force
  96. // Access : public
  97. // Description : remove operation
  98. ////////////////////////////////////////////////////////////////////
  99. void ForceNode::
  100. remove_force(int index) {
  101. nassertv(index >= 0 && index <= (int)_forces.size());
  102. pvector< PT(BaseForce) >::iterator remove;
  103. remove = _forces.begin() + index;
  104. (*remove)->_force_node = (ForceNode *) NULL;
  105. _forces.erase(remove);
  106. }