Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Common - Geometry 3D - Particle.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_PC_BA) --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID V(tgGM_PC_BA)( V(PCU_TgBOXAA) psBA0, V(CPCU_TgPARTICLE) psPC1, const TYPE fT )
{
    V(C_TgVEC)                          vX0 = *V(tgGM_PC_Query_Position)( psPC1 );
    V(C_TgVEC)                          tvX1 = V(tgGM_PC_Query_Position_Time)( psPC1, fT );

    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_PC_Is_Valid)(psPC1) && TgTRUE != F(tgPM_NAN)(fT) && fT >= MKL(0.0));

    V(tgGM_BA_Init_PT)( psBA0, &vX0 );
    V(tgGM_BA_Union_PT)( psBA0, &tvX1 );

    /* Check for points of inflection during the time interval */

    if (TgTRUE != F(tgCM_NR0)(psPC1->m_vAccel.m.x) && psPC1->m_vVel.m.x * psPC1->m_vAccel.m.x < MKL(0.0))
    {
        const TYPE                          fPoI = -psPC1->m_vVel.m.x / psPC1->m_vAccel.m.x;

        if (fPoI > MKL(0.0) && fPoI < fT)
        {
            const TYPE fTMP = psPC1->m_vPos.m.x + fPoI*psPC1->m_vVel.m.x + MKL(0.5)*fPoI*fPoI*psPC1->m_vAccel.m.x;

            V(tgGM_BA_Set_MinX)( psBA0, F(tgPM_FSEL)(fTMP - V(tgGM_BA_Query_MinX)(psBA0), V(tgGM_BA_Query_MinX)(psBA0), fTMP) );
            V(tgGM_BA_Set_MaxX)( psBA0, F(tgPM_FSEL)(V(tgGM_BA_Query_MaxX)(psBA0) - fTMP, V(tgGM_BA_Query_MaxX)(psBA0), fTMP) );
        };
    };

    if (TgTRUE != F(tgCM_NR0)(psPC1->m_vAccel.m.y) && psPC1->m_vVel.m.y * psPC1->m_vAccel.m.y < MKL(0.0))
    {
        const TYPE                          fPoI = -psPC1->m_vVel.m.y / psPC1->m_vAccel.m.y;

        if (fPoI > MKL(0.0) && fPoI < fT)
        {
            const TYPE fTMP = psPC1->m_vPos.m.y + fPoI*psPC1->m_vVel.m.y + MKL(0.5)*fPoI*fPoI*psPC1->m_vAccel.m.y;

            V(tgGM_BA_Set_MinY)( psBA0, F(tgPM_FSEL)(fTMP - V(tgGM_BA_Query_MinY)(psBA0), V(tgGM_BA_Query_MinY)(psBA0), fTMP) );
            V(tgGM_BA_Set_MaxY)( psBA0, F(tgPM_FSEL)(V(tgGM_BA_Query_MaxY)(psBA0) - fTMP, V(tgGM_BA_Query_MaxY)(psBA0), fTMP) );
        };
    };

    if (TgTRUE != F(tgCM_NR0)(psPC1->m_vAccel.m.z) && psPC1->m_vVel.m.z * psPC1->m_vAccel.m.z < MKL(0.0))
    {
        const TYPE                          fPoI = -psPC1->m_vVel.m.z / psPC1->m_vAccel.m.z;

        if (fPoI > MKL(0.0) && fPoI < fT)
        {
            const TYPE fTMP = psPC1->m_vPos.m.z + fPoI*psPC1->m_vVel.m.z + MKL(0.5)*fPoI*fPoI*psPC1->m_vAccel.m.z;

            V(tgGM_BA_Set_MinZ)( psBA0, F(tgPM_FSEL)(fTMP - V(tgGM_BA_Query_MinZ)(psBA0), V(tgGM_BA_Query_MinZ)(psBA0), fTMP) );
            V(tgGM_BA_Set_MaxZ)( psBA0, F(tgPM_FSEL)(V(tgGM_BA_Query_MaxZ)(psBA0) - fTMP, V(tgGM_BA_Query_MaxZ)(psBA0), fTMP) );
        };
    };
}


/* ---- V(tgGM_PC_Project) ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID V(tgGM_PC_Project)( PCU_TYPE ptyMin, PCU_TYPE ptyMax, V(CPCU_TgPARTICLE) psPC1, V(CPCU_TgVEC) ptvDN )
{
    const TYPE                          fS_AX = V(F_DOT)(&psPC1->m_vPos, ptvDN);
    const TYPE                          fV_AX = V(F_DOT)(&psPC1->m_vVel, ptvDN);
    const TYPE                          fA_AX = V(F_DOT)(&psPC1->m_vAccel, ptvDN);
    TYPE                                fTMP;

    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_PC_Is_Valid)(psPC1) && TgTRUE == V(F_Is_Vector_Valid)(ptvDN));

    *ptyMin = *ptyMax = fS_AX;

    fTMP = fS_AX + fV_AX + MKL(0.5) * fA_AX;
    if (fTMP < *ptyMin)
    {
        *ptyMin = fTMP;
    }
    else if (fTMP > *ptyMax)
    {
        *ptyMax = fTMP;
    };

    /* Check for points of inflexion during the time interval */

    if (TgTRUE != F(tgCM_NR0)(fA_AX) && fV_AX * fA_AX < MKL(0.0))
    {
        const TYPE                          fPoI = -fV_AX / fA_AX;

        if (fPoI > MKL(0.0) && fPoI < MKL(1.0))
        {
            fTMP = fS_AX + fPoI * fV_AX + MKL(0.5) * fPoI * fPoI * fA_AX;

            if (fTMP < *ptyMin)
            {
                *ptyMin = fTMP;
            }
            else if (fTMP > *ptyMax)
            {
                *ptyMax = fTMP;
            };
        };
    };
}