Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Common - Geometry 3D - Mesh [BA].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_MA_Is_Valid) --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgBOOL V(tgGM_MA_Is_Valid)( 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;

    if (TgTRUE != V(tgGM_MS_Is_Valid)( &psMA1->m_sMS ))
    {
        return (TgFALSE);
    };

    if (ETgSWEEP_ROTATIONAL == psMA1->m_enSweep || ETgSWEEP_LINEAR == psMA1->m_enSweep)
    {
        TgUINT32                            uiIndex;

        if (ETgSWEEP_ROTATIONAL == psMA1->m_enSweep)
        {
            if ((nullptr == psMA1->m_pvVert_DT) || (nullptr == psMA1->m_psBA) || (nullptr == psMA1->m_puiFlags))
            {
                return (TgFALSE);
            };

            if (TgTRUE != V(F_Is_Point_Valid)(psMA1->m_vCG + 0) )
            {
                return (TgFALSE);
            };

            if (TgTRUE != V(F_Is_Point_Valid)(psMA1->m_vCG + 1))
            {
                return (TgFALSE);
            };

            for (uiIndex = 0; uiIndex < psMA1->m_sMS.m_nuiVert; ++uiIndex)
            {
                if (TgTRUE != V(F_Is_Vector_Valid)(psMA1->m_pvVert_DT + uiIndex))
                {
                    return (TgFALSE);
                };
            };
        }
        else if (ETgSWEEP_LINEAR == psMA1->m_enSweep)
        {
            if ((nullptr != psMA1->m_pvVert_DT) || TgTRUE != V(tgGM_DT_Is_Valid)( &psMA1->m_sDT ) )
            {
                return (TgFALSE);
            };

            if ((nullptr == psMA1->m_psBA) || (nullptr == psMA1->m_puiFlags))
            {
                return (TgFALSE);
            };

            if (TgTRUE != V(tgGM_DT_Is_Valid)(&psMA1->m_sDT))
            {
                return (TgFALSE);
            };
        };

        for (uiIndex = 0; uiIndex < nuiFace; ++uiIndex)
        {
            if (TgTRUE != V(tgGM_BA_Is_Valid)( psMA1->m_psBA + uiIndex) )
            {
                return (TgFALSE);
            };
        };
    }
    else
    {
        if (nullptr != psMA1->m_pvVert_DT)
        {
            return (TgFALSE);
        };
    };

    return (TgTRUE);
}


/* ---- V(tgGM_MA_TX) --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID V(tgGM_MA_TX)( V(PCU_TgMESH_BA) psMA0, M34(CPCU_TgMAT) pxM0 )
{
    V(tgGM_MS_TX)( &psMA0->m_sMS, pxM0 );

    psMA0->m_vCG[0] = M34(F_TX_P)(pxM0, psMA0->m_vCG + 0);

    if (ETgSWEEP_ROTATIONAL == psMA0->m_enSweep)
    {
        TgUINT32                            uiIndex;

        TgERROR((nullptr != psMA0->m_psBA) && (nullptr != psMA0->m_puiFlags));

        for (uiIndex = 0; uiIndex < psMA0->m_sMS.m_nuiVert; ++uiIndex)
        {
            psMA0->m_pvVert_DT[uiIndex] = M34(F_TX_V)(pxM0, psMA0->m_pvVert_DT + uiIndex);
        };

        psMA0->m_vCG[1] = M34(F_TX_P)(pxM0, psMA0->m_vCG + 1);

        V(tgGM_MA_Update_Face_BA)( psMA0 );
    }
    else if (ETgSWEEP_LINEAR == psMA0->m_enSweep)
    {
        V(tgGM_DT_TX)( &psMA0->m_sDT, pxM0 );

        psMA0->m_vCG[1] = M34(F_TX_P)(pxM0, psMA0->m_vCG + 1);

        V(tgGM_MA_Update_Face_BA)( psMA0 );
    };
}


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

    V(tgGM_MA_Init)( psMA0, nuiVert, nuiIndx, psMA1->m_enSweep );
    V(tgGM_MS_Copy_TX)( &psMA0->m_sMS, &psMA1->m_sMS, pxM0 );

    psMA0->m_vCG[0] = M34(F_TX_P)(pxM0, psMA1->m_vCG + 0);

    if (ETgSWEEP_ROTATIONAL == psMA1->m_enSweep)
    {
        TgUINT32                            uiIndex;

        TgERROR((nullptr != psMA1->m_psBA) && (nullptr != psMA1->m_puiFlags));

        for (uiIndex = 0; uiIndex < psMA1->m_sMS.m_nuiVert; ++uiIndex)
        {
            psMA0->m_pvVert_DT[uiIndex] = M34(F_TX_V)(pxM0, psMA1->m_pvVert_DT + uiIndex);
        };

        psMA0->m_vCG[1] = M34(F_TX_P)(pxM0, psMA1->m_vCG + 1);

        V(tgGM_MA_Update_Face_BA)( psMA0 );
    }
    else if (ETgSWEEP_LINEAR == psMA1->m_enSweep)
    {
        V(tgGM_DT_Copy_TX)( &psMA0->m_sDT, &psMA1->m_sDT, pxM0 );

        psMA0->m_vCG[1] = M34(F_TX_P)(pxM0, psMA1->m_vCG + 1);

        V(tgGM_MA_Update_Face_BA)( psMA0 );
    };

    memcpy( psMA0->m_puiFlags, psMA1->m_puiFlags, nuiFace*sizeof( psMA1->m_puiFlags[0] ) );

    psMA0->m_enSweep = psMA1->m_enSweep;
}


/* ---- V(tgGM_MA_Init) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID V(tgGM_MA_Init)( V(PCU_TgMESH_BA) psMA0, C_TgUINT32 nuiVert, C_TgUINT32 nuiIndx, C_ETgSWEEP_TYPE enSweep )
{
    C_TgUINT32                          nuiVert_Old = psMA0->m_sMS.m_nuiVert;
    C_TgUINT32                          nuiIndx_Old = psMA0->m_sMS.m_nuiIndx;
    C_TgUINT32                          nuiFace_Old = (0 == psMA0->m_sMS.m_puiIndx_List ? nuiVert_Old : nuiIndx_Old) / 3;
    C_TgUINT32                          nuiFace = (0 == nuiIndx ? nuiVert : nuiIndx) / 3;

    V(tgGM_MS_Init)( &psMA0->m_sMS, nuiVert, nuiIndx );

    if ((nuiFace_Old == nuiFace) && (enSweep == psMA0->m_enSweep))
    {
        return;
    };

    V(tgGM_MA_Free_Internal)( psMA0 );

    psMA0->m_enSweep = enSweep;

    if (0 == nuiFace)
    {
        return;
    };

    switch (psMA0->m_enSweep)
    {
        case ETgSWEEP_ROTATIONAL:
            psMA0->m_pvVert_DT = (V(P_TgVEC))(TgMALLOC_POOL( nuiFace*sizeof( V(TgVEC) ) ));
        case ETgSWEEP_LINEAR:
        case ETgSWEEP_STATIC:
            psMA0->m_psBA = (V(P_TgBOXAA))(TgMALLOC_POOL( nuiFace*sizeof( V(TgBOXAA) ) ));
            psMA0->m_puiFlags = (P_TgUINT32)(TgMALLOC_POOL( nuiFace*sizeof( TgUINT32 ) ));
            break;
        default:
            TgS_NO_DEFAULT( break );
    };
}