collisionNode.I 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. // Filename: collisionNode.I
  2. // Created by: drose (16Mar02)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) Carnegie Mellon University. All rights reserved.
  8. //
  9. // All use of this software is subject to the terms of the revised BSD
  10. // license. You should have received a copy of this license along
  11. // with this source code in a file named "LICENSE."
  12. //
  13. ////////////////////////////////////////////////////////////////////
  14. ////////////////////////////////////////////////////////////////////
  15. // Function: CollisionNode::set_collide_mask
  16. // Access: Published
  17. // Description: Simultaneously sets both the "from" and "into"
  18. // CollideMask values to the same thing.
  19. ////////////////////////////////////////////////////////////////////
  20. INLINE void CollisionNode::
  21. set_collide_mask(CollideMask mask) {
  22. set_from_collide_mask(mask);
  23. set_into_collide_mask(mask);
  24. }
  25. ////////////////////////////////////////////////////////////////////
  26. // Function: CollisionNode::set_into_collide_mask
  27. // Access: Published
  28. // Description: Sets the "into" CollideMask. In order for a
  29. // collision to be detected from another object into
  30. // this object, the intersection of the other object's
  31. // "from" mask and this object's "into" mask must be
  32. // nonzero.
  33. ////////////////////////////////////////////////////////////////////
  34. INLINE void CollisionNode::
  35. set_into_collide_mask(CollideMask mask) {
  36. // This is now inherited from the PandaNode base class.
  37. PandaNode::set_into_collide_mask(mask);
  38. }
  39. ////////////////////////////////////////////////////////////////////
  40. // Function: CollisionNode::get_from_collide_mask
  41. // Access: Published
  42. // Description: Returns the current "from" CollideMask. In order for
  43. // a collision to be detected from this object into
  44. // another object, the intersection of this object's
  45. // "from" mask and the other object's "into" mask must
  46. // be nonzero.
  47. ////////////////////////////////////////////////////////////////////
  48. INLINE CollideMask CollisionNode::
  49. get_from_collide_mask() const {
  50. return _from_collide_mask;
  51. }
  52. ////////////////////////////////////////////////////////////////////
  53. // Function: CollisionNode::get_into_collide_mask
  54. // Access: Published
  55. // Description: Returns the current "into" CollideMask. In order for
  56. // a collision to be detected from another object into
  57. // this object, the intersection of the other object's
  58. // "from" mask and this object's "into" mask must be
  59. // nonzero.
  60. ////////////////////////////////////////////////////////////////////
  61. INLINE CollideMask CollisionNode::
  62. get_into_collide_mask() const {
  63. // This is now inherited from the PandaNode base class.
  64. return PandaNode::get_into_collide_mask();
  65. }
  66. ////////////////////////////////////////////////////////////////////
  67. // Function: CollisionNode::clear_solids
  68. // Access: Published
  69. // Description: Removes all solids from the node.
  70. ////////////////////////////////////////////////////////////////////
  71. INLINE void CollisionNode::
  72. clear_solids() {
  73. _solids.clear();
  74. mark_internal_bounds_stale();
  75. }
  76. ////////////////////////////////////////////////////////////////////
  77. // Function: CollisionNode::get_num_solids
  78. // Access: Published
  79. // Description:
  80. ////////////////////////////////////////////////////////////////////
  81. INLINE int CollisionNode::
  82. get_num_solids() const {
  83. return _solids.size();
  84. }
  85. ////////////////////////////////////////////////////////////////////
  86. // Function: CollisionNode::get_solid
  87. // Access: Published
  88. // Description:
  89. ////////////////////////////////////////////////////////////////////
  90. INLINE CPT(CollisionSolid) CollisionNode::
  91. get_solid(int n) const {
  92. nassertr(n >= 0 && n < get_num_solids(), NULL);
  93. return _solids[n].get_read_pointer();
  94. }
  95. ////////////////////////////////////////////////////////////////////
  96. // Function: CollisionNode::modify_solid
  97. // Access: Published
  98. // Description:
  99. ////////////////////////////////////////////////////////////////////
  100. INLINE PT(CollisionSolid) CollisionNode::
  101. modify_solid(int n) {
  102. nassertr(n >= 0 && n < get_num_solids(), NULL);
  103. mark_internal_bounds_stale();
  104. return _solids[n].get_write_pointer();
  105. }
  106. ////////////////////////////////////////////////////////////////////
  107. // Function: CollisionNode::set_solid
  108. // Access: Published
  109. // Description: Replaces the solid with the indicated index.
  110. ////////////////////////////////////////////////////////////////////
  111. INLINE void CollisionNode::
  112. set_solid(int n, CollisionSolid *solid) {
  113. nassertv(n >= 0 && n < get_num_solids());
  114. _solids[n] = solid;
  115. mark_internal_bounds_stale();
  116. }
  117. ////////////////////////////////////////////////////////////////////
  118. // Function: CollisionNode::remove_solid
  119. // Access: Published
  120. // Description: Removes the solid with the indicated index. This
  121. // will shift all subsequent indices down by one.
  122. ////////////////////////////////////////////////////////////////////
  123. INLINE void CollisionNode::
  124. remove_solid(int n) {
  125. nassertv(n >= 0 && n < get_num_solids());
  126. _solids.erase(_solids.begin() + n);
  127. mark_internal_bounds_stale();
  128. }
  129. ////////////////////////////////////////////////////////////////////
  130. // Function: CollisionNode::add_solid
  131. // Access: Published
  132. // Description: Adds the indicated solid to the node. Returns the
  133. // index of the new solid within the node's list of
  134. // solids.
  135. ////////////////////////////////////////////////////////////////////
  136. INLINE int CollisionNode::
  137. add_solid(const CollisionSolid *solid) {
  138. _solids.push_back((CollisionSolid *)solid);
  139. mark_internal_bounds_stale();
  140. return _solids.size() - 1;
  141. }
  142. ////////////////////////////////////////////////////////////////////
  143. // Function: CollisionNode::get_collider_sort
  144. // Access: Published
  145. // Description: Returns the collider_sort value that has been set for
  146. // this particular node. See set_collider_sort().
  147. ////////////////////////////////////////////////////////////////////
  148. INLINE int CollisionNode::
  149. get_collider_sort() const {
  150. return _collider_sort;
  151. }
  152. ////////////////////////////////////////////////////////////////////
  153. // Function: CollisionNode::set_collider_sort
  154. // Access: Published
  155. // Description: Sets a particular collider_sort value on this node.
  156. // This controls the order in which colliders (that is,
  157. // "from nodes") are grouped together for the collision
  158. // traversal.
  159. //
  160. // If there are 32 or fewer colliders added to any
  161. // particular CollisionTraverser, then this value has no
  162. // meaning. It is only useful if there are many
  163. // colliders, which may force the CollisionTraverser to
  164. // make multiple passes through the data; in that case,
  165. // it may be a useful optimization to group colliders
  166. // that have similar bounding volumes together (by
  167. // giving them similar sort values).
  168. ////////////////////////////////////////////////////////////////////
  169. INLINE void CollisionNode::
  170. set_collider_sort(int sort) {
  171. _collider_sort = sort;
  172. }
  173. ////////////////////////////////////////////////////////////////////
  174. // Function: CollisionNode::get_default_collide_mask
  175. // Access: Published, Static
  176. // Description: Returns the default into_collide_mask assigned to new
  177. // CollisionNodes.
  178. ////////////////////////////////////////////////////////////////////
  179. INLINE CollideMask CollisionNode::
  180. get_default_collide_mask() {
  181. return default_collision_node_collide_mask;
  182. }