Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Common - Geometry 3D - Disk.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_DK_Reset) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_DK_Reset)( V(PCU_TgDISK) psDK0 )
{
    psDK0->m.m.vU = V(FS_SETV)( MKL(0.0), MKL(0.0), MKL(0.0) );
    psDK0->m.m.vNormal = V(FS_SETV)( MKL(0.0), MKL(0.0), MKL(0.0) );
    psDK0->m.m.vV = V(FS_SETV)( MKL(0.0), MKL(0.0), MKL(0.0) );
    psDK0->m.m.vOrigin = V(FS_SETP)( MKL(0.0), MKL(0.0), MKL(0.0) );
    psDK0->m_fRadius = MKL(0.0);
    psDK0->m_fRadiusSq = MKL(0.0);
}


/* ---- V(tgGM_DK_Area) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgGM_DK_Area)( V(CPCU_TgDISK) psDK1 )
{
    return (F(KTgF_PI)*psDK1->m_fRadiusSq);
}


/* ---- V(tgGM_DK_Sweep_BA) --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_DK_Sweep_BA)( V(PCU_TgBOXAA) psBA0, V(CPCU_TgDISK) psDK1, V(CPCU_TgVEC) pvDT )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Vector_Valid)(pvDT));

    V(tgGM_DK_BA)( psBA0, psDK1 );
    V(tgGM_BA_Sweep)( psBA0, pvDT );
}


/* ---- V(tgGM_DK_Is_Contained) ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL V(tgGM_DK_Is_Contained)( V(CPCU_TgDISK) psDK1, V(CPCU_TgVEC) pvS0 )
{
    V(C_TgVEC)                          vDS = V(F_SUB)( pvS0, &psDK1->m.m.vOrigin );
    const TYPE                          fDS_E0 = V(F_DOT)( &vDS, &psDK1->m.m.vU );
    const TYPE                          fDS_E1 = V(F_DOT)( &vDS, &psDK1->m.m.vV );

    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_DK_Is_Valid)(psDK1) && TgTRUE == V(F_Is_Point_Valid)( pvS0 ));

    return (fDS_E0*fDS_E0 + fDS_E1*fDS_E1 < psDK1->m_fRadiusSq ? TgTRUE : TgFALSE);
}


/* ---- V(tgGM_DK_TX) --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_DK_TX)( V(PCU_TgDISK) psDK0, M34(CPCU_TgMAT) pxM0 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE != M34(F_NaN)(pxM0));

    psDK0->m.m.vU = M34(F_TX_V)( pxM0, &psDK0->m.m.vU );
    psDK0->m.m.vNormal = M34(F_TX_V)( pxM0, &psDK0->m.m.vNormal );
    psDK0->m.m.vV = M34(F_TX_V)( pxM0, &psDK0->m.m.vV );
    psDK0->m.m.vOrigin = M34(F_TX_P)( pxM0, &psDK0->m.m.vOrigin );
}


/* ---- V(tgGM_DK_Copy_TX) ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_DK_Copy_TX)( V(PCU_TgDISK) psDK0, V(CPCU_TgDISK) psDK1, M34(CPCU_TgMAT) pxM0 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_DK_Is_Valid)(psDK1) && !M34(F_NaN)(pxM0));

    psDK0->m.m.vU = M34(F_TX_V)( pxM0, &psDK1->m.m.vU );
    psDK0->m.m.vNormal = M34(F_TX_V)( pxM0, &psDK1->m.m.vNormal );
    psDK0->m.m.vV = M34(F_TX_V)( pxM0, &psDK1->m.m.vV );
    psDK0->m.m.vOrigin = M34(F_TX_P)( pxM0, &psDK1->m.m.vOrigin );
    psDK0->m_fRadius = psDK1->m_fRadius;
    psDK0->m_fRadiusSq = psDK1->m_fRadiusSq;
}


/* ---- V(tgGM_DK_Init) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_DK_Init)( V(PCU_TgDISK) psDK0, V(CPCU_TgVEC) pvU, V(CPCU_TgVEC) pvNM, V(CPCU_TgVEC) pvV, V(CPCU_TgVEC) pvOG, const TYPE fRadius )
{
    V(tgGM_DK_Set_U)( psDK0, pvU );
    V(tgGM_DK_Set_Normal)( psDK0, pvNM );
    V(tgGM_DK_Set_V)( psDK0, pvV );
    V(tgGM_DK_Set_Origin)( psDK0, pvOG );
    V(tgGM_DK_Set_Radius)( psDK0, fRadius );
}


/* ---- V(tgGM_DK_Init_3D) ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_DK_Init_3D)( V(PCU_TgDISK) psDK0, M34(CPCU_TgMAT) pxM0, const TYPE fRadius )
{
    V(tgGM_DK_Set_3D)( psDK0, pxM0 );
    V(tgGM_DK_Set_Radius)( psDK0, fRadius );
}


/* ---- V(tgGM_DK_Copy) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_DK_Copy)( V(PCU_TgDISK) psDK0, V(CPCU_TgDISK) psDK1 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_DK_Is_Valid)(psDK1));

    psDK0->m.m.vU = psDK1->m.m.vU;
    psDK0->m.m.vNormal = psDK1->m.m.vNormal;
    psDK0->m.m.vV = psDK1->m.m.vV;
    psDK0->m.m.vOrigin = psDK1->m.m.vOrigin;
    psDK0->m_fRadius = psDK1->m_fRadius;
    psDK0->m_fRadiusSq = psDK1->m_fRadiusSq;
}


/* ---- V(tgGM_DK_Set_Origin) ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_DK_Set_Origin)( V(PCU_TgDISK) psDK0, V(CPCU_TgVEC) pvS0 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Point_Valid)( pvS0 ));
    psDK0->m.m.vOrigin = *pvS0;
}


/* ---- V(tgGM_DK_Set_Axes_Unit) ---------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_DK_Set_Axes_Unit)( V(PCU_TgDISK) psDK0, M34(CPCU_TgMAT) pxM0 )
{
    V(C_TgVEC)                          vS0 = psDK0->m.avData[3];

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

    M34(F_TR)(&psDK0->m.xData, pxM0);

    psDK0->m.avData[3] = vS0;

    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Vector_Valid)(psDK0->m.avData + 0) && TgTRUE == F(tgCM_NR1)(V(F_LSQ)(psDK0->m.avData + 0)));
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Vector_Valid)(psDK0->m.avData + 1) && TgTRUE == F(tgCM_NR1)(V(F_LSQ)(psDK0->m.avData + 1)));
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Vector_Valid)(psDK0->m.avData + 2) && TgTRUE == F(tgCM_NR1)(V(F_LSQ)(psDK0->m.avData + 2)));
}


/* ---- V(tgGM_DK_Set_U) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_DK_Set_U)( V(PCU_TgDISK) psDK0, V(CPCU_TgVEC) pvU )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Vector_Valid)(pvU) && TgTRUE == F(tgCM_NR1)(V(F_LSQ)(pvU)));
    psDK0->m.m.vU = *pvU;
}


/* ---- V(tgGM_DK_Set_Normal) ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_DK_Set_Normal)( V(PCU_TgDISK) psDK0, V(CPCU_TgVEC) pvN )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Vector_Valid)(pvN) && TgTRUE == F(tgCM_NR1)(V(F_LSQ)(pvN)));
    psDK0->m.m.vNormal = *pvN;
}


/* ---- V(tgGM_DK_Set_V) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_DK_Set_V)( V(PCU_TgDISK) psDK0, V(CPCU_TgVEC) pvV )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Vector_Valid)(pvV) && TgTRUE == F(tgCM_NR1)(V(F_LSQ)(pvV)));
    psDK0->m.m.vV = *pvV;
}


/* ---- V(tgGM_DK_Set_3D) ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_DK_Set_3D)( V(PCU_TgDISK) psDK0, M34(CPCU_TgMAT) pxM0 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE != M34(F_NaN)(pxM0));

    M34(F_TR)(&psDK0->m.xData, pxM0);

    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Vector_Valid)(psDK0->m.avData + 0) && TgTRUE == F(tgCM_NR1)(V(F_LSQ)(psDK0->m.avData + 0)));
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Vector_Valid)(psDK0->m.avData + 1) && TgTRUE == F(tgCM_NR1)(V(F_LSQ)(psDK0->m.avData + 1)));
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Vector_Valid)(psDK0->m.avData + 2) && TgTRUE == F(tgCM_NR1)(V(F_LSQ)(psDK0->m.avData + 2)));
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Point_Valid)(psDK0->m.avData + 3));
}


/* ---- V(tgGM_DK_Set_Radius) ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_DK_Set_Radius)( V(PCU_TgDISK) psDK0, const TYPE fRadius )
{
    TgGEOM_ASSERT_PARAM(TgTRUE != F(tgPM_NAN)(fRadius) && fRadius > MKL(0.0));

    psDK0->m_fRadius = fRadius;
    psDK0->m_fRadiusSq = fRadius*fRadius;
}


/* ---- V(tgGM_DK_Query_Origin) ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(CP_TgVEC) V(tgGM_DK_Query_Origin)( V(CPCU_TgDISK) psDK1 )
{
    return (&psDK1->m.m.vOrigin);
}


/* ---- V(tgGM_DK_Query_U) ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(CP_TgVEC) V(tgGM_DK_Query_U)( V(CPCU_TgDISK) psDK1 )
{
    return (&psDK1->m.m.vU);
}


/* ---- V(tgGM_DK_Query_Normal) ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(CP_TgVEC) V(tgGM_DK_Query_Normal)( V(CPCU_TgDISK) psDK1 )
{
    return (&psDK1->m.m.vNormal);
}


/* ---- V(tgGM_DK_Query_V) ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(CP_TgVEC) V(tgGM_DK_Query_V)( V(CPCU_TgDISK) psDK1 )
{
    return (&psDK1->m.m.vV);
}


/* ---- V(tgGM_DK_Query_Radius) ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgGM_DK_Query_Radius)( V(CPCU_TgDISK) psDK1 )
{
    return (psDK1->m_fRadius);
}


/* ---- V(tgGM_DK_Query_Radius_Sq) -------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgGM_DK_Query_Radius_Sq)( V(CPCU_TgDISK) psDK1 )
{
    return (psDK1->m_fRadiusSq);
}


#if defined(TgCOMPILE_NATIVE_VECTOR)

/* ---- V(tgGM_DK_M_TX) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_DK_M_TX)( V(PCU_TgDISK) psDK0, M34(CPCU_TgMAT) pxM0 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE != M34(F_NaN)( pxM0 ));

    psDK0->m.m.vOrigin.m_mData = M34(M_TX_P)( pxM0, psDK0->m.m.vOrigin.m_mData );
    psDK0->m.m.vU.m_mData = M34(M_TX_V)( pxM0, psDK0->m.m.vU.m_mData );
    psDK0->m.m.vNormal.m_mData = M34(M_TX_V)( pxM0, psDK0->m.m.vNormal.m_mData );
    psDK0->m.m.vV.m_mData = M34(M_TX_V)( pxM0, psDK0->m.m.vV.m_mData );
}


/* ---- V(tgGM_DK_Copy_M_TX) -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_DK_Copy_M_TX)( V(PCU_TgDISK) psDK0, V(CPCU_TgDISK) psDK1, M34(CPCU_TgMAT) pxM0 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_DK_Is_Valid)( psDK1 ) && TgTRUE != M34(F_NaN)( pxM0 ));

    psDK0->m.m.vU.m_mData = M34(M_TX_V)( pxM0, psDK1->m.m.vU.m_mData );
    psDK0->m.m.vNormal.m_mData = M34(M_TX_V)( pxM0, psDK1->m.m.vNormal.m_mData );
    psDK0->m.m.vV.m_mData = M34(M_TX_V)( pxM0, psDK1->m.m.vV.m_mData );
    psDK0->m.m.vOrigin.m_mData = M34(M_TX_P)( pxM0, psDK1->m.m.vOrigin.m_mData );
    psDK0->m_fRadius = psDK1->m_fRadius;
    psDK0->m_fRadiusSq = psDK1->m_fRadiusSq;
}

/*# defined(TgCOMPILE_NATIVE_VECTOR) */
#endif