physicsManager.I 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. // Filename: physicsManager.I
  2. // Created by: charles (14Jun00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, 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://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. ////////////////////////////////////////////////////////////////////
  19. // Function : attach_physical
  20. // Access : Public
  21. // Description : Registers a Physical class with the manager
  22. ////////////////////////////////////////////////////////////////////
  23. INLINE void PhysicsManager::
  24. attach_physical(Physical *p) {
  25. nassertv(p);
  26. p->_physics_manager = this;
  27. pvector< Physical * >::iterator found;
  28. found = find(_physicals.begin(), _physicals.end(), p);
  29. if (found == _physicals.end()) {
  30. _physicals.push_back(p);
  31. }
  32. }
  33. ////////////////////////////////////////////////////////////////////
  34. // Function : attach_linear_force
  35. // Access : Public
  36. // Description : Adds a global linear force to the physics manager
  37. ////////////////////////////////////////////////////////////////////
  38. INLINE void PhysicsManager::
  39. add_linear_force(LinearForce *f) {
  40. nassertv(f);
  41. LinearForceVector::iterator found;
  42. PT(LinearForce) ptlf = f;
  43. found = find(_linear_forces.begin(), _linear_forces.end(), ptlf);
  44. if (found == _linear_forces.end()) {
  45. _linear_forces.push_back(f);
  46. }
  47. }
  48. ////////////////////////////////////////////////////////////////////
  49. // Function : attach_physicalnode
  50. // Access : Public
  51. // Description : Registers a physicalnode with the manager
  52. ////////////////////////////////////////////////////////////////////
  53. INLINE void PhysicsManager::
  54. attach_physicalnode(PhysicalNode *p) {
  55. attach_physical_node(p);
  56. }
  57. ////////////////////////////////////////////////////////////////////
  58. // Function : attach_physical_node
  59. // Access : Public
  60. // Description : Registers a physicalnode with the manager
  61. ////////////////////////////////////////////////////////////////////
  62. INLINE void PhysicsManager::
  63. attach_physical_node(PhysicalNode *p) {
  64. nassertv(p);
  65. for (int i = 0; i < p->get_num_physicals(); ++i) {
  66. attach_physical(p->get_physical(i));
  67. }
  68. }
  69. ////////////////////////////////////////////////////////////////////
  70. // Function : clear_linear_forces
  71. // Access : Public
  72. // Description : Resets the physics manager force vector
  73. ////////////////////////////////////////////////////////////////////
  74. INLINE void PhysicsManager::
  75. clear_linear_forces() {
  76. _linear_forces.erase(_linear_forces.begin(), _linear_forces.end());
  77. }
  78. ////////////////////////////////////////////////////////////////////
  79. // Function : attach_angular_force
  80. // Access : Public
  81. // Description : Adds a global angular force to the physics manager
  82. ////////////////////////////////////////////////////////////////////
  83. INLINE void PhysicsManager::
  84. add_angular_force(AngularForce *f) {
  85. nassertv(f);
  86. AngularForceVector::iterator found;
  87. PT(AngularForce) ptaf = f;
  88. found = find(_angular_forces.begin(), _angular_forces.end(), ptaf);
  89. if (found == _angular_forces.end())
  90. _angular_forces.push_back(f);
  91. }
  92. ////////////////////////////////////////////////////////////////////
  93. // Function : clear_angular_forces
  94. // Access : Public
  95. // Description : Resets the physics manager force vector
  96. ////////////////////////////////////////////////////////////////////
  97. INLINE void PhysicsManager::
  98. clear_angular_forces() {
  99. _angular_forces.erase(_angular_forces.begin(), _angular_forces.end());
  100. }
  101. ////////////////////////////////////////////////////////////////////
  102. // Function : clear_physicals
  103. // Access : Public
  104. // Description : Resets the physics manager objects vector
  105. ////////////////////////////////////////////////////////////////////
  106. INLINE void PhysicsManager::
  107. clear_physicals() {
  108. _physicals.erase(_physicals.begin(), _physicals.end());
  109. }
  110. ////////////////////////////////////////////////////////////////////
  111. // Function : set_viscosity
  112. // Access : Public
  113. // Description : Set the global viscosity.
  114. ////////////////////////////////////////////////////////////////////
  115. INLINE void PhysicsManager::
  116. set_viscosity(float viscosity) {
  117. _viscosity=viscosity;
  118. }
  119. ////////////////////////////////////////////////////////////////////
  120. // Function : get_viscosity
  121. // Access : Public
  122. // Description : Get the global viscosity.
  123. ////////////////////////////////////////////////////////////////////
  124. INLINE float PhysicsManager::
  125. get_viscosity() const {
  126. return _viscosity;
  127. }
  128. ////////////////////////////////////////////////////////////////////
  129. // Function : attach_linear_integrator
  130. // Access : Public
  131. // Description : Hooks a linear integrator into the manager
  132. ////////////////////////////////////////////////////////////////////
  133. INLINE void PhysicsManager::
  134. attach_linear_integrator(LinearIntegrator *i) {
  135. nassertv(i);
  136. _linear_integrator = i;
  137. }
  138. ////////////////////////////////////////////////////////////////////
  139. // Function : attach_angular_integrator
  140. // Access : Public
  141. // Description : Hooks an angular integrator into the manager
  142. ////////////////////////////////////////////////////////////////////
  143. INLINE void PhysicsManager::
  144. attach_angular_integrator(AngularIntegrator *i) {
  145. nassertv(i);
  146. _angular_integrator = i;
  147. }