Wednesday, July 29, 2015

The dangers of dynamic memory allocation and working out a passable navigation mesh

Phew, today was a tough day. Regardless of the lack of documentation, I pedaled through Recast's methods of creating a basic navigation mesh and figuring out how to load DirectX vertices and indices into the float* and int* arrays that Recast uses. I have no idea why the person who did these libraries thought it was a good idea; I was very confused by the cap variable and its use in constantly allocating memory as the amount of vertices and triangles increased (y'know, because of that no-documentation thing) but finally managed to figure it out, along with the need to put a counter in midst a vector iterator to get the indices into proper triangles after three iterations.

After preparing said triangle mesh, the rest is creepily straightforward. Create a heightfield, compact it for faster use, a set of contours, a 3D mesh with matching detail object, then peel off the 3D to make a 2D mesh set that Detour can later use for pathfinding. Next up is to figure out how to fit Detour in the whole equation and I may finally be able to test a proper AI. Due to the amount of code tailored to use SDL in the demo, I am a bit hesitant in rendering the navMesh at this point, but if worse comes to worse, I may have to convert back from dynamic arrays to vectors. If anyone uses Recast or has worked with it, a version that actually uses std::vectors would be VERY much appreciated.

No comments:

Post a Comment