1 /* This file is part of Dilay 2 * Copyright © 2015-2018 Alexander Bau 3 * Use and redistribute under the terms of the GNU General Public License 4 */ 5 #ifndef DILAY_DYNAMIC_OCTREE 6 #define DILAY_DYNAMIC_OCTREE 7 8 #include <functional> 9 #include <glm/fwd.hpp> 10 #include <vector> 11 #include "macro.hpp" 12 13 class Camera; 14 class PrimAABox; 15 class PrimPlane; 16 class PrimRay; 17 class PrimSphere; 18 19 class DynamicOctree 20 { 21 public: 22 DECLARE_BIG4_EXPLICIT_COPY (DynamicOctree) 23 24 typedef std::function<void(unsigned int)> IntersectionCallback; 25 typedef std::function<float(unsigned int)> RayIntersectionCallback; 26 typedef std::function<void(bool, unsigned int)> ContainsIntersectionCallback; 27 typedef std::function<float(unsigned int)> DistanceCallback; 28 29 bool hasRoot () const; 30 void setupRoot (const glm::vec3&, float); 31 void addElement (unsigned int, const glm::vec3&, float); 32 void realignElement (unsigned int, const glm::vec3&, float); 33 void deleteElement (unsigned int); 34 void deleteEmptyChildren (); 35 void updateIndices (const std::vector<unsigned int>&); 36 void shrinkRoot (); 37 void reset (); 38 void render (Camera&) const; 39 void intersects (const PrimRay&, const RayIntersectionCallback&) const; 40 void intersects (const PrimPlane&, const IntersectionCallback&) const; 41 void intersects (const PrimSphere&, const ContainsIntersectionCallback&) const; 42 void intersects (const PrimAABox&, const ContainsIntersectionCallback&) const; 43 float distance (const glm::vec3&, const DistanceCallback&) const; 44 void printStatistics () const; 45 46 private: 47 IMPLEMENTATION 48 }; 49 50 #endif 51