OctreeQuery.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. Intersection PointOctreeQuery::TestOctant(const BoundingBox& box, bool inside)
  27. {
  28. if (inside)
  29. return INSIDE;
  30. else
  31. return box.IsInside(point_);
  32. }
  33. void PointOctreeQuery::TestDrawables(Drawable** start, Drawable** end, bool inside)
  34. {
  35. while (start != end)
  36. {
  37. Drawable* drawable = *start;
  38. if ((drawable->GetDrawableFlags() & drawableFlags_) && drawable->IsVisible() && (drawable->GetViewMask() & viewMask_))
  39. {
  40. if (inside || drawable->GetWorldBoundingBox().IsInside(point_))
  41. result_.Push(drawable);
  42. }
  43. ++start;
  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->IsVisible() && (drawable->GetViewMask() & viewMask_))
  59. {
  60. if (inside || sphere_.IsInsideFast(drawable->GetWorldBoundingBox()))
  61. result_.Push(drawable);
  62. }
  63. ++start;
  64. }
  65. }
  66. Intersection BoxOctreeQuery::TestOctant(const BoundingBox& box, bool inside)
  67. {
  68. if (inside)
  69. return INSIDE;
  70. else
  71. return box_.IsInside(box);
  72. }
  73. void BoxOctreeQuery::TestDrawables(Drawable** start, Drawable** end, bool inside)
  74. {
  75. while (start != end)
  76. {
  77. Drawable* drawable = *start;
  78. if ((drawable->GetDrawableFlags() & drawableFlags_) && drawable->IsVisible() && (drawable->GetViewMask() & viewMask_))
  79. {
  80. if (inside || box_.IsInsideFast(drawable->GetWorldBoundingBox()))
  81. result_.Push(drawable);
  82. }
  83. ++start;
  84. }
  85. }
  86. Intersection FrustumOctreeQuery::TestOctant(const BoundingBox& box, bool inside)
  87. {
  88. if (inside)
  89. return INSIDE;
  90. else
  91. return frustum_.IsInside(box);
  92. }
  93. void FrustumOctreeQuery::TestDrawables(Drawable** start, Drawable** end, bool inside)
  94. {
  95. while (start != end)
  96. {
  97. Drawable* drawable = *start;
  98. if ((drawable->GetDrawableFlags() & drawableFlags_) && drawable->IsVisible() && (drawable->GetViewMask() & viewMask_))
  99. {
  100. if (inside || frustum_.IsInsideFast(drawable->GetWorldBoundingBox()))
  101. result_.Push(drawable);
  102. }
  103. ++start;
  104. }
  105. }