MiniAPI/MiniCollision.c
void miniCutBox(const MINI_Box* pBox, MINI_Box* pLeftBox, MINI_Box* pRightBox)
{
    float    x;
    float    y;
    float    z;
    unsigned longestAxis;

    // calculate each edge length
    x = fabs(pBox->m_Max.m_X - pBox->m_Min.m_X);
    y = fabs(pBox->m_Max.m_Y - pBox->m_Min.m_Y);
    z = fabs(pBox->m_Max.m_Z - pBox->m_Min.m_Z);

    // search for longest axis
    if (x >= y && x >= z)
        longestAxis = 0;
    else
    if (y >= x && y >= z)
        longestAxis = 1;
    else
        longestAxis = 2;

    // cut box
    switch (longestAxis)
    {
        // cut on x axis
        case 0:
            pLeftBox->m_Min     = pBox->m_Min;
            pLeftBox->m_Max     = pBox->m_Max;
            pLeftBox->m_Max.m_X = pBox->m_Min.m_X + (x / 2.0f);

            pRightBox->m_Min     = pBox->m_Min;
            pRightBox->m_Max     = pBox->m_Max;
            pRightBox->m_Min.m_X = pBox->m_Min.m_X + (x / 2.0f);
            break;

        // cut on y axis
        case 1:
            pLeftBox->m_Min     = pBox->m_Min;
            pLeftBox->m_Max     = pBox->m_Max;
            pLeftBox->m_Max.m_Y = pBox->m_Min.m_Y + (y / 2.0f);

            pRightBox->m_Min     = pBox->m_Min;
            pRightBox->m_Max     = pBox->m_Max;
            pRightBox->m_Min.m_Y = pBox->m_Min.m_Y + (y / 2.0f);
            break;

        // cut on z axis
        case 2:
            pLeftBox->m_Min     = pBox->m_Min;
            pLeftBox->m_Max     = pBox->m_Max;
            pLeftBox->m_Max.m_Z = pBox->m_Min.m_Z + (z / 2.0f);

            pRightBox->m_Min     = pBox->m_Min;
            pRightBox->m_Max     = pBox->m_Max;
            pRightBox->m_Min.m_Z = pBox->m_Min.m_Z + (z / 2.0f);
            break;
    }
}
//----------------------------------------------------------------------------
// Aligned-Axis Bounding Box tree
//----------------------------------------------------------------------------
Aligned-Axis Bounding Box tree
Aligned - Axis Bounding Box tree
void miniCutBox(const MINI_Box* pBox, MINI_Box* pLeftBox, MINI_Box* pRightBox)
{
    float    x;
    float    y;
    float    z;
    unsigned longestAxis;
    x = fabs(pBox->m_Max.m_X - pBox->m_Min.m_X);
    y = fabs(pBox->m_Max.m_Y - pBox->m_Min.m_Y);
    z = fabs(pBox->m_Max.m_Z - pBox->m_Min.m_Z);
    if (x >= y && x >= z)
        longestAxis = 0;
    else
    if (y >= x && y >= z)
        longestAxis = 1;
    else
        longestAxis = 2;
    switch (longestAxis)
    {
        case 0:
            pLeftBox->m_Min     = pBox->m_Min;
            pLeftBox->m_Max     = pBox->m_Max;
            pLeftBox->m_Max.m_X = pBox->m_Min.m_X + (x / 2.0f);
            pRightBox->m_Min     = pBox->m_Min;
            pRightBox->m_Max     = pBox->m_Max;
            pRightBox->m_Min.m_X = pBox->m_Min.m_X + (x / 2.0f);
            break;
        case 1:
            pLeftBox->m_Min     = pBox->m_Min;
            pLeftBox->m_Max     = pBox->m_Max;
            pLeftBox->m_Max.m_Y = pBox->m_Min.m_Y + (y / 2.0f);
            pRightBox->m_Min     = pBox->m_Min;
            pRightBox->m_Max     = pBox->m_Max;
            pRightBox->m_Min.m_Y = pBox->m_Min.m_Y + (y / 2.0f);
            break;
        case 2:
            pLeftBox->m_Min     = pBox->m_Min;
            pLeftBox->m_Max     = pBox->m_Max;
            pLeftBox->m_Max.m_Z = pBox->m_Min.m_Z + (z / 2.0f);
            pRightBox->m_Min     = pBox->m_Min;
            pRightBox->m_Max     = pBox->m_Max;
            pRightBox->m_Min.m_Z = pBox->m_Min.m_Z + (z / 2.0f);
            break;
    }
}
void miniCutBox ( const MINI_Box * pBox , MINI_Box * pLeftBox , MINI_Box * pRightBox ) { float x ; float y ; float z ; unsigned longestAxis ; x = fabs ( pBox -> m_Max . m_X - pBox -> m_Min . m_X ) ; y = fabs ( pBox -> m_Max . m_Y - pBox -> m_Min . m_Y ) ; z = fabs ( pBox -> m_Max . m_Z - pBox -> m_Min . m_Z ) ; if ( x >= y && x >= z ) longestAxis = 0 ; else if ( y >= x && y >= z ) longestAxis = 1 ; else longestAxis = 2 ; switch ( longestAxis ) { case 0 : pLeftBox -> m_Min = pBox -> m_Min ; pLeftBox -> m_Max = pBox -> m_Max ; pLeftBox -> m_Max . m_X = pBox -> m_Min . m_X + ( x / 2.0f ) ; pRightBox -> m_Min = pBox -> m_Min ; pRightBox -> m_Max = pBox -> m_Max ; pRightBox -> m_Min . m_X = pBox -> m_Min . m_X + ( x / 2.0f ) ; break ; case 1 : pLeftBox -> m_Min = pBox -> m_Min ; pLeftBox -> m_Max = pBox -> m_Max ; pLeftBox -> m_Max . m_Y = pBox -> m_Min . m_Y + ( y / 2.0f ) ; pRightBox -> m_Min = pBox -> m_Min ; pRightBox -> m_Max = pBox -> m_Max ; pRightBox -> m_Min . m_Y = pBox -> m_Min . m_Y + ( y / 2.0f ) ; break ; case 2 : pLeftBox -> m_Min = pBox -> m_Min ; pLeftBox -> m_Max = pBox -> m_Max ; pLeftBox -> m_Max . m_Z = pBox -> m_Min . m_Z + ( z / 2.0f ) ; pRightBox -> m_Min = pBox -> m_Min ; pRightBox -> m_Max = pBox -> m_Max ; pRightBox -> m_Min . m_Z = pBox -> m_Min . m_Z + ( z / 2.0f ) ; break ; } }
Aligned-Axis Bounding Box tree
Aligned - Axis Bounding Box tree
// calculate each edge length // search for longest axis // cut box // cut on x axis // cut on y axis // cut on z axis