OctreeQuery.cpp 3.6 KB

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