OctreeQuery.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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(const PODVector<Drawable*>& drawables, bool inside)
  34. {
  35. Drawable** ptr = const_cast<Drawable**>(&drawables.Front());
  36. Drawable** end = ptr + drawables.Size();
  37. while (ptr != end)
  38. {
  39. Drawable* drawable = *ptr;
  40. if ((drawable->GetDrawableFlags() & drawableFlags_) && drawable->IsVisible() && (drawable->GetViewMask() & viewMask_))
  41. {
  42. if (inside || drawable->GetWorldBoundingBox().IsInside(point_))
  43. result_.Push(drawable);
  44. }
  45. ++ptr;
  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(const PODVector<Drawable*>& drawables, bool inside)
  56. {
  57. Drawable** ptr = const_cast<Drawable**>(&drawables.Front());
  58. Drawable** end = ptr + drawables.Size();
  59. while (ptr != end)
  60. {
  61. Drawable* drawable = *ptr;
  62. if ((drawable->GetDrawableFlags() & drawableFlags_) && drawable->IsVisible() && (drawable->GetViewMask() & viewMask_))
  63. {
  64. if (inside || sphere_.IsInsideFast(drawable->GetWorldBoundingBox()))
  65. result_.Push(drawable);
  66. }
  67. ++ptr;
  68. }
  69. }
  70. Intersection BoxOctreeQuery::TestOctant(const BoundingBox& box, bool inside)
  71. {
  72. if (inside)
  73. return INSIDE;
  74. else
  75. return box_.IsInside(box);
  76. }
  77. void BoxOctreeQuery::TestDrawables(const PODVector<Drawable*>& drawables, bool inside)
  78. {
  79. Drawable** ptr = const_cast<Drawable**>(&drawables.Front());
  80. Drawable** end = ptr + drawables.Size();
  81. while (ptr != end)
  82. {
  83. Drawable* drawable = *ptr;
  84. if ((drawable->GetDrawableFlags() & drawableFlags_) && drawable->IsVisible() && (drawable->GetViewMask() & viewMask_))
  85. {
  86. if (inside || box_.IsInsideFast(drawable->GetWorldBoundingBox()))
  87. result_.Push(drawable);
  88. }
  89. ++ptr;
  90. }
  91. }
  92. Intersection FrustumOctreeQuery::TestOctant(const BoundingBox& box, bool inside)
  93. {
  94. if (inside)
  95. return INSIDE;
  96. else
  97. return frustum_.IsInside(box);
  98. }
  99. void FrustumOctreeQuery::TestDrawables(const PODVector<Drawable*>& drawables, bool inside)
  100. {
  101. Drawable** ptr = const_cast<Drawable**>(&drawables.Front());
  102. Drawable** end = ptr + drawables.Size();
  103. while (ptr != end)
  104. {
  105. Drawable* drawable = *ptr;
  106. if ((drawable->GetDrawableFlags() & drawableFlags_) && drawable->IsVisible() && (drawable->GetViewMask() & viewMask_))
  107. {
  108. if (inside || frustum_.IsInsideFast(drawable->GetWorldBoundingBox()))
  109. result_.Push(drawable);
  110. }
  111. ++ptr;
  112. }
  113. }