ChunkyTriMesh.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 CHUNKYTRIMESH_H
  19. #define CHUNKYTRIMESH_H
  20. struct rcChunkyTriMeshNode
  21. {
  22. float bmin[2];
  23. float bmax[2];
  24. int i;
  25. int n;
  26. };
  27. struct rcChunkyTriMesh
  28. {
  29. inline rcChunkyTriMesh() : nodes(0), nnodes(0), tris(0), ntris(0), maxTrisPerChunk(0) {};
  30. inline ~rcChunkyTriMesh() { delete [] nodes; delete [] tris; }
  31. rcChunkyTriMeshNode* nodes;
  32. int nnodes;
  33. int* tris;
  34. int ntris;
  35. int maxTrisPerChunk;
  36. private:
  37. // Explicitly disabled copy constructor and copy assignment operator.
  38. rcChunkyTriMesh(const rcChunkyTriMesh&);
  39. rcChunkyTriMesh& operator=(const rcChunkyTriMesh&);
  40. };
  41. /// Creates partitioned triangle mesh (AABB tree),
  42. /// where each node contains at max trisPerChunk triangles.
  43. bool rcCreateChunkyTriMesh(const float* verts, const int* tris, int ntris,
  44. int trisPerChunk, rcChunkyTriMesh* cm);
  45. /// Returns the chunk indices which overlap the input rectable.
  46. int rcGetChunksOverlappingRect(const rcChunkyTriMesh* cm, float bmin[2], float bmax[2], int* ids, const int maxIds);
  47. /// Returns the chunk indices which overlap the input segment.
  48. int rcGetChunksOverlappingSegment(const rcChunkyTriMesh* cm, float p[2], float q[2], int* ids, const int maxIds);
  49. #endif // CHUNKYTRIMESH_H