Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Collision - F - Triangle [Axis Separation].c_inc
    »Keywords«  Collision;Distance;Closest;Intersect;Penetrate;Sweep;Triangle;
    »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
    »Version«   4.51 / »GUID« A9981407-3EC9-42AF-8B6F-8BE6DD919615                                                                                                        */
/*   -------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
/*  Copyright: © 2002-2017, Andrew Aye.  All Rights Reserved.
    This software is free for non-commercial use.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
      following conditions are met:
        Redistribution of source code must retain this copyright notice, this list of conditions and the following disclaimers.
        Redistribution in binary form must reproduce this copyright notice, this list of conditions and the following disclaimers in the documentation and other materials
          provided with the distribution.
    The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
    The intellectual property rights of the algorithms used reside with Andrew Aye.
    You may not use this software, in whole or in part, in support of any commercial product without the express written consent of the author.
    There is no warranty or other guarantee of fitness of this software for any purpose. It is provided solely "as is".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/* == Collision ========================================================================================================================================================= */

/* ---- V(tgCO_F_PT_Axis_ProjInfo) -------------------------------------------------------------------------------------------------------------------------------------- */
/* Input:  vAx: Axis of separation being tested                                                                                                                           */
/* Input:  tgPT0: Point triangle primitive                                                                                                                                */
/* Output: tgConfig: Holds the resulting information for the axis separation tests for this primitive                                                                     */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID V(tgCO_F_PT_Axis_ProjInfo)( V(PC_STg2_CO_Axis_Project) psConfig, V(CPC_TgVEC) pvAx, V(CPC_TgPTRI) psPT0 )
{
    /* Feature ID: 0,1,2 = Points 0,1,2; 4,5,6 = Edge 0,1,2 [0->1, 0->2, 1->2] */

    const TYPE                          fP0_AX = V(F_DOT)(pvAx, psPT0->m_avPoint + 0);
    const TYPE                          fP1_AX = V(F_DOT)(pvAx, psPT0->m_avPoint + 1);
    const TYPE                          fP2_AX = V(F_DOT)(pvAx, psPT0->m_avPoint + 2);

    C_TgBOOL                            bEq01 = F(tgCM_NR0)(fP0_AX - fP1_AX);
    C_TgBOOL                            bEq02 = F(tgCM_NR0)(fP0_AX - fP2_AX);
    C_TgBOOL                            bEq12 = F(tgCM_NR0)(fP1_AX - fP2_AX);

    /* Explicit sort of vertices to construct a ContactConfig. */

    if (fP0_AX <= fP1_AX)
    {
        if (fP1_AX <= fP2_AX) /* fP0_AX <= fP1_AX <= fP2_AX */
        {
            psConfig->m_avMinVert[0] = psPT0->m_avPoint[0];
            psConfig->m_avMinVert[1] = psPT0->m_avPoint[1];
            psConfig->m_avMinVert[2] = psPT0->m_avPoint[2];
            psConfig->m_avMaxVert[0] = psPT0->m_avPoint[2];
            psConfig->m_avMaxVert[1] = psPT0->m_avPoint[1];
            psConfig->m_iMinID = bEq02 ? 8 : (bEq01 ? 4 : 0);
            psConfig->m_iMaxID = bEq02 ? 0 : (bEq12 ? 6 : 2);
            psConfig->m_nuiMinDepth = bEq02 ? 3 : (bEq01 ? 2 : 1);
            psConfig->m_nuiMaxDepth = bEq02 ? 0 : (bEq12 ? 2 : 1);
        }
        else if (fP0_AX <= fP2_AX) /* fP0_AX <= fP2_AX < fP1_AX */
        {
            psConfig->m_avMinVert[0] = psPT0->m_avPoint[0];
            psConfig->m_avMinVert[1] = psPT0->m_avPoint[2];
            psConfig->m_avMaxVert[0] = psPT0->m_avPoint[1];
            psConfig->m_iMinID = bEq02 ? 5 : 0;
            psConfig->m_iMaxID = 1;
            psConfig->m_nuiMinDepth = bEq02 ? 2 : 1;
            psConfig->m_nuiMaxDepth = 1;
        }
        else /* fP2_AX < fP0_AX <= fP1_AX */
        {
            psConfig->m_avMinVert[0] = psPT0->m_avPoint[2];
            psConfig->m_avMaxVert[0] = psPT0->m_avPoint[1];
            psConfig->m_avMaxVert[1] = psPT0->m_avPoint[0];
            psConfig->m_iMinID = 2;
            psConfig->m_iMaxID = bEq01 ? 4 : 1;
            psConfig->m_nuiMinDepth = 1;
            psConfig->m_nuiMaxDepth = bEq01 ? 2 : 1;
        };
    }
    else
    {
        if (fP2_AX <= fP1_AX) /* fP2_AX < = fP1_AX < fP0_AX */
        {
            psConfig->m_avMinVert[0] = psPT0->m_avPoint[2];
            psConfig->m_avMinVert[1] = psPT0->m_avPoint[1];
            psConfig->m_avMaxVert[0] = psPT0->m_avPoint[0];
            psConfig->m_iMinID = bEq12 ? 6 : 2;
            psConfig->m_iMaxID = 0;
            psConfig->m_nuiMinDepth = bEq12 ? 2 : 1;
            psConfig->m_nuiMaxDepth = 1;
        }
        else if (fP2_AX <= fP0_AX) /* fP1_AX < fP2_AX <= fP0_AX */
        {
            psConfig->m_avMinVert[0] = psPT0->m_avPoint[1];
            psConfig->m_avMaxVert[0] = psPT0->m_avPoint[0];
            psConfig->m_avMaxVert[1] = psPT0->m_avPoint[2];
            psConfig->m_iMinID = 1;
            psConfig->m_iMaxID = bEq02 ? 5 : 0;
            psConfig->m_nuiMinDepth = 1;
            psConfig->m_nuiMaxDepth = bEq02 ? 2 : 1;
        }
        else /* fP1_AX < fP0_AX < fP2_AX */
        {
            psConfig->m_avMinVert[0] = psPT0->m_avPoint[1];
            psConfig->m_avMaxVert[0] = psPT0->m_avPoint[2];
            psConfig->m_iMinID = 1;
            psConfig->m_iMaxID = 2;
            psConfig->m_nuiMinDepth = 1;
            psConfig->m_nuiMaxDepth = 1;
        };
    };
}