Octree.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <Tests/Framework/Framework.h>
  6. #include <anki/scene/Octree.h>
  7. namespace anki
  8. {
  9. ANKI_TEST(Scene, Octree)
  10. {
  11. HeapAllocator<U8> alloc(allocAligned, nullptr);
  12. // Fuzzy
  13. #if 0
  14. {
  15. Octree octree(alloc);
  16. octree.init(Vec3(-100.0f), Vec3(100.0f), 4);
  17. OrthographicFrustum frustum(-200.0f, 200.0f, -200.0f, 200.0f, 200.0f, -200.0f);
  18. frustum.resetTransform(Transform::getIdentity());
  19. const U ITERATION_COUNT = 1000;
  20. Array<OctreePlaceable, ITERATION_COUNT> placeables;
  21. std::vector<U32> placed;
  22. for(U i = 0; i < ITERATION_COUNT; ++i)
  23. {
  24. F32 min = randRange(-100.0f, 100.0f - 1.0f);
  25. F32 max = randRange(min + 1.0f, 100.0f);
  26. Aabb volume(Vec4(Vec3(min), 0.0f), Vec4(Vec3(max), 0.0f));
  27. I mode = rand() % 3;
  28. if(mode == 0)
  29. {
  30. // Place
  31. placeables[i].m_userData = &placeables[i];
  32. octree.place(volume, &placeables[i], true);
  33. placed.push_back(i);
  34. }
  35. else if(mode == 1 && placed.size() > 0)
  36. {
  37. // Remove
  38. octree.remove(placeables[placed.back()]);
  39. placed.pop_back();
  40. }
  41. else if(placed.size() > 0)
  42. {
  43. // Gather
  44. // Reset the placed
  45. for(U32 idx : placed)
  46. {
  47. placeables[idx].reset();
  48. }
  49. DynamicArrayAuto<void*> arr(alloc);
  50. octree.gatherVisible(frustum, 0, nullptr, nullptr, arr);
  51. ANKI_TEST_EXPECT_EQ(arr.getSize(), placed.size());
  52. for(U32 idx : placed)
  53. {
  54. Bool found = false;
  55. for(void* placeable : arr)
  56. {
  57. if(&placeables[idx] == static_cast<OctreePlaceable*>(placeable))
  58. {
  59. found = true;
  60. break;
  61. }
  62. }
  63. ANKI_TEST_EXPECT_EQ(found, true);
  64. }
  65. }
  66. }
  67. // Remove all
  68. while(!placed.empty())
  69. {
  70. octree.remove(placeables[placed.back()]);
  71. placed.pop_back();
  72. }
  73. }
  74. #endif
  75. }
  76. } // end namespace anki