OctreeQuery.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2012 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 "OctreeQuery.h"
  25. #include "DebugNew.h"
  26. namespace Urho3D
  27. {
  28. Intersection PointOctreeQuery::TestOctant(const BoundingBox& box, bool inside)
  29. {
  30. if (inside)
  31. return INSIDE;
  32. else
  33. return box.IsInside(point_);
  34. }
  35. void PointOctreeQuery::TestDrawables(Drawable** start, Drawable** end, bool inside)
  36. {
  37. while (start != end)
  38. {
  39. Drawable* drawable = *start;
  40. if ((drawable->GetDrawableFlags() & drawableFlags_) && drawable->IsVisible() && (drawable->GetViewMask() & viewMask_))
  41. {
  42. if (inside || drawable->GetWorldBoundingBox().IsInside(point_))
  43. result_.Push(drawable);
  44. }
  45. ++start;
  46. }
  47. }
  48. Intersection SphereOctreeQuery::TestOctant(const BoundingBox& box, bool inside)
  49. {
  50. if (inside)
  51. return INSIDE;
  52. else
  53. return sphere_.IsInside(box);
  54. }
  55. void SphereOctreeQuery::TestDrawables(Drawable** start, Drawable** end, bool inside)
  56. {
  57. while (start != end)
  58. {
  59. Drawable* drawable = *start;
  60. if ((drawable->GetDrawableFlags() & drawableFlags_) && drawable->IsVisible() && (drawable->GetViewMask() & viewMask_))
  61. {
  62. if (inside || sphere_.IsInsideFast(drawable->GetWorldBoundingBox()))
  63. result_.Push(drawable);
  64. }
  65. ++start;
  66. }
  67. }
  68. Intersection BoxOctreeQuery::TestOctant(const BoundingBox& box, bool inside)
  69. {
  70. if (inside)
  71. return INSIDE;
  72. else
  73. return box_.IsInside(box);
  74. }
  75. void BoxOctreeQuery::TestDrawables(Drawable** start, Drawable** end, bool inside)
  76. {
  77. while (start != end)
  78. {
  79. Drawable* drawable = *start;
  80. if ((drawable->GetDrawableFlags() & drawableFlags_) && drawable->IsVisible() && (drawable->GetViewMask() & viewMask_))
  81. {
  82. if (inside || box_.IsInsideFast(drawable->GetWorldBoundingBox()))
  83. result_.Push(drawable);
  84. }
  85. ++start;
  86. }
  87. }
  88. Intersection FrustumOctreeQuery::TestOctant(const BoundingBox& box, bool inside)
  89. {
  90. if (inside)
  91. return INSIDE;
  92. else
  93. return frustum_.IsInside(box);
  94. }
  95. void FrustumOctreeQuery::TestDrawables(Drawable** start, Drawable** end, bool inside)
  96. {
  97. while (start != end)
  98. {
  99. Drawable* drawable = *start;
  100. if ((drawable->GetDrawableFlags() & drawableFlags_) && drawable->IsVisible() && (drawable->GetViewMask() & viewMask_))
  101. {
  102. if (inside || frustum_.IsInsideFast(drawable->GetWorldBoundingBox()))
  103. result_.Push(drawable);
  104. }
  105. ++start;
  106. }
  107. }
  108. }