| 730 | } |
| 731 | |
| 732 | void dtNavMeshQuery::queryPolygonsInTile(const dtMeshTile* tile, const float* qmin, const float* qmax, |
| 733 | const dtQueryFilter* filter, dtPolyQuery* query) const |
| 734 | { |
| 735 | dtAssert(m_nav); |
| 736 | static const int batchSize = 32; |
| 737 | dtPolyRef polyRefs[batchSize]; |
| 738 | dtPoly* polys[batchSize]; |
| 739 | int n = 0; |
| 740 | |
| 741 | if (tile->bvTree) |
| 742 | { |
| 743 | const dtBVNode* node = &tile->bvTree[0]; |
| 744 | const dtBVNode* end = &tile->bvTree[tile->header->bvNodeCount]; |
| 745 | const float* tbmin = tile->header->bmin; |
| 746 | const float* tbmax = tile->header->bmax; |
| 747 | const float qfac = tile->header->bvQuantFactor; |
| 748 | |
| 749 | // Calculate quantized box |
| 750 | unsigned short bmin[3], bmax[3]; |
| 751 | // dtClamp query box to world box. |
| 752 | float minx = dtClamp(qmin[0], tbmin[0], tbmax[0]) - tbmin[0]; |
| 753 | float miny = dtClamp(qmin[1], tbmin[1], tbmax[1]) - tbmin[1]; |
| 754 | float minz = dtClamp(qmin[2], tbmin[2], tbmax[2]) - tbmin[2]; |
| 755 | float maxx = dtClamp(qmax[0], tbmin[0], tbmax[0]) - tbmin[0]; |
| 756 | float maxy = dtClamp(qmax[1], tbmin[1], tbmax[1]) - tbmin[1]; |
| 757 | float maxz = dtClamp(qmax[2], tbmin[2], tbmax[2]) - tbmin[2]; |
| 758 | // Quantize |
| 759 | bmin[0] = (unsigned short)(qfac * minx) & 0xfffe; |
| 760 | bmin[1] = (unsigned short)(qfac * miny) & 0xfffe; |
| 761 | bmin[2] = (unsigned short)(qfac * minz) & 0xfffe; |
| 762 | bmax[0] = (unsigned short)(qfac * maxx + 1) | 1; |
| 763 | bmax[1] = (unsigned short)(qfac * maxy + 1) | 1; |
| 764 | bmax[2] = (unsigned short)(qfac * maxz + 1) | 1; |
| 765 | |
| 766 | // Traverse tree |
| 767 | const dtPolyRef base = m_nav->getPolyRefBase(tile); |
| 768 | while (node < end) |
| 769 | { |
| 770 | const bool overlap = dtOverlapQuantBounds(bmin, bmax, node->bmin, node->bmax); |
| 771 | const bool isLeafNode = node->i >= 0; |
| 772 | |
| 773 | if (isLeafNode && overlap) |
| 774 | { |
| 775 | dtPolyRef ref = base | (dtPolyRef)node->i; |
| 776 | if (filter->passFilter(ref, tile, &tile->polys[node->i])) |
| 777 | { |
| 778 | polyRefs[n] = ref; |
| 779 | polys[n] = &tile->polys[node->i]; |
| 780 | |
| 781 | if (n == batchSize - 1) |
| 782 | { |
| 783 | query->process(tile, polys, polyRefs, batchSize); |
| 784 | n = 0; |
| 785 | } |
| 786 | else |
| 787 | { |
| 788 | n++; |
| 789 | } |
nothing calls this directly
no test coverage detected