Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Collision - F - Parallelogram-Linear.i_inc
    »Keywords«  Collision;Distance;Closest;Intersect;Penetrate;Sweep;Parallelogram;
    »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".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */

MSVC_WARN_DISABLE_PUSH( 6285 ) /* Analysis - (<non-zero constant> || <non-zero constant>) is always a non-zero constant. */


/* == Collision ========================================================================================================================================================= */

/* ---- V(tgCO_FI_PE_Test_LR) ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL VI(tgCO_FI_PE_Test_LR)( V(CPC_TgPARALLELOGRAM) psPE0, V(CPC_TgVEC) pvS0, V(CPC_TgVEC) pvD0 )
{
    V(C_TgVEC)                          vK0 = V(F_SUB)( pvS0, &psPE0->m_vOrigin );
    const TYPE                          fDist = V(F_DOT)( &psPE0->m_vNormal, &vK0 );
    const TYPE                          fD1_N = V(F_DOT)( &psPE0->m_vNormal, pvD0 );

    TgPARAM_CHECK( V(tgGM_PE_Is_Valid)( psPE0 ) && V(F_Is_Point_Valid)( pvS0 ) && V(F_Is_Vector_Valid)( pvD0 ) );

    if (F(tgCM_NR0)( fD1_N ) || (LR_CAP_0 && !((fDist > MKL(0.0)) ^ (fD1_N > MKL(0.0)))))
    {
        return (TgFALSE);
    }
#if LR_CAP_1
    else if (F(tgPM_ABS)( fDist ) > F(tgPM_ABS)( fD1_N ))
    {
        return (TgFALSE);
    }
#endif
    else
    {
        V(C_TgVEC)                          vK1 = V(F_MUL_SV)( -fDist / fD1_N, pvD0 );
        V(C_TgVEC)                          vK2 = V(F_ADD)( pvS0, &vK1 );

        return (V(tgGM_PE_Is_Contained)( psPE0, &vK2 ));
    };
}


/* ---- V(tgCO_FI_PE_Clip_LR) ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgRESULT VI(tgCO_FI_PE_Clip_LR)( V(PC_STg2_CO_Clip_List) psCL, V(CPC_TgPARALLELOGRAM) psPE0, V(CPC_TgVEC) pvS0, V(CPC_TgVEC) pvD0 )
{
    TYPE                                fT0, fT1;

    if (psCL->m_niMax < 2)
    {
        return (KTgE_FAIL);
    };

    if (TgFAILED(VI(tgCO_FI_PE_Clip_Param_LR)( &fT0, &fT1, psPE0, pvS0, pvD0 )))
    {
        psCL->m_niPoint = 0;
        return (KTgE_NO_INTERSECT);
    };

    if ((LR_CAP_0 && fT0 < MKL(0.0) && fT1 <= MKL(0.0)) || (LR_CAP_1 && fT0 >= MKL(1.0) && fT1 > MKL(1.0)))
    {
        psCL->m_niPoint = 0;
        return (KTgE_NO_INTERSECT);
    }
    else
    {
        V(C_TgVEC)                          vK0 = V(F_MUL_SV)( fT0, pvD0 );
        V(C_TgVEC)                          vK1 = V(F_MUL_SV)( fT1, pvD0 );

        psCL->m_avPoint[0] = V(F_ADD)( pvS0, &vK0 );
        psCL->m_avPoint[1] = V(F_ADD)( pvS0, &vK1 );

        psCL->m_niPoint = 2;
        return (KTgS_OK);
    };
}


MSVC_WARN_DISABLE_POP( 6285 )