OctreeQuery.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #include "Precompiled.h"
  24. #include "OcclusionBuffer.h"
  25. #include "OctreeQuery.h"
  26. #include "DebugNew.h"
  27. Intersection PointOctreeQuery::TestOctant(const BoundingBox& box, unsigned& mask) const
  28. {
  29. return box.IsInside(point_);
  30. }
  31. Intersection PointOctreeQuery::TestDrawable(const BoundingBox& box, unsigned& mask) const
  32. {
  33. return box.IsInside(point_);
  34. }
  35. Intersection SphereOctreeQuery::TestOctant(const BoundingBox& box, unsigned& mask) const
  36. {
  37. if (mask == M_MAX_UNSIGNED)
  38. return INSIDE;
  39. return sphere_.IsInside(box);
  40. }
  41. Intersection SphereOctreeQuery::TestDrawable(const BoundingBox& box, unsigned& mask) const
  42. {
  43. if (mask == M_MAX_UNSIGNED)
  44. return INSIDE;
  45. return sphere_.IsInsideFast(box);
  46. }
  47. Intersection BoxOctreeQuery::TestOctant(const BoundingBox& box, unsigned& mask) const
  48. {
  49. if (mask == M_MAX_UNSIGNED)
  50. return INSIDE;
  51. return box_.IsInside(box);
  52. }
  53. Intersection BoxOctreeQuery::TestDrawable(const BoundingBox& box, unsigned& mask) const
  54. {
  55. if (mask == M_MAX_UNSIGNED)
  56. return INSIDE;
  57. return box_.IsInsideFast(box);
  58. }
  59. Intersection FrustumOctreeQuery::TestOctant(const BoundingBox& box, unsigned& mask) const
  60. {
  61. if (mask == M_MAX_UNSIGNED)
  62. return INSIDE;
  63. return frustum_.IsInsideMasked(box, mask);
  64. }
  65. Intersection FrustumOctreeQuery::TestDrawable(const BoundingBox& box, unsigned& mask) const
  66. {
  67. if (mask == M_MAX_UNSIGNED)
  68. return INSIDE;
  69. return frustum_.IsInsideFastMasked(box, mask);
  70. }
  71. Intersection OccludedFrustumOctreeQuery::TestOctant(const BoundingBox& box, unsigned& mask) const
  72. {
  73. // First check the frustum
  74. Intersection frustumRes = INSIDE;
  75. if (mask != M_MAX_UNSIGNED)
  76. {
  77. frustumRes = frustum_.IsInsideMasked(box, mask);
  78. if (frustumRes == OUTSIDE)
  79. return OUTSIDE;
  80. }
  81. // Then check occlusion
  82. if (buffer_->IsVisible(box))
  83. return frustumRes;
  84. else
  85. return OUTSIDE;
  86. }
  87. Intersection OccludedFrustumOctreeQuery::TestDrawable(const BoundingBox& box, unsigned& mask) const
  88. {
  89. // First check the frustum
  90. if (mask != M_MAX_UNSIGNED)
  91. {
  92. if (frustum_.IsInsideFastMasked(box, mask) == OUTSIDE)
  93. return OUTSIDE;
  94. }
  95. // Then check occlusion
  96. if (buffer_->IsVisible(box))
  97. return INSIDE;
  98. else
  99. return OUTSIDE;
  100. }