OctreeQuery.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // Copyright (c) 2008-2017 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "../Precompiled.h"
  23. #include "../Graphics/OctreeQuery.h"
  24. #include "../DebugNew.h"
  25. namespace Atomic
  26. {
  27. Intersection PointOctreeQuery::TestOctant(const BoundingBox& box, bool inside)
  28. {
  29. if (inside)
  30. return INSIDE;
  31. else
  32. return box.IsInside(point_);
  33. }
  34. void PointOctreeQuery::TestDrawables(Drawable** start, Drawable** end, bool inside)
  35. {
  36. while (start != end)
  37. {
  38. Drawable* drawable = *start++;
  39. if ((drawable->GetDrawableFlags() & drawableFlags_) && (drawable->GetViewMask() & viewMask_))
  40. {
  41. if (inside || drawable->GetWorldBoundingBox().IsInside(point_))
  42. result_.Push(drawable);
  43. }
  44. }
  45. }
  46. Intersection SphereOctreeQuery::TestOctant(const BoundingBox& box, bool inside)
  47. {
  48. if (inside)
  49. return INSIDE;
  50. else
  51. return sphere_.IsInside(box);
  52. }
  53. void SphereOctreeQuery::TestDrawables(Drawable** start, Drawable** end, bool inside)
  54. {
  55. while (start != end)
  56. {
  57. Drawable* drawable = *start++;
  58. if ((drawable->GetDrawableFlags() & drawableFlags_) && (drawable->GetViewMask() & viewMask_))
  59. {
  60. if (inside || sphere_.IsInsideFast(drawable->GetWorldBoundingBox()))
  61. result_.Push(drawable);
  62. }
  63. }
  64. }
  65. Intersection BoxOctreeQuery::TestOctant(const BoundingBox& box, bool inside)
  66. {
  67. if (inside)
  68. return INSIDE;
  69. else
  70. return box_.IsInside(box);
  71. }
  72. void BoxOctreeQuery::TestDrawables(Drawable** start, Drawable** end, bool inside)
  73. {
  74. while (start != end)
  75. {
  76. Drawable* drawable = *start++;
  77. if ((drawable->GetDrawableFlags() & drawableFlags_) && (drawable->GetViewMask() & viewMask_))
  78. {
  79. if (inside || box_.IsInsideFast(drawable->GetWorldBoundingBox()))
  80. result_.Push(drawable);
  81. }
  82. }
  83. }
  84. Intersection FrustumOctreeQuery::TestOctant(const BoundingBox& box, bool inside)
  85. {
  86. if (inside)
  87. return INSIDE;
  88. else
  89. return frustum_.IsInside(box);
  90. }
  91. void FrustumOctreeQuery::TestDrawables(Drawable** start, Drawable** end, bool inside)
  92. {
  93. while (start != end)
  94. {
  95. Drawable* drawable = *start++;
  96. if ((drawable->GetDrawableFlags() & drawableFlags_) && (drawable->GetViewMask() & viewMask_))
  97. {
  98. if (inside || frustum_.IsInsideFast(drawable->GetWorldBoundingBox()))
  99. result_.Push(drawable);
  100. }
  101. }
  102. }
  103. Intersection AllContentOctreeQuery::TestOctant(const BoundingBox& box, bool inside)
  104. {
  105. return INSIDE;
  106. }
  107. void AllContentOctreeQuery::TestDrawables(Drawable** start, Drawable** end, bool inside)
  108. {
  109. while (start != end)
  110. {
  111. Drawable* drawable = *start++;
  112. if ((drawable->GetDrawableFlags() & drawableFlags_) && (drawable->GetViewMask() & viewMask_))
  113. result_.Push(drawable);
  114. }
  115. }
  116. }