OctreeQuery.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2012 Lasse Oorni
  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->IsVisible() && (drawable->GetDrawableFlags() & drawableFlags_) && (drawable->GetViewMask() & viewMask_))
  41. {
  42. if (inside || drawable->GetWorldBoundingBox().IsInside(point_))
  43. result_.Push(drawable);
  44. }
  45. }
  46. }
  47. Intersection SphereOctreeQuery::TestOctant(const BoundingBox& box, bool inside)
  48. {
  49. if (inside)
  50. return INSIDE;
  51. else
  52. return sphere_.IsInside(box);
  53. }
  54. void SphereOctreeQuery::TestDrawables(Drawable** start, Drawable** end, bool inside)
  55. {
  56. while (start != end)
  57. {
  58. Drawable* drawable = *start++;
  59. if (drawable->IsVisible() && (drawable->GetDrawableFlags() & drawableFlags_) && (drawable->GetViewMask() & viewMask_))
  60. {
  61. if (inside || sphere_.IsInsideFast(drawable->GetWorldBoundingBox()))
  62. result_.Push(drawable);
  63. }
  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->IsVisible() && (drawable->GetDrawableFlags() & drawableFlags_) && (drawable->GetViewMask() & viewMask_))
  79. {
  80. if (inside || box_.IsInsideFast(drawable->GetWorldBoundingBox()))
  81. result_.Push(drawable);
  82. }
  83. }
  84. }
  85. Intersection FrustumOctreeQuery::TestOctant(const BoundingBox& box, bool inside)
  86. {
  87. if (inside)
  88. return INSIDE;
  89. else
  90. return frustum_.IsInside(box);
  91. }
  92. void FrustumOctreeQuery::TestDrawables(Drawable** start, Drawable** end, bool inside)
  93. {
  94. while (start != end)
  95. {
  96. Drawable* drawable = *start++;
  97. if (drawable->IsVisible() && (drawable->GetDrawableFlags() & drawableFlags_) && (drawable->GetViewMask() & viewMask_))
  98. {
  99. if (inside || frustum_.IsInsideFast(drawable->GetWorldBoundingBox()))
  100. result_.Push(drawable);
  101. }
  102. }
  103. }
  104. }