Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Common - Geometry 3D - Plane.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_PN_Negate) ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PN_Negate)( V(PCU_TgPLANE) psPN0 )
{
    psPN0->m_vPlnEqN = V(F_NEG)( &psPN0->m_vPlnEqN );
    psPN0->m_vNormal = V(F_NEG)( &psPN0->m_vNormal );
    psPN0->m_fD = -psPN0->m_fD;
}


/* ---- V(tgGM_PN_Reset) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PN_Reset)( V(PCU_TgPLANE) psPN0 )
{
    psPN0->m_vPlnEqN = V(FS_SET)( MKL(0.0), MKL(0.0), MKL(0.0), MKL(0.0) );
    psPN0->m_vNormal = V(FS_SETV)( MKL(0.0), MKL(0.0), MKL(0.0) );
    psPN0->m_fD = MKL(0.0);
}


/* ---- V(tgGM_PN_Is_Valid) --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL V(tgGM_PN_Is_Valid)( V(CPCU_TgPLANE) psPN1 )
{
    if (F(tgPM_NAN)(psPN1->m_fD) || TgTRUE == V(F_NaN)(&psPN1->m_vNormal) || TgTRUE != F(tgCM_NR1)(V(F_LSQ)(&psPN1->m_vNormal)))
    {
        return (TgFALSE);
    };

    return (TgTRUE);
}


/* ---- V(tgGM_PN_Is_Contained) ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL V(tgGM_PN_Is_Contained)( V(CPCU_TgPLANE) psPN0, V(CPCU_TgVEC) pvS0 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_PN_Is_Valid)(psPN0) && TgTRUE != V(F_NaN)(pvS0));
    return (V(F_DOT3)( pvS0, &psPN0->m_vNormal) <= psPN0->m_fD ? TgTRUE : TgFALSE);
}


/* ---- V(tgGM_PN_TX) --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PN_TX)( V(PCU_TgPLANE) psPN0, M34(CPCU_TgMAT) pxM0 )
{
    V(C_TgVEC)                          tvK = V(F_MUL_VS)( &psPN0->m_vNormal, -psPN0->m_fD );
    V(C_TgVEC)                          tvO = M34(F_TX_P)( pxM0, &tvK );
    V(C_TgVEC)                          tvN = M34(F_TX_V)( pxM0, &psPN0->m_vNormal );
    const TYPE                          fK = -V(F_DOT)( &tvN, &tvO );

    TgGEOM_ASSERT_PARAM(TgTRUE != M34(F_NaN)(pxM0));

    psPN0->m_vPlnEqN = V(FS_SET)( tvN.m.x, tvN.m.y, tvN.m.z, fK );
    psPN0->m_vNormal = tvN;
    psPN0->m_fD = fK;
}


/* ---- V(tgGM_PN_Copy_TX) ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PN_Copy_TX)( V(PCU_TgPLANE) psPN0, V(CPCU_TgPLANE) psPN1, M34(CPCU_TgMAT) pxM0 )
{
    V(C_TgVEC)                          tvK = V(F_MUL_VS)( &psPN1->m_vNormal, -psPN1->m_fD );
    V(C_TgVEC)                          tvO = M34(F_TX_P)( pxM0, &tvK );
    V(C_TgVEC)                          tvN = M34(F_TX_V)( pxM0, &psPN1->m_vNormal );
    const TYPE                          fK = -V(F_DOT)( &tvN, &tvO );

    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_PN_Is_Valid)(psPN1) && !M34(F_NaN)(pxM0));

    psPN0->m_vPlnEqN = V(FS_SET)( tvN.m.x, tvN.m.y, tvN.m.z, fK );
    psPN0->m_vNormal = tvN;
    psPN0->m_fD = fK;
}


/* ---- V(tgGM_PN_Init_ND) ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PN_Init_ND)( V(PCU_TgPLANE) psPN0, V(CPCU_TgVEC) pvN, const TYPE fK )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Vector_Valid)(pvN) && TgTRUE == F(tgCM_NR1)(V(F_LSQ)(pvN)) && TgTRUE != F(tgPM_NAN)(fK));

    psPN0->m_vPlnEqN = V(FS_SET)( pvN->m.x, pvN->m.y, pvN->m.z, fK );
    psPN0->m_vNormal = *pvN;
    psPN0->m_fD = fK;
}


/* ---- V(tgGM_PN_Init_NP) ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PN_Init_NP)( V(PCU_TgPLANE) psPN0, V(CPCU_TgVEC) pvN, V(CPCU_TgVEC) pvS )
{
    const TYPE                          fK = -V(F_DOT)( pvN, pvS );

    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Vector_Valid)(pvN) && TgTRUE == F(tgCM_NR1)(V(F_LSQ)(pvN)) && TgTRUE == V(F_Is_Point_Valid)(pvS));

    psPN0->m_vPlnEqN = V(FS_SET)( pvN->m.x, pvN->m.y, pvN->m.z, fK );
    psPN0->m_vNormal = *pvN;
    psPN0->m_fD = fK;
}


/* ---- V(tgGM_PN_Copy) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PN_Copy)( V(PCU_TgPLANE) psPN0, V(CPCU_TgPLANE) psPN1 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_PN_Is_Valid)(psPN1));

    psPN0->m_vPlnEqN = psPN1->m_vPlnEqN;
    psPN0->m_vNormal = psPN1->m_vNormal;
    psPN0->m_fD = psPN1->m_fD;
}


/* ---- V(tgGM_PN_Set_PlnEqN) ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PN_Set_PlnEqN)( V(PCU_TgPLANE) psPN0, V(CPCU_TgVEC) pvPlnEqN )
{
    TgGEOM_ASSERT_PARAM(TgTRUE != V(F_NaN)(pvPlnEqN));

    psPN0->m_vPlnEqN = *pvPlnEqN;
    psPN0->m_vNormal.m.x = pvPlnEqN->m.x;
    psPN0->m_vNormal.m.y = pvPlnEqN->m.y;
    psPN0->m_vNormal.m.z = pvPlnEqN->m.z;
    psPN0->m_fD = pvPlnEqN->m.w;
}


/* ---- V(tgGM_PN_Set_Normal) ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PN_Set_Normal)( V(PCU_TgPLANE) psPN0, V(CPCU_TgVEC) pvN )
{
    V(TgVEC)                            tvK = V(F_MUL_VS)( &psPN0->m_vNormal, -psPN0->m_fD );
    const TYPE                          fK = -V(F_DOT)( pvN, &tvK );

    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Vector_Valid)(pvN) && TgTRUE == F(tgCM_NR1)(V(F_LSQ)(pvN)));

    psPN0->m_vPlnEqN = V(FS_SET)( pvN->m.x, pvN->m.y, pvN->m.z, fK );
    psPN0->m_vNormal = *pvN;
    psPN0->m_fD = fK;
}


/* ---- V(tgGM_PN_Set_Origin) ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PN_Set_Origin)( V(PCU_TgPLANE) psPN0, V(CPCU_TgVEC) pvS )
{
    const TYPE                          fK = -V(F_DOT)( &psPN0->m_vNormal, pvS );

    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Point_Valid)(pvS));

    psPN0->m_vPlnEqN.m.w = fK;
    psPN0->m_fD = fK;
}


/* ---- V(tgGM_PN_Set_Constant) ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PN_Set_Constant)( V(PCU_TgPLANE) psPN0, const TYPE fK )
{
    TgGEOM_ASSERT_PARAM(TgTRUE != F(tgPM_NAN)(fK));

    psPN0->m_vPlnEqN.m.w = fK;
    psPN0->m_fD = fK;
}


/* ---- V(tgGM_PN_Query_PlnEqN) ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(CP_TgVEC) V(tgGM_PN_Query_PlnEqN)( V(CPCU_TgPLANE) psPN0 )
{
    return (&psPN0->m_vPlnEqN);
}


/* ---- V(tgGM_PN_Query_Normal) ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(CP_TgVEC) V(tgGM_PN_Query_Normal)( V(CPCU_TgPLANE) psPN0 )
{
    return (&psPN0->m_vNormal);

}


/* ---- V(tgGM_PN_Query_Constant) --------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgGM_PN_Query_Constant)( V(CPCU_TgPLANE) psPN0 )
{
    return (psPN0->m_fD);

}


/* ---- V(tgGM_F_DistSq_PN_VT) ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgGM_F_DistSq_PN_VT)( V(CPCU_TgPLANE) psPN1, V(CPCU_TgVEC) pvS0 )
{
    const TYPE fDist = V(F_DOT3)(&psPN1->m_vNormal, pvS0) + psPN1->m_fD;
    return (F(tgPM_FSEL)( fDist, fDist*fDist, -F(KTgMAX)) );
}


/* ---- V(tgGM_F_Dist_PN_VT) -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgGM_F_Dist_PN_VT)( V(CPCU_TgPLANE) psPN1, V(CPCU_TgVEC) pvS0 )
{
    const TYPE fDist = V(F_DOT3)(&psPN1->m_vNormal, pvS0) + psPN1->m_fD;
    return (F(tgPM_FSEL)( fDist, fDist, -F(KTgMAX)) );
}


/* ---- V(tgGM_F_Sign_Dist_PN_VT) --------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgGM_F_Sign_Dist_PN_VT)( V(CPCU_TgPLANE) psPN1, V(CPCU_TgVEC) pvS0 )
{
    return (V(F_DOT3)( &psPN1->m_vNormal, pvS0) + psPN1->m_fD );
}


/* ---- V(tgGM_F_Sign_Closest_PN_VT) ------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgGM_F_Sign_Closest_PN_VT)( V(PCU_TgVEC) pvS0, V(CPCU_TgPLANE) psPN1, V(CPCU_TgVEC) pvS1 )
{
    const TYPE fDist = V(F_DOT3)(&psPN1->m_vNormal, pvS0) + psPN1->m_fD;
    *pvS0 = V(F_NMS_SVV)( fDist, &psPN1->m_vNormal, pvS1 );
    return (fDist);
}


#if defined(TgCOMPILE_NATIVE_VECTOR)

/* ---- V(tgGM_PN_M_TX) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PN_M_TX)( V(PCU_TgPLANE) psPN0, M34(CPCU_TgMAT) pxM0 )
{
    V(TgVEC_M)                          vX1 = V(M_SPW)( psPN0->m_vPlnEqN.m_mData );
    V(TgVEC_M)                          vX2 = V(M_NEG)( vX1 );
    V(TgVEC_M)                          vX3 = V(M_MUL)( vX2, psPN0->m_vNormal.m_mData );
    V(TgVEC_M)                          vX4 = M34(M_TX_P)( pxM0, vX3 );
    V(TgVEC_M)                          vX5 = M34(M_TX_V)( pxM0, psPN0->m_vNormal.m_mData );
    V(TgVEC_M)                          vX6 = V(M_DOT)( vX4, vX5 );

    TgGEOM_ASSERT_PARAM(TgTRUE != M34( F_NaN )(pxM0));

    psPN0->m_vPlnEqN.m_mData = V(M_SEL)( vX4, vX6, KTgV_000F.m_f32_v04.m_mData );
    psPN0->m_vNormal.m_mData = vX5;
    psPN0->m_fD = psPN0->m_vPlnEqN.m_aData[3];
}


/* ---- V(tgGM_PN_Copy_M_TX) -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_PN_Copy_M_TX)( V(PCU_TgPLANE) psPN0, V(CPCU_TgPLANE) psPN1, M34(CPCU_TgMAT) pxM0 )
{
    V(TgVEC_M)                          vX1 = V(M_SPW)( psPN1->m_vPlnEqN.m_mData );
    V(TgVEC_M)                          vX2 = V(M_NEG)( vX1 );
    V(TgVEC_M)                          vX3 = V(M_MUL)( vX2, psPN1->m_vNormal.m_mData );
    V(TgVEC_M)                          vX4 = M34(M_TX_P)( pxM0, vX3 );
    V(TgVEC_M)                          vX5 = M34(M_TX_V)( pxM0, psPN1->m_vNormal.m_mData );
    V(TgVEC_M)                          vX6 = V(M_DOT)( vX4, vX5 );

    TgGEOM_ASSERT_PARAM(TgTRUE != M34( F_NaN )(pxM0));

    psPN0->m_vPlnEqN.m_mData = V(M_SEL)( vX4, vX6, KTgV_000F.m_f32_v04.m_mData );
    psPN0->m_vNormal.m_mData = vX5;
    psPN0->m_fD = psPN0->m_vPlnEqN.m_aData[3];
}

/*# defined(TgCOMPILE_NATIVE_VECTOR) */
#endif