Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Common - Geometry 3D - Mesh [AABB].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_MA_Free_Internal) ---------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_MA_Free_Internal)( V(PCU_TgMESH_BA) psMA0 )
{
    if (psMA0->m_pvVert_DT)
    {
        TgFREE_POOL( psMA0->m_pvVert_DT );
        psMA0->m_pvVert_DT = nullptr;
    };
    if (psMA0->m_psBA)
    {
        TgFREE_POOL( psMA0->m_psBA );
        psMA0->m_psBA = nullptr;
    };
    if (psMA0->m_puiFlags)
    {
        TgFREE_POOL( psMA0->m_puiFlags );
        psMA0->m_puiFlags = nullptr;
    };
}


/* ---- V(tgGM_MA_Reset) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_MA_Reset)( V(PCU_TgMESH_BA) psMA0 )
{
    V(tgGM_MS_Reset)( &psMA0->m_sMS );
    V(tgGM_MA_Free_Internal)( psMA0 );
    V(tgGM_DT_Reset)( &psMA0->m_sDT );

    psMA0->m_vCG[0] = V(FS_SETP)( MKL(0.0), MKL(0.0), MKL(0.0) );
    psMA0->m_vCG[1] = V(FS_SETP)( MKL(0.0), MKL(0.0), MKL(0.0) );
    psMA0->m_enSweep = ETgSWEEP_STATIC;
}


/* ---- V(tgGM_MA_Support_Point) ---------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) V(tgGM_MA_Support_Point)( V(CPCU_TgMESH_BA) psMA1, V(CPCU_TgVEC) pvDN )
{
    return (V(tgGM_MS_Support_Point)( &psMA1->m_sMS, pvDN) );
}


/* ---- V(tgGM_MA_Volume) ----------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgGM_MA_Volume)( V(CPCU_TgMESH_BA) psMA1 )
{
    return (V(tgGM_MS_Volume)( &psMA1->m_sMS) );
}


/* ---- V(tgGM_MA_Area) ----------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgGM_MA_Area)( V(CPCU_TgMESH_BA) psMA1 )
{
    return (V(tgGM_MS_Area)( &psMA1->m_sMS) );
}


/* ---- V(tgGM_MA_BA) --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_MA_BA)( V(PCU_TgBOXAA) psBA0, V(CPCU_TgMESH_BA) psMA1 )
{
    V(tgGM_MS_BA)( psBA0, &psMA1->m_sMS );
}


/* ---- V(tgGM_MA_Sweep_BA) --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_MA_Sweep_BA)( V(PCU_TgBOXAA) psBA0, V(CPCU_TgMESH_BA) psMA1, V(CPCU_TgVEC) pvDT )
{
    V(tgGM_MA_BA)( psBA0, psMA1 );
    V(tgGM_BA_Sweep)( psBA0, pvDT );
}


/* ---- V(tgGM_MA_Project) ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_MA_Project)( PCU_TYPE ptyMin, PCU_TYPE ptyMax, V(CPCU_TgMESH_BA) psMA1, V(CPCU_TgVEC) pvDN )
{
    V(tgGM_MS_Project)( ptyMin, ptyMax, &psMA1->m_sMS, pvDN );
}


/* ---- V(tgGM_MA_Is_Contained) ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL V(tgGM_MA_Is_Contained)( V(CPCU_TgMESH_BA) psMA1, V(CPCU_TgVEC) pvS0 )
{
    return (V(tgGM_MS_Is_Contained)( &psMA1->m_sMS, pvS0 ));
}


/* ---- V(tgGM_MA_Init_MS_TX) ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_MA_Init_MS_TX)( V(PCU_TgMESH_BA) psMA0, V(CPCU_TgMESH_SIMPLE) psMS, M34(CPCU_TgMAT) pxM0 )
{
    C_TgUINT32                          nuiVert = psMS->m_nuiVert;
    C_TgUINT32                          nuiIndx = psMS->m_nuiIndx;
    C_TgUINT32                          nuiFace = (0 == psMS->m_puiIndx_List ? nuiVert : nuiIndx) / 3;

    V(tgGM_MA_Init)( psMA0, nuiVert, nuiIndx, ETgSWEEP_STATIC );
    V(tgGM_MS_Copy_TX)( &psMA0->m_sMS, psMS, pxM0 );
    V(tgGM_DT_Reset)( &psMA0->m_sDT );

    V(tgGM_MA_Update_Face_CG_BA)( psMA0 );
    memset( psMA0->m_puiFlags, 0xFF, nuiFace*sizeof( TgUINT32 ) );
    psMA0->m_enSweep = ETgSWEEP_STATIC;
}


/* ---- V(tgGM_MA_Init_MS_TX_TL) ---------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_MA_Init_MS_TX_TL)( V(PCU_TgMESH_BA) psMA0, V(CPCU_TgMESH_SIMPLE) psMS, M34(CPCU_TgMAT) pxM0, V(CPCU_TgVEC) pvDT )
{
    C_TgUINT32                          nuiVert = psMS->m_nuiVert;
    C_TgUINT32                          nuiIndx = psMS->m_nuiIndx;
    C_TgUINT32                          nuiFace = (0 == psMS->m_puiIndx_List ? nuiVert : nuiIndx) / 3;

    V(tgGM_MA_Init)( psMA0, nuiVert, nuiIndx, ETgSWEEP_LINEAR );
    V(tgGM_MS_Copy_TX)( &psMA0->m_sMS, psMS, pxM0 );
    V(tgGM_DT_Set)( &psMA0->m_sDT, pvDT );

    V(tgGM_MA_Update_Face_CG_BA)( psMA0 );
    memset( psMA0->m_puiFlags, 0xFF, nuiFace*sizeof( TgUINT32 ) );
    psMA0->m_enSweep = ETgSWEEP_LINEAR;
}


/* ---- V(tgGM_MA_Init_MS_TX_TX) ---------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_MA_Init_MS_TX_TX)( V(PCU_TgMESH_BA) psMA0, V(CPCU_TgMESH_SIMPLE) psMS, M34(CPCU_TgMAT) pxM0, M34(CPCU_TgMAT) pxM1 )
{
    C_TgUINT32                          nuiVert = psMS->m_nuiVert;
    C_TgUINT32                          nuiIndx = psMS->m_nuiIndx;
    C_TgUINT32                          nuiFace = (0 == psMS->m_puiIndx_List ? nuiVert : nuiIndx) / 3;
    TgUINT32                            uiIndex;

    V(tgGM_MA_Init)( psMA0, nuiVert, nuiIndx, ETgSWEEP_ROTATIONAL );
    V(tgGM_MS_Copy_TX)( &psMA0->m_sMS, psMS, pxM0 );
    V(tgGM_DT_Reset)( &psMA0->m_sDT );

    for (uiIndex = 0; uiIndex < psMS->m_nuiVert; ++uiIndex)
    {
        V(C_TgVEC)                          vX0 = M34(F_TX_P)( pxM1, psMS->m_pvVert_List + uiIndex );

        psMA0->m_pvVert_DT[uiIndex] = V(F_SUB)( &vX0, psMA0->m_sMS.m_pvVert_List + uiIndex );
    };

    V(tgGM_MA_Update_Face_CG_BA)( psMA0 );
    memset( psMA0->m_puiFlags, 0xFF, nuiFace*sizeof( TgUINT32 ) );
    psMA0->m_enSweep = ETgSWEEP_ROTATIONAL;
}


/* ---- V(tgGM_MS_MA_Init) ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_MS_MA_Init)( V(PCU_TgMESH_BA) psMA0, V(CPCU_TgMESH_SIMPLE) psMS )
{
    C_TgUINT32                          nuiVert = psMS->m_nuiVert;
    C_TgUINT32                          nuiIndx = psMS->m_nuiIndx;
    C_TgUINT32                          nuiFace = (0 == psMS->m_puiIndx_List ? nuiVert : nuiIndx) / 3;

    V(tgGM_MA_Init)( psMA0, nuiVert, nuiIndx, ETgSWEEP_STATIC );
    V(tgGM_MS_Copy)( &psMA0->m_sMS, psMS );
    V(tgGM_DT_Reset)( &psMA0->m_sDT );

    V(tgGM_MA_Update_Face_CG_BA)( psMA0 );
    memset( psMA0->m_puiFlags, 0xFF, nuiFace*sizeof( TgUINT32 ) );
    psMA0->m_enSweep = ETgSWEEP_STATIC;
}


/* ---- V(tgGM_MA_Copy) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_MA_Copy)( V(PCU_TgMESH_BA) psMA0, V(CPCU_TgMESH_BA) psMA1 )
{
    C_TgUINT32                          nuiVert = psMA1->m_sMS.m_nuiVert;
    C_TgUINT32                          nuiIndx = psMA1->m_sMS.m_nuiIndx;
    C_TgUINT32                          nuiFace = (0 == psMA1->m_sMS.m_puiIndx_List ? nuiVert : nuiIndx) / 3;

    V(tgGM_MA_Init)( psMA0, nuiVert, nuiIndx, psMA1->m_enSweep );
    V(tgGM_MS_Copy)( &psMA0->m_sMS, &psMA1->m_sMS );
    psMA0->m_enSweep = psMA1->m_enSweep;

    switch (psMA0->m_enSweep)
    {
        case ETgSWEEP_ROTATIONAL:
            memcpy( psMA0->m_pvVert_DT, psMA1->m_pvVert_DT, nuiVert*sizeof( psMA1->m_pvVert_DT[0] ) );
            psMA0->m_vCG[1] = psMA1->m_vCG[1];
            SWITCH_FALLTHROUGH
        case ETgSWEEP_LINEAR:
            psMA0->m_sDT = psMA1->m_sDT;
            SWITCH_FALLTHROUGH
        case ETgSWEEP_STATIC:
            memcpy( psMA0->m_psBA, psMA1->m_psBA, nuiFace*sizeof( psMA1->m_psBA[0] ) );
            memcpy( psMA0->m_puiFlags, psMA1->m_puiFlags, nuiFace*sizeof( psMA1->m_puiFlags[0] ) );
            psMA0->m_vCG[0] = psMA1->m_vCG[0];
            break;
        default:
            TgS_NO_DEFAULT( break );
    };
}


/* ---- V(tgGM_MA_Update_Face_BA) --------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_MA_Update_Face_BA)( V(PCU_TgMESH_BA) psMA0 )
{
    if (nullptr == psMA0->m_sMS.m_puiIndx_List)
    {
        V(tgGM_MA_Update_Face_BA_VL)(psMA0);
    }
    else
    {
        V(tgGM_MA_Update_Face_BA_IL)(psMA0);
    };
}


/* ---- V(tgGM_MA_Update_Face_CG_BA) ------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_MA_Update_Face_CG_BA)( V(PCU_TgMESH_BA) psMA0 )
{
    if (nullptr == psMA0->m_sMS.m_puiIndx_List)
    {
        V(tgGM_MA_Update_Face_CG_BA_VL)( psMA0 );
    }
    else
    {
        V(tgGM_MA_Update_Face_CG_BA_IL)( psMA0 );
    };
}


/* ---- V(tgGM_MA_Query_Indx_List) -------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE CP_TgUINT16 V(tgGM_MA_Query_Indx_List)( V(CPCU_TgMESH_BA) psMA0 )
{
    return (V(tgGM_MS_Query_Indx_List)( &psMA0->m_sMS) );
}


/* ---- V(tgGM_MA_Query_Vert_List) -------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(CP_TgVEC) V(tgGM_MA_Query_Vert_List)( V(CPCU_TgMESH_BA) psMA0 )
{
    return (V(tgGM_MS_Query_Vert_List)( &psMA0->m_sMS) );
}


/* ---- V(tgGM_MA_Query_Indx_Count) ------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINT32 V(tgGM_MA_Query_Indx_Count)( V(CPCU_TgMESH_BA) psMA0 )
{
    return (V(tgGM_MS_Query_Indx_Count)( &psMA0->m_sMS) );
}


/* ---- V(tgGM_MA_Query_Vert_Count) ------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINT32 V(tgGM_MA_Query_Vert_Count)( V(CPCU_TgMESH_BA) psMA0 )
{
    return (V(tgGM_MS_Query_Vert_Count)( &psMA0->m_sMS) );
}


/* ---- V(tgGM_MA_Query_CG_0) ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(CP_TgVEC) V(tgGM_MA_Query_CG_0)( V(CPCU_TgMESH_BA) psMA0 )
{
    return (psMA0->m_vCG + 0);
}


/* ---- V(tgGM_MA_Query_CG_1) ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(CP_TgVEC) V(tgGM_MA_Query_CG_1)( V(CPCU_TgMESH_BA) psMA0 )
{
    TgERROR(ETgSWEEP_STATIC != psMA0->m_enSweep);
    return (psMA0->m_vCG + 1);
}


/* ---- V(tgGM_MA_Query_DT) --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(CP_TgDELTA) V(tgGM_MA_Query_DT)( V(CPCU_TgMESH_BA) psMA0 )
{
    return (&psMA0->m_sDT);
}