qpcollisionNode.I 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // Filename: qpcollisionNode.I
  2. // Created by: drose (16Mar02)
  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. ////////////////////////////////////////////////////////////////////
  19. // Function: qpCollisionNode::set_collide_mask
  20. // Access: Public
  21. // Description: Simultaneously sets both the "from" and "into"
  22. // CollideMask values to the same thing.
  23. ////////////////////////////////////////////////////////////////////
  24. INLINE void qpCollisionNode::
  25. set_collide_mask(CollideMask mask) {
  26. set_from_collide_mask(mask);
  27. set_into_collide_mask(mask);
  28. }
  29. ////////////////////////////////////////////////////////////////////
  30. // Function: qpCollisionNode::set_from_collide_mask
  31. // Access: Public
  32. // Description: Sets the "from" CollideMask. In order for a
  33. // collision to be detected from this object into
  34. // another object, the intersection of this object's
  35. // "from" mask and the other object's "into" mask must
  36. // be nonzero.
  37. ////////////////////////////////////////////////////////////////////
  38. INLINE void qpCollisionNode::
  39. set_from_collide_mask(CollideMask mask) {
  40. _from_collide_mask = mask;
  41. }
  42. ////////////////////////////////////////////////////////////////////
  43. // Function: qpCollisionNode::set_into_collide_mask
  44. // Access: Public
  45. // Description: Sets the "into" CollideMask. In order for a
  46. // collision to be detected from another object into
  47. // this object, the intersection of the other object's
  48. // "from" mask and this object's "into" mask must be
  49. // nonzero.
  50. ////////////////////////////////////////////////////////////////////
  51. INLINE void qpCollisionNode::
  52. set_into_collide_mask(CollideMask mask) {
  53. _into_collide_mask = mask;
  54. // We mark the bound stale when this changes, not because the actual
  55. // bounding volume changes, but rather because we piggyback the
  56. // computing of the _net_collide_mask on the bounding volume.
  57. mark_bound_stale();
  58. }
  59. ////////////////////////////////////////////////////////////////////
  60. // Function: qpCollisionNode::get_from_collide_mask
  61. // Access: Public
  62. // Description: Returns the current "from" CollideMask. In order for
  63. // a collision to be detected from this object into
  64. // another object, the intersection of this object's
  65. // "from" mask and the other object's "into" mask must
  66. // be nonzero.
  67. ////////////////////////////////////////////////////////////////////
  68. INLINE CollideMask qpCollisionNode::
  69. get_from_collide_mask() const {
  70. return _from_collide_mask;
  71. }
  72. ////////////////////////////////////////////////////////////////////
  73. // Function: qpCollisionNode::get_into_collide_mask
  74. // Access: Public
  75. // Description: Returns the current "into" CollideMask. In order for
  76. // a collision to be detected from another object into
  77. // this object, the intersection of the other object's
  78. // "from" mask and this object's "into" mask must be
  79. // nonzero.
  80. ////////////////////////////////////////////////////////////////////
  81. INLINE CollideMask qpCollisionNode::
  82. get_into_collide_mask() const {
  83. return _into_collide_mask;
  84. }
  85. ////////////////////////////////////////////////////////////////////
  86. // Function: qpCollisionNode::set_collide_geom
  87. // Access: Public
  88. // Description: Sets the state of the "collide geom" flag for this
  89. // qpCollisionNode. Normally, this is false; when this is
  90. // set true, the CollisionSolids in this node will test
  91. // for collisions with actual renderable geometry, in
  92. // addition to whatever CollisionSolids may be indicated
  93. // by the from_collide_mask.
  94. //
  95. // Setting this to true causes this to test *all*
  96. // GeomNodes for collisions. It is an all-or-none
  97. // thing; there is no way to collide with only some
  98. // GeomNodes, as GeomNodes have no into_collide_mask.
  99. ////////////////////////////////////////////////////////////////////
  100. INLINE void qpCollisionNode::
  101. set_collide_geom(bool flag) {
  102. _collide_geom = flag;
  103. }
  104. ////////////////////////////////////////////////////////////////////
  105. // Function: qpCollisionNode::get_collide_geom
  106. // Access: Public
  107. // Description: Returns the current state of the collide_geom flag.
  108. // See set_collide_geom().
  109. ////////////////////////////////////////////////////////////////////
  110. INLINE bool qpCollisionNode::
  111. get_collide_geom() const {
  112. return _collide_geom;
  113. }
  114. ////////////////////////////////////////////////////////////////////
  115. // Function: qpCollisionNode::get_num_solids
  116. // Access: Public
  117. // Description:
  118. ////////////////////////////////////////////////////////////////////
  119. INLINE int qpCollisionNode::
  120. get_num_solids() const {
  121. return _solids.size();
  122. }
  123. ////////////////////////////////////////////////////////////////////
  124. // Function: qpCollisionNode::get_solid
  125. // Access: Public
  126. // Description:
  127. ////////////////////////////////////////////////////////////////////
  128. INLINE CollisionSolid *qpCollisionNode::
  129. get_solid(int n) const {
  130. nassertr(n >= 0 && n < get_num_solids(), NULL);
  131. return _solids[n];
  132. }
  133. ////////////////////////////////////////////////////////////////////
  134. // Function: qpCollisionNode::remove_solid
  135. // Access: Public
  136. // Description: Removes the solid with the indicated index. This
  137. // will shift all subsequent indices down by one.
  138. ////////////////////////////////////////////////////////////////////
  139. INLINE void qpCollisionNode::
  140. remove_solid(int n) {
  141. nassertv(n >= 0 && n < get_num_solids());
  142. _solids.erase(_solids.begin() + n);
  143. mark_bound_stale();
  144. }
  145. ////////////////////////////////////////////////////////////////////
  146. // Function: qpCollisionNode::add_solid
  147. // Access: Public
  148. // Description: Adds the indicated solid to the node. Returns the
  149. // index of the new solid within the node's list of
  150. // solids.
  151. ////////////////////////////////////////////////////////////////////
  152. INLINE int qpCollisionNode::
  153. add_solid(CollisionSolid *solid) {
  154. _solids.push_back(solid);
  155. mark_bound_stale();
  156. return _solids.size() - 1;
  157. }