RecastDll.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #include "RecastDll.h"
  2. #include "CRecastHelper.h"
  3. extern "C"
  4. {
  5. CRecastHelper* _helper = NULL;
  6. DllExport bool recast_init()
  7. {
  8. _helper = new CRecastHelper();
  9. return true;
  10. }
  11. void recast_fini()
  12. {
  13. if (_helper)
  14. delete _helper;
  15. _helper = NULL;
  16. }
  17. bool recast_loadmap(int id, const char* path)
  18. {
  19. if (!_helper) return false;
  20. if (!_helper->LoadMap(id, path))
  21. return false;
  22. return true;
  23. }
  24. bool recast_freemap(int id)
  25. {
  26. if (!_helper || !_helper->Get(id)) return false;
  27. _helper->FreeMap(id);
  28. return true;
  29. }
  30. int recast_findpath(int id, const float* spos, const float* epos)
  31. {
  32. if (!_helper || !_helper->Get(id)) return 0;
  33. dtStatus status = _helper->Get(id)->FindPath(spos, epos);
  34. return status;
  35. }
  36. bool recast_smooth(int id, float step_size, float slop)
  37. {
  38. if (!_helper || !_helper->Get(id)) return false;
  39. _helper->Get(id)->Smooth(step_size, slop);
  40. return true;
  41. }
  42. int recast_raycast(int id, const float* spos, const float* epos)
  43. {
  44. if (!_helper || !_helper->Get(id)) return 0;
  45. dtStatus status = _helper->Get(id)->Raycast(spos, epos);
  46. return status;
  47. }
  48. float* recast_gethitposition(int id)
  49. {
  50. if (!_helper || !_helper->Get(id)) return NULL;
  51. return _helper->Get(id)->GetHitPosition();
  52. }
  53. int recast_getcountpoly(int id)
  54. {
  55. if (!_helper || !_helper->Get(id)) return 0;
  56. return _helper->Get(id)->GetCountPoly();
  57. }
  58. int recast_getcountsmooth(int id)
  59. {
  60. if (!_helper || !_helper->Get(id)) return 0;
  61. return _helper->Get(id)->GetCountSmooth();
  62. }
  63. unsigned int* recast_getpathpoly(int id)
  64. {
  65. if (!_helper || !_helper->Get(id)) return NULL;
  66. int count = 0;
  67. unsigned int* polys = _helper->Get(id)->GetPathPoly(&count);
  68. if (count == 0)
  69. return NULL;
  70. return polys;
  71. }
  72. float* recast_getpathsmooth(int id)
  73. {
  74. if (!_helper || !_helper->Get(id)) return NULL;
  75. int count = 0;
  76. float* polys = _helper->Get(id)->GetPathSmooth(&count);
  77. if (count == 0)
  78. return NULL;
  79. return polys;
  80. }
  81. float* recast_getfixposition(int id, const float* pos)
  82. {
  83. if (!_helper || !_helper->Get(id)) return NULL;
  84. float* fixPos = _helper->Get(id)->fixPosition(pos);
  85. return fixPos;
  86. }
  87. }