Guest User

Untitled

a guest
Nov 23rd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.75 KB | None | 0 0
  1.  
  2. bool CNavMeshInterface::GetWalkingHeightInternal(uint32 mapid, float positionx, float positiony, float positionz, float endz, LocationVector& out)
  3. {
  4.     if(m_navMesh[mapid] == NULL)
  5.         return false;
  6.  
  7.     dtNavMeshQuery* query = mallocNavMeshQuery();
  8.     if(query->init(m_navMesh[mapid], 1024) != DT_SUCCESS)
  9.     {
  10.         freeNavMeshQuery(query);
  11.         Log.Error("NavMeshInterface", "Failed to initialize dtNavMeshQuery for mapId %03u", mapid);
  12.         return false;
  13.     }
  14.  
  15.     dtStatus result;
  16.     //convert to nav coords.
  17.     float startPos[3] = { positiony, positionz, positionx };
  18.     float endPos[3] = { positiony, endz, positionx };
  19.     float mPolyPickingExtents[3] = { 2.00f, 4.00f, 2.00f };
  20.     float closestPoint[3] = {0.0f, 0.0f, 0.0f};
  21.     int gx = GetPosX(positionx)/8;
  22.     int gy = GetPosY(positiony)/8;
  23.     dtQueryFilter* mPathFilter = new dtQueryFilter();
  24.     if(mPathFilter)
  25.     {
  26.         dtPolyRef mStartRef;
  27.         result = query->findNearestPoly(startPos, mPolyPickingExtents, mPathFilter, &mStartRef, closestPoint);
  28.         if(result != DT_SUCCESS || !mStartRef)
  29.         {
  30.             freeNavMeshQuery(query);
  31.             delete mPathFilter;
  32.             mPathFilter = NULL;
  33.             return false;
  34.         }
  35.  
  36.         dtPolyRef mEndRef;
  37.         result = query->findNearestPoly(endPos, mPolyPickingExtents, mPathFilter, &mEndRef, closestPoint);
  38.         if(result != DT_SUCCESS || !mEndRef)
  39.         {
  40.             freeNavMeshQuery(query);
  41.             delete mPathFilter;
  42.             mPathFilter = NULL;
  43.             return false;
  44.         }
  45.  
  46.         if (mStartRef != 0 && mEndRef != 0)
  47.         {
  48.             int mNumPathResults;
  49.             dtPolyRef mPathResults[50];
  50.             result = query->findPath(mStartRef, mEndRef,startPos, endPos, mPathFilter, mPathResults, &mNumPathResults, 50);
  51.             if(result != DT_SUCCESS || mNumPathResults <= 0)
  52.             {
  53.                 freeNavMeshQuery(query);
  54.                 delete mPathFilter;
  55.                 mPathFilter = NULL;
  56.                 return false;
  57.             }
  58.  
  59.             int mNumPathPoints;
  60.             float actualpath[3*2];
  61.             dtPolyRef polyrefs = 0;
  62.             result = query->findStraightPath(startPos, endPos, mPathResults, mNumPathResults, actualpath, NULL, &polyrefs, &mNumPathPoints, 2);
  63.             if (result != DT_SUCCESS)
  64.             {
  65.                 freeNavMeshQuery(query);
  66.                 delete mPathFilter;
  67.                 mPathFilter = NULL;
  68.                 return false;
  69.             }
  70.             if(mNumPathPoints < 3)
  71.             {
  72.                 out.y = positiony;
  73.                 out.z = positionz;
  74.                 out.x = positionx;
  75.                 freeNavMeshQuery(query);
  76.                 delete mPathFilter;
  77.                 mPathFilter = NULL;
  78.                 return true;
  79.             }
  80.  
  81.             out.y = actualpath[3];
  82.             out.z = actualpath[4];
  83.             out.x = actualpath[5];
  84.             freeNavMeshQuery(query);
  85.             delete mPathFilter;
  86.             mPathFilter = NULL;
  87.             return true;
  88.         }
  89.     }
  90.     return false;
  91. }
  92.  
  93. float CNavMeshInterface::GetWalkingHeight(uint32 mapid, float x, float y, float z, float z2)
  94. {
  95.     float height = MMAP_UNAVAILABLE;
  96.     LocationVector Step;
  97.     if(GetWalkingHeightInternal(mapid, x, y, z, z2, Step))
  98.         height = Step.z;
  99.     return height;
  100. }
Add Comment
Please, Sign In to add comment