Commits

Daniel K. O. committed 830b683

some more code for hash space

Comments (0)

Files changed (2)

include/kode/collision/HashSpace.hpp

 namespace kode {
 
     class HashSpace : public Space {
-
+        int minLevel = -3;
+        int maxLevel = 20;
     public:
 
         void findPairs(const std::function<void(Geom&, Geom&)>& callback) override;

src/collision/HashSpace.cpp

         constexpr uint32_t p3 = 2654435789u;
         constexpr uint32_t p4 = 1785443183u;
 
+
         struct Hasher {
             size_t
             operator()(const Key& key) const noexcept
             }
         };
 
-        struct Value {
-            
-            const Geom* geom;
+
+        struct AABBidx {
+            int32_t minX, maxX, minY, maxY, minZ, maxZ;
         };
 
 
+        struct Value {
+            Geom* geom;
+            AABBidx idx;
+        };
+
     
         // return the `level' of an AABB. the AABB will be put into cells at this
         // level - the cell size will be 2^level. the level is chosen to be the
         // where q is the maximum AABB dimension.
 
         inline
-        int32_t
+        int
         findLevel (const AxisAlignedBox& box)
         {
             if (!box.isFinite())
-                return std::numeric_limits<int32_t>::max();
+                return std::numeric_limits<int>::max();
 
             const Vector3 size = box.getSize();
             const Real m = std::max({size.x, size.y, size.z});
             return;
 
         std::vector<Geom*> big_geoms;
-        std::unordered_map<Key, Value, Hasher> table;
+        std::unordered_multimap<Key, Value, Hasher> table;
         for (Geom* g : geoms) {
             if (!g->isEnabled())
                 continue;
-            
+
+            const int level = findLevel(g->getAABB());
+            if (level > maxLevel) {
+                bigGeoms.push_back(g);
+            } else {
+                
+            }
         }
     }