// sorting a max edge downwards can only ever *remove* overlaps void AxisSweep3::SortMaxDown(int axis, unsigned short edge, bool updateOverlaps) { Edge* pEdge = m_pEdges[axis] + edge; Edge* pPrev = pEdge - 1; Handle* pHandleEdge = GetHandle(pEdge->m_handle); while (pEdge->m_pos < pPrev->m_pos) { Handle* pHandlePrev = GetHandle(pPrev->m_handle); if (!pPrev->IsMax()) { // if previous edge was a minimum remove any overlap between the two handles if (updateOverlaps) { Handle* handle0 = GetHandle(pEdge->m_handle); Handle* handle1 = GetHandle(pPrev->m_handle); BroadphasePair* pair = FindPair(handle0,handle1); //assert(pair); if (pair) { RemoveOverlappingPair(*pair); } } // update edge reference in other handle pHandlePrev->m_minEdges[axis]++;; } else pHandlePrev->m_maxEdges[axis]++; pHandleEdge->m_maxEdges[axis]--; // swap the edges Edge swap = *pEdge; *pEdge = *pPrev; *pPrev = swap; // decrement pEdge--; pPrev--; } }
// sorting a min edge upwards can only ever *remove* overlaps void AxisSweep3::SortMinUp(int axis, unsigned short edge, bool updateOverlaps) { Edge* pEdge = m_pEdges[axis] + edge; Edge* pNext = pEdge + 1; Handle* pHandleEdge = GetHandle(pEdge->m_handle); while (pEdge->m_pos > pNext->m_pos) { Handle* pHandleNext = GetHandle(pNext->m_handle); if (pNext->IsMax()) { // if next edge is maximum remove any overlap between the two handles if (updateOverlaps) { Handle* handle0 = GetHandle(pEdge->m_handle); Handle* handle1 = GetHandle(pNext->m_handle); BroadphasePair* pair = FindPair(handle0,handle1); //assert(pair); if (pair) { RemoveOverlappingPair(*pair); } } // update edge reference in other handle pHandleNext->m_maxEdges[axis]--; } else pHandleNext->m_minEdges[axis]--; pHandleEdge->m_minEdges[axis]++; // swap the edges Edge swap = *pEdge; *pEdge = *pNext; *pNext = swap; // increment pEdge++; pNext++; } }
// sorting a min edge downwards can only ever *add* overlaps void AxisSweep3::SortMinDown(int axis, unsigned short edge, bool updateOverlaps) { Edge* pEdge = m_pEdges[axis] + edge; Edge* pPrev = pEdge - 1; Handle* pHandleEdge = GetHandle(pEdge->m_handle); while (pEdge->m_pos < pPrev->m_pos) { Handle* pHandlePrev = GetHandle(pPrev->m_handle); if (pPrev->IsMax()) { // if previous edge is a maximum check the bounds and add an overlap if necessary if (updateOverlaps && TestOverlap(axis,pHandleEdge, pHandlePrev)) { AddOverlappingPair(pHandleEdge,pHandlePrev); //AddOverlap(pEdge->m_handle, pPrev->m_handle); } // update edge reference in other handle pHandlePrev->m_maxEdges[axis]++; } else pHandlePrev->m_minEdges[axis]++; pHandleEdge->m_minEdges[axis]--; // swap the edges Edge swap = *pEdge; *pEdge = *pPrev; *pPrev = swap; // decrement pEdge--; pPrev--; } }
// sorting a max edge upwards can only ever *add* overlaps void AxisSweep3::SortMaxUp(int axis, unsigned short edge, bool updateOverlaps) { Edge* pEdge = m_pEdges[axis] + edge; Edge* pNext = pEdge + 1; Handle* pHandleEdge = GetHandle(pEdge->m_handle); while (pEdge->m_pos > pNext->m_pos) { Handle* pHandleNext = GetHandle(pNext->m_handle); if (!pNext->IsMax()) { // if next edge is a minimum check the bounds and add an overlap if necessary if (updateOverlaps && TestOverlap(axis, pHandleEdge, pHandleNext)) { Handle* handle0 = GetHandle(pEdge->m_handle); Handle* handle1 = GetHandle(pNext->m_handle); AddOverlappingPair(handle0,handle1); } // update edge reference in other handle pHandleNext->m_minEdges[axis]--; } else pHandleNext->m_maxEdges[axis]--; pHandleEdge->m_maxEdges[axis]++; // swap the edges Edge swap = *pEdge; *pEdge = *pNext; *pNext = swap; // increment pEdge++; pNext++; } }