Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Common - Geometry 3D - Triangle [Point].i_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_PT_Calc_Normal) ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PT_Calc_Normal)( V(PCU_TgPTRI) psPT0 )
{
    V(C_TgVEC)                          vX0 = V(F_SUB)( psPT0->m_avPoint + 1, psPT0->m_avPoint + 0 );
    V(C_TgVEC)                          tvX1 = V(F_SUB)( psPT0->m_avPoint + 2, psPT0->m_avPoint + 0 );

    psPT0->m_vNormal = V(F_UCX)( &vX0, &tvX1 );
}


/* ---- V(tgGM_PT_Reset) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PT_Reset)( V(PCU_TgPTRI) psPT0 )
{
    psPT0->m_avPoint[0] = V(FS_SETP)( MKL(0.0), MKL(0.0), MKL(0.0) );
    psPT0->m_avPoint[1] = V(FS_SETP)( MKL(0.0), MKL(0.0), MKL(0.0) );
    psPT0->m_avPoint[2] = V(FS_SETP)( MKL(0.0), MKL(0.0), MKL(0.0) );
    psPT0->m_vNormal = V(FS_SETV)( MKL(0.0), MKL(0.0), MKL(0.0) );
}


/* ---- V(tgGM_PT_Area) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgGM_PT_Area)( V(CPCU_TgPTRI) psPT1 )
{
    V(C_TgVEC)                          vX0 = V(F_SUB)( psPT1->m_avPoint + 1, psPT1->m_avPoint + 0 );
    V(C_TgVEC)                          tvX1 = V(F_SUB)( psPT1->m_avPoint + 2, psPT1->m_avPoint + 0 );
    V(C_TgVEC)                          tvX2 = V(F_CX)( &vX0, &tvX1 );

    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_PT_Is_Valid)(psPT1));

    return (MKL(0.5) * V(F_LEN)( &tvX2) );
}


/* ---- V(tgGM_PT_BA) --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PT_BA)( V(PCU_TgBOXAA) psBA0, V(CPCU_TgPTRI) psPT1 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_PT_Is_Valid)(psPT1));

    V(tgGM_BA_Init_PT)( psBA0, psPT1->m_avPoint + 0 );
    V(tgGM_BA_Union_PT)( psBA0, psPT1->m_avPoint + 1 );
    V(tgGM_BA_Union_PT)( psBA0, psPT1->m_avPoint + 2 );
}


/* ---- V(tgGM_PT_Sweep_BA) --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PT_Sweep_BA)( V(PCU_TgBOXAA) psBA0, V(CPCU_TgPTRI) psPT1, V(CPCU_TgVEC) pvDT )
{
    V(tgGM_PT_BA)( psBA0, psPT1 );
    V(tgGM_BA_Sweep)( psBA0, pvDT );
}


/* ---- V(tgGM_PT_Project) ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PT_Project)( PCU_TYPE ptyMin, PCU_TYPE ptyMax, V(CPCU_TgPTRI) psPT1, V(CPCU_TgVEC) pvDN )
{
    const TYPE                          fP0_AX = V(F_DOT)( pvDN, psPT1->m_avPoint + 0 );
    const TYPE                          fP1_AX = V(F_DOT)( pvDN, psPT1->m_avPoint + 1 );
    const TYPE                          fP2_AX = V(F_DOT)( pvDN, psPT1->m_avPoint + 2 );

    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_PT_Is_Valid)(psPT1) && TgTRUE == V(F_Is_Vector_Valid)(pvDN));

    *ptyMin = F(tgPM_FSEL)( fP1_AX - fP0_AX, F(tgPM_FSEL)(fP0_AX - fP2_AX, fP2_AX, fP0_AX), F(tgPM_FSEL)(fP1_AX - fP2_AX, fP2_AX, fP1_AX) );
    *ptyMax = F(tgPM_FSEL)( fP0_AX - fP1_AX, F(tgPM_FSEL)(fP2_AX - fP0_AX, fP2_AX, fP0_AX), F(tgPM_FSEL)(fP2_AX - fP1_AX, fP2_AX, fP1_AX) );
}


/* ---- V(tgGM_PT_Is_Contained) ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL V(tgGM_PT_Is_Contained)( V(CPCU_TgPTRI) psPT1, V(CPCU_TgVEC) pvS0 )
{
    /* Note: For both the point and edge triangles are bary-centric approach is used to compute containment.  This is, of course, very susceptible to floating point errors, */
    /* made more prominent as the aspect ratio of the triangle becomes extended.  Thus, if even a reasonable amount of accuracy is required for a general case triangle -  */
    /* create a space tri so that the space variation will be used (plane containment). */

    V(TgVEC)                            tvP0 = V(F_SUB)( psPT1->m_avPoint + 0, pvS0 );
    V(TgVEC)                            tvP1 = V(F_SUB)( psPT1->m_avPoint + 1, pvS0 );
    V(TgVEC)                            tvP2 = V(F_SUB)( psPT1->m_avPoint + 2, pvS0 );

    const TYPE                          fP0_P1 = V(F_DOT)( &tvP0, &tvP1 );
    const TYPE                          fP0_P2 = V(F_DOT)( &tvP0, &tvP2 );
    const TYPE                          fP1_P2 = V(F_DOT)( &tvP1, &tvP2 );

    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_PT_Is_Valid)(psPT1) && TgTRUE == V(F_Is_Point_Valid)( pvS0 ));

    return (fP1_P2*fP0_P2 >= fP0_P1*V(F_LSQ)(&tvP2) && fP0_P1*fP1_P2 >= fP0_P2*V(F_LSQ)(&tvP1) ? TgTRUE : TgFALSE);
}


/* ---- V(tgGM_PT_TX) --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PT_TX)( V(PCU_TgPTRI) psPT0, M34(CPCU_TgMAT) pxM0 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE != M34(F_NaN)(pxM0));

    psPT0->m_avPoint[0] = M34(F_TX_P)( pxM0, psPT0->m_avPoint + 0 );
    psPT0->m_avPoint[1] = M34(F_TX_P)( pxM0, psPT0->m_avPoint + 1 );
    psPT0->m_avPoint[2] = M34(F_TX_P)( pxM0, psPT0->m_avPoint + 2 );
    psPT0->m_vNormal = M34(F_TX_V)( pxM0, &psPT0->m_vNormal );
}


/* ---- V(tgGM_PT_Copy_TX) ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PT_Copy_TX)( V(PCU_TgPTRI) psPT0, V(CPCU_TgPTRI) psPT1, M34(CPCU_TgMAT) pxM0 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_PT_Is_Valid)(psPT1) && !M34(F_NaN)(pxM0));

    psPT0->m_avPoint[0] = M34(F_TX_P)( pxM0, psPT1->m_avPoint + 0 );
    psPT0->m_avPoint[1] = M34(F_TX_P)( pxM0, psPT1->m_avPoint + 1 );
    psPT0->m_avPoint[2] = M34(F_TX_P)( pxM0, psPT1->m_avPoint + 2 );
    psPT0->m_vNormal = M34(F_TX_V)( pxM0, &psPT1->m_vNormal );
}


/* ---- V(tgGM_PT_Init_PN) ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PT_Init_PN)( V(PCU_TgPTRI) psPT0, V(CPCU_TgVEC) pvS0, V(CPCU_TgVEC) pvS1, V(CPCU_TgVEC) pvS2, V(CPCU_TgVEC) pvN )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Point_Valid)( pvS0 ));
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Point_Valid)( pvS1 ));
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Point_Valid)( pvS2 ));
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Vector_Valid)( pvN ));
    TgGEOM_ASSERT_PARAM(TgTRUE == F(tgCM_NR1)(V(F_LSQ)( pvN )));

    psPT0->m_avPoint[0] = *pvS0;
    psPT0->m_avPoint[1] = *pvS1;
    psPT0->m_avPoint[2] = *pvS2;
    psPT0->m_vNormal = *pvN;
}


/* ---- V(tgGM_PT_Init_P) ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PT_Init_P)( V(PCU_TgPTRI) psPT0, V(CPCU_TgVEC) pvS0, V(CPCU_TgVEC) pvS1, V(CPCU_TgVEC) pvS2 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Point_Valid)( pvS0 ));
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Point_Valid)( pvS1 ));
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Point_Valid)( pvS2 ));

    psPT0->m_avPoint[0] = *pvS0;
    psPT0->m_avPoint[1] = *pvS1;
    psPT0->m_avPoint[2] = *pvS2;
    V(tgGM_PT_Calc_Normal)( psPT0 );
}


/* ---- V(tgGM_PT_Copy) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PT_Copy)( V(PCU_TgPTRI) psPT0, V(CPCU_TgPTRI) psPT1 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_PT_Is_Valid)( psPT1 ));

    psPT0->m_avPoint[0] = psPT1->m_avPoint[0];
    psPT0->m_avPoint[1] = psPT1->m_avPoint[1];
    psPT0->m_avPoint[2] = psPT1->m_avPoint[2];
    psPT0->m_vNormal = psPT1->m_vNormal;
}


/* ---- V(tgGM_PT_Set_Origin) ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PT_Set_Origin)( V(PCU_TgPTRI) psPT0, V(CPCU_TgVEC) pvS0 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Point_Valid)( pvS0 ));

    psPT0->m_avPoint[0] = *pvS0;
    V(tgGM_PT_Calc_Normal)( psPT0 );
}


/* ---- V(tgGM_PT_Set_Point_0) ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PT_Set_Point_0)( V(PCU_TgPTRI) psPT0, V(CPCU_TgVEC) pvS0 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Point_Valid)( pvS0 ));

    psPT0->m_avPoint[0] = *pvS0;
    V(tgGM_PT_Calc_Normal)( psPT0 );
}


/* ---- V(tgGM_PT_Set_Point_1) ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PT_Set_Point_1)( V(PCU_TgPTRI) psPT0, V(CPCU_TgVEC) pvS0 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Point_Valid)( pvS0 ));

    psPT0->m_avPoint[1] = *pvS0;
    V(tgGM_PT_Calc_Normal)( psPT0 );
}


/* ---- V(tgGM_PT_Set_Point_2) ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PT_Set_Point_2)( V(PCU_TgPTRI) psPT0, V(CPCU_TgVEC) pvS0 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Point_Valid)( pvS0 ));

    psPT0->m_avPoint[2] = *pvS0;
    V(tgGM_PT_Calc_Normal)( psPT0 );
}


/* ---- V(tgGM_PT_Query_Origin) ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(CP_TgVEC) V(tgGM_PT_Query_Origin)( V(CPCU_TgPTRI) psPT1 )
{
    return (psPT1->m_avPoint + 0);
}


/* ---- V(tgGM_PT_Query_Normal) ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(CP_TgVEC) V(tgGM_PT_Query_Normal)( V(CPCU_TgPTRI) psPT1 )
{
    return (&psPT1->m_vNormal);
}


/* ---- V(tgGM_PT_Query_Point_0) ---------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(CP_TgVEC) V(tgGM_PT_Query_Point_0)( V(CPCU_TgPTRI) psPT1 )
{
    return (psPT1->m_avPoint + 0);
}


/* ---- V(tgGM_PT_Query_Point_1) ---------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(CP_TgVEC) V(tgGM_PT_Query_Point_1)( V(CPCU_TgPTRI) psPT1 )
{
    return (psPT1->m_avPoint + 1);
}


/* ---- V(tgGM_PT_Query_Point_2) ---------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(CP_TgVEC) V(tgGM_PT_Query_Point_2)( V(CPCU_TgPTRI) psPT1 )
{
    return (psPT1->m_avPoint + 2);
}


/* ---- V(tgGM_PT_Query_Point) ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(CP_TgVEC) V(tgGM_PT_Query_Point)( V(CPCU_TgPTRI) psPT1, C_TgSINT32 iIndex )
{
    TgGEOM_ASSERT_PARAM(iIndex >= 0 && iIndex <= 2);
    return (psPT1->m_avPoint + iIndex);
}


#if defined(TgCOMPILE_NATIVE_VECTOR)

/* ---- V(tgGM_PT_M_TX) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PT_M_TX)( V(PCU_TgPTRI) psPT0, M34(CPCU_TgMAT) pxM0 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE != M34(F_NaN)( pxM0 ));

    psPT0->m_avPoint[0].m_mData = M34(M_TX_P)( pxM0, psPT0->m_avPoint[0].m_mData );
    psPT0->m_avPoint[1].m_mData = M34(M_TX_P)( pxM0, psPT0->m_avPoint[1].m_mData );
    psPT0->m_avPoint[2].m_mData = M34(M_TX_P)( pxM0, psPT0->m_avPoint[2].m_mData );
    psPT0->m_vNormal.m_mData = M34(M_TX_V)(  pxM0, psPT0->m_vNormal.m_mData );
}


/* ---- V(tgGM_PT_Copy_M_TX) -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PT_Copy_M_TX)( V(PCU_TgPTRI) psPT0, V(CPCU_TgPTRI) psPT1, M34(CPCU_TgMAT) pxM0 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_PT_Is_Valid)( psPT1 ));
    TgGEOM_ASSERT_PARAM(TgTRUE != M34(F_NaN)( pxM0 ));

    psPT0->m_avPoint[0].m_mData = M34(M_TX_P)( pxM0, psPT1->m_avPoint[0].m_mData );
    psPT0->m_avPoint[1].m_mData = M34(M_TX_P)( pxM0, psPT1->m_avPoint[1].m_mData );
    psPT0->m_avPoint[2].m_mData = M34(M_TX_P)( pxM0, psPT1->m_avPoint[2].m_mData );
    psPT0->m_vNormal.m_mData = M34(M_TX_V)( pxM0, psPT1->m_vNormal.m_mData );
}

/*# defined(TgCOMPILE_NATIVE_VECTOR) */
#endif