boundingVolume.I 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Filename: boundingVolume.I
  2. // Created by: drose (01Oct99)
  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: BoundingVolume::Constructor
  20. // Access: Public
  21. // Description:
  22. ////////////////////////////////////////////////////////////////////
  23. INLINE_MATHUTIL BoundingVolume::
  24. BoundingVolume() {
  25. _flags = F_empty;
  26. }
  27. ////////////////////////////////////////////////////////////////////
  28. // Function: BoundingVolume::is_empty
  29. // Access: Public
  30. // Description: Any kind of volume might be empty. This is a
  31. // degenerate volume that contains no points; it's not
  32. // the same as, for instance, a sphere with radius zero,
  33. // since that contains one point (the center). It
  34. // intersects with no other volumes.
  35. ////////////////////////////////////////////////////////////////////
  36. INLINE_MATHUTIL bool BoundingVolume::
  37. is_empty() const {
  38. return (_flags & F_empty) != 0;
  39. }
  40. ////////////////////////////////////////////////////////////////////
  41. // Function: BoundingVolume::is_infinite
  42. // Access: Public
  43. // Description: The other side of the empty coin is an infinite
  44. // volume. This is a degenerate state of a normally
  45. // finite volume that contains all points. (Note that
  46. // some kinds of infinite bounding volumes, like binary
  47. // separating planes, do not contain all points and thus
  48. // correctly return is_infinite() == false, even though
  49. // they are technically infinite. This is a special
  50. // case of the word 'infinite' meaning the volume covers
  51. // all points in space.)
  52. //
  53. // It completely intersects with all other volumes
  54. // except empty volumes.
  55. ////////////////////////////////////////////////////////////////////
  56. INLINE_MATHUTIL bool BoundingVolume::
  57. is_infinite() const {
  58. return (_flags & F_infinite) != 0;
  59. }
  60. ////////////////////////////////////////////////////////////////////
  61. // Function: BoundingVolume::set_infinite
  62. // Access: Public
  63. // Description: Marks the volume as infinite, even if it is normally
  64. // finite. You can think of this as an infinite
  65. // extend_by() operation.
  66. ////////////////////////////////////////////////////////////////////
  67. INLINE_MATHUTIL void BoundingVolume::
  68. set_infinite() {
  69. _flags = F_infinite;
  70. }
  71. ////////////////////////////////////////////////////////////////////
  72. // Function: BoundingVolume::extend_by
  73. // Access: Public
  74. // Description: Increases the size of the volume to include the given
  75. // volume.
  76. ////////////////////////////////////////////////////////////////////
  77. INLINE_MATHUTIL bool BoundingVolume::
  78. extend_by(const BoundingVolume *vol) {
  79. if (vol->is_infinite()) {
  80. set_infinite();
  81. } else if (!vol->is_empty()) {
  82. // This is a double-dispatch. We call this virtual function on the
  83. // volume we were given, which will in turn call the appropriate
  84. // virtual function in our own class to perform the operation.
  85. return vol->extend_other(this);
  86. }
  87. return true;
  88. }
  89. ////////////////////////////////////////////////////////////////////
  90. // Function: BoundingVolume::contains
  91. // Access: Public
  92. // Description: Returns the appropriate set of IntersectionFlags to
  93. // indicate the amount of intersection with the
  94. // indicated volume.
  95. ////////////////////////////////////////////////////////////////////
  96. INLINE_MATHUTIL int BoundingVolume::
  97. contains(const BoundingVolume *vol) const {
  98. if (is_empty() || vol->is_empty()) {
  99. return IF_no_intersection;
  100. } else if (is_infinite()) {
  101. return IF_possible | IF_some | IF_all;
  102. } else if (vol->is_infinite()) {
  103. return IF_possible | IF_some;
  104. }
  105. // This is a double-dispatch. We call this virtual function on the
  106. // volume we were given, which will in turn call the appropriate
  107. // virtual function in our own class to perform the operation.
  108. return vol->contains_other(this);
  109. }
  110. INLINE_MATHUTIL ostream &operator << (ostream &out, const BoundingVolume &bound) {
  111. bound.output(out);
  112. return out;
  113. }