DetourProximityGrid.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
  3. //
  4. // This software is provided 'as-is', without any express or implied
  5. // warranty. In no event will the authors be held liable for any damages
  6. // arising from the use of this software.
  7. // Permission is granted to anyone to use this software for any purpose,
  8. // including commercial applications, and to alter it and redistribute it
  9. // freely, subject to the following restrictions:
  10. // 1. The origin of this software must not be misrepresented; you must not
  11. // claim that you wrote the original software. If you use this software
  12. // in a product, an acknowledgment in the product documentation would be
  13. // appreciated but is not required.
  14. // 2. Altered source versions must be plainly marked as such, and must not be
  15. // misrepresented as being the original software.
  16. // 3. This notice may not be removed or altered from any source distribution.
  17. //
  18. #ifndef DETOURPROXIMITYGRID_H
  19. #define DETOURPROXIMITYGRID_H
  20. class dtProximityGrid
  21. {
  22. float m_cellSize;
  23. float m_invCellSize;
  24. struct Item
  25. {
  26. unsigned short id;
  27. short x,y;
  28. unsigned short next;
  29. };
  30. Item* m_pool;
  31. int m_poolHead;
  32. int m_poolSize;
  33. unsigned short* m_buckets;
  34. int m_bucketsSize;
  35. int m_bounds[4];
  36. public:
  37. dtProximityGrid();
  38. ~dtProximityGrid();
  39. bool init(const int poolSize, const float cellSize);
  40. void clear();
  41. void addItem(const unsigned short id,
  42. const float minx, const float miny,
  43. const float maxx, const float maxy);
  44. int queryItems(const float minx, const float miny,
  45. const float maxx, const float maxy,
  46. unsigned short* ids, const int maxIds) const;
  47. int getItemCountAt(const int x, const int y) const;
  48. inline const int* getBounds() const { return m_bounds; }
  49. inline float getCellSize() const { return m_cellSize; }
  50. };
  51. dtProximityGrid* dtAllocProximityGrid();
  52. void dtFreeProximityGrid(dtProximityGrid* ptr);
  53. #endif // DETOURPROXIMITYGRID_H