DetourProximityGrid.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. private:
  51. // Explicitly disabled copy constructor and copy assignment operator.
  52. dtProximityGrid(const dtProximityGrid&);
  53. dtProximityGrid& operator=(const dtProximityGrid&);
  54. };
  55. dtProximityGrid* dtAllocProximityGrid();
  56. void dtFreeProximityGrid(dtProximityGrid* ptr);
  57. #endif // DETOURPROXIMITYGRID_H