Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Common - Geometry 3D - Triangle [Edge].c_inc
    »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".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/* == Common ============================================================================================================================================================ */

/* ---- V(tgGM_ET_Is_Valid) --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgBOOL V(tgGM_ET_Is_Valid)( V(CPCU_TgETRI) psET1 )
{
    if (TgTRUE != V(tgGM_PT_Is_Valid)( &psET1->m_sPT) )
    {
        return (TgFALSE);
    };

    /* Sanity Check: on the edge size. */

    if (TgTRUE != V(F_Is_Vector_Valid)(psET1->m_avEdge + 0) || TgTRUE == F(tgCM_NR0)(V(F_LSQ)(psET1->m_avEdge + 0)))
    {
        return (TgFALSE);
    };

    if (TgTRUE != V(F_Is_Vector_Valid)(psET1->m_avEdge + 1) || TgTRUE == F(tgCM_NR0)(V(F_LSQ)(psET1->m_avEdge + 1)))
    {
        return (TgFALSE);
    };

    if (TgTRUE != V(F_Is_Vector_Valid)(psET1->m_avEdge + 2) || TgTRUE == F(tgCM_NR0)(V(F_LSQ)(psET1->m_avEdge + 2)))
    {
        return (TgFALSE);
    };

    return (TgTRUE);
}


/* ---- V(tgGM_ET_Support_Point) ---------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID V(tgGM_ET_Support_Point)( V(P_TgVEC) pvRT, V(CPCU_TgETRI) psET1, V(CPCU_TgVEC) ptvDN )
{
    const TYPE                          fAx_E0 = V(F_DOT)(ptvDN, psET1->m_avEdge + 0);
    const TYPE                          fAx_E1 = -V(F_DOT)(ptvDN, psET1->m_avEdge + 2);

    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_ET_Is_Valid)(psET1) && TgTRUE == V(F_Is_Vector_Valid)(ptvDN));

    if (F(tgCM_NR0)(fAx_E0) && TgTRUE == F(tgCM_NR0)(fAx_E1))
    {
        V(C_TgVEC)                          vX0 = V(F_SUB)(psET1->m_avEdge + 0, psET1->m_avEdge + 2);
        V(C_TgVEC)                          tvX1 = V(F_MUL_SV)(F(KTgF_THIRD), &vX0);

        *pvRT = (V(F_ADD)(psET1->m_sPT.m_avPoint + 0, &tvX1));
        return;
    }

    if (!(fAx_E0 < MKL(0.0)))
    {
        if (fAx_E1 > fAx_E0)
        {
            *pvRT = (V(F_SUB)(psET1->m_sPT.m_avPoint + 0, psET1->m_avEdge + 2));
            return;
        }
        else
        {
            *pvRT = (V(F_ADD)(psET1->m_sPT.m_avPoint + 0, psET1->m_avEdge + 0));
            return;
        };
    }
    else if (!(fAx_E1 < MKL(0.0)))
    {
        *pvRT = (V(F_SUB)(psET1->m_sPT.m_avPoint + 0, psET1->m_avEdge + 2));
        return;
    };

    *pvRT = psET1->m_sPT.m_avPoint[0];
}


/* ---- V(tgGM_ET_Is_Tri_Edge_Ignored) ---------------------------------------------------------------------------------------------------------------------------------- */
/* Edge culling is used in different ways by the different systems.  Sometimes the desired approach is to have an edge included one time even if its marked to be ignored. */
/* For instance, during penetration collisions calls it is necessary to ignore an edge in determining the method of separation (normal) but in contact reduction the edge */
/* has to be considered at least once. */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgBOOL V(tgGM_ET_Is_Tri_Edge_Ignored)( V(CPCU_TgETRI) psET1, const TYPE fT0, const TYPE fT1 )
{
    if (F(tgPM_ABS)(fT1) <= F(KTgEPS))
    {   /*  Edge generated by vertex 0 and vertex 1 */
        if (psET1->m_avEdge[0].m.x != MKL(0.0))
        {
            return (psET1->m_avEdge[0].m.x <= MKL(0.0) ? TgTRUE : TgFALSE);
        }
        else if (psET1->m_avEdge[0].m.y != MKL(0.0))
        {
            return (psET1->m_avEdge[0].m.y <= MKL(0.0) ? TgTRUE : TgFALSE);
        }
        else if (psET1->m_avEdge[0].m.z != MKL(0.0))
        {
            return (psET1->m_avEdge[0].m.z <= MKL(0.0) ? TgTRUE : TgFALSE);
        };
    }
    else if (F(tgPM_ABS)(fT0) <= F(KTgEPS))
    {   /* Edge generated by vertex 0 and vertex 2 */
        if (psET1->m_avEdge[2].m.x != MKL(0.0))
        {
            return (psET1->m_avEdge[2].m.x <= MKL(0.0) ? TgTRUE : TgFALSE);
        }
        else if (psET1->m_avEdge[2].m.y != MKL(0.0))
        {
            return (psET1->m_avEdge[2].m.y <= MKL(0.0) ? TgTRUE : TgFALSE);
        }
        else if (psET1->m_avEdge[2].m.z != MKL(0.0))
        {
            return (psET1->m_avEdge[2].m.z <= MKL(0.0) ? TgTRUE : TgFALSE);
        };
    }
    else if (F(tgPM_ABS)(fT0 + fT1 - MKL(1.0)) <= F(KTgEPS))
    {   /*  Edge generated by vertex 1 and vertex 2 */
        if (psET1->m_avEdge[1].m.x != MKL(0.0))
        {
            return (psET1->m_avEdge[1].m.x <= MKL(0.0) ? TgTRUE : TgFALSE);
        }
        else if (psET1->m_avEdge[1].m.y != MKL(0.0))
        {
            return (psET1->m_avEdge[1].m.y <= MKL(0.0) ? TgTRUE : TgFALSE);
        }
        else if (psET1->m_avEdge[1].m.z != MKL(0.0))
        {
            return (psET1->m_avEdge[1].m.z <= MKL(0.0) ? TgTRUE : TgFALSE);
        };
    };

    TgERROR(TgFALSE);
    return (TgFALSE);
}


/* ---- V(tgGM_ET_Is_Tri_Edge_Ignored_Code) ----------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgBOOL V(tgGM_ET_Is_Tri_Edge_Ignored_Code)( V(CPCU_TgETRI) psET1, C_TgSINT32 iEdge )
{
    if (0 == iEdge)
    {   /*  Edge generated by vertex 0 and vertex 1 */
        if (psET1->m_avEdge[0].m.x != MKL(0.0))
        {
            return (psET1->m_avEdge[0].m.x <= MKL(0.0) ? TgTRUE : TgFALSE);
        }
        else if (psET1->m_avEdge[0].m.y != MKL(0.0))
        {
            return (psET1->m_avEdge[0].m.y <= MKL(0.0) ? TgTRUE : TgFALSE);
        }
        else if (psET1->m_avEdge[0].m.z != MKL(0.0))
        {
            return (psET1->m_avEdge[0].m.z <= MKL(0.0) ? TgTRUE : TgFALSE);
        };
    }
    else if (2 == iEdge)
    {   /* Edge generated by vertex 0 and vertex 2 */
        if (psET1->m_avEdge[1].m.x != MKL(0.0))
        {
            return (psET1->m_avEdge[1].m.x <= MKL(0.0) ? TgTRUE : TgFALSE);
        }
        else if (psET1->m_avEdge[1].m.y != MKL(0.0))
        {
            return (psET1->m_avEdge[1].m.y <= MKL(0.0) ? TgTRUE : TgFALSE);
        }
        else if (psET1->m_avEdge[1].m.z != MKL(0.0))
        {
            return (psET1->m_avEdge[1].m.z <= MKL(0.0) ? TgTRUE : TgFALSE);
        };
    }
    else if (1 == iEdge)
    {   /*  Edge generated by vertex 1 and vertex 2 */
        if (psET1->m_avEdge[2].m.x != MKL(0.0))
        {
            return (psET1->m_avEdge[2].m.x <= MKL(0.0) ? TgTRUE : TgFALSE);
        }
        else if (psET1->m_avEdge[2].m.y != MKL(0.0))
        {
            return (psET1->m_avEdge[2].m.y <= MKL(0.0) ? TgTRUE : TgFALSE);
        }
        else if (psET1->m_avEdge[2].m.z != MKL(0.0))
        {
            return (psET1->m_avEdge[2].m.z <= MKL(0.0) ? TgTRUE : TgFALSE);
        };
    };

    TgERROR(TgFALSE);
    return (TgFALSE);
}