Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Collision - F - Parallelogram-Segment.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".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/* == Collision ========================================================================================================================================================= */

#define VI(A) V(A##11)
#define LR_CAP_0 1
#define LR_CAP_1 1
    #include "TgS Collision - F - Parallelogram-Linear.i_inc"
#undef LR_CAP_1
#undef LR_CAP_0
#undef VI

/* ---- V(tgCO_F_PE_DistSq_SG) ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgCO_F_PE_DistSq_SG)( V(CPC_TgPARALLELOGRAM) psPE0, V(CPC_TgSEGMENT) psSG0 )
{
    TYPE                                fT0, fT1, fT2;

    return (V(tgCO_F_PE_ParamSq_SG)( &fT0, &fT1, &fT2, psPE0, psSG0 ));
}


/* ---- V(tgCO_F_PE_Dist_SG) -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgCO_F_PE_Dist_SG)( V(CPC_TgPARALLELOGRAM) psPE0, V(CPC_TgSEGMENT) psSG0 )
{
    const TYPE                          fDistSq = V(tgCO_F_PE_DistSq_SG)( psPE0, psSG0 );

    return (F(tgPM_FSEL)( fDistSq, F(tgPM_SQRT)( fDistSq ), -F(KTgMAX) ));
}


/* ---- V(tgCO_F_PE_ClosestSq_SG) --------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgCO_F_PE_ClosestSq_SG)( V(PC_TgVEC) pvPE0, V(PC_TgVEC) pvSG0, V(CPC_TgPARALLELOGRAM) psPE0, V(CPC_TgSEGMENT) psSG0 )
{
    TYPE                                fT0, fT1, fT2;

    const TYPE                          fDistSq = V(tgCO_F_PE_ParamSq_SG)( &fT0, &fT1, &fT2, psPE0, psSG0 );
    V(C_TgVEC)                          vK0 = V(F_MUL_SV)( fT0, psPE0->m_avEdge + 0 );
    V(C_TgVEC)                          vK1 = V(F_MUL_SV)( fT1, psPE0->m_avEdge + 1 );
    V(C_TgVEC)                          vK2 = V(F_ADD)( &vK0, &vK1 );
    V(C_TgVEC)                          vK3 = V(F_MUL_SV)( fT2, &psSG0->m_vDirN );

    *pvPE0 = V(F_ADD)( &psPE0->m_vOrigin, &vK2 );
    *pvSG0 = V(F_ADD)( &psSG0->m_vOrigin, &vK3 );

    return (F(tgPM_FSEL)( fDistSq, fDistSq, -F(KTgMAX) ));
}


/* ---- V(tgCO_F_PE_Closest_SG) ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgCO_F_PE_Closest_SG)( V(PC_TgVEC) pvPE0, V(PC_TgVEC) pvSG0, V(CPC_TgPARALLELOGRAM) psPE0, V(CPC_TgSEGMENT) psSG0 )
{
    const TYPE                          fDistSq = V(tgCO_F_PE_ClosestSq_SG)( pvPE0, pvSG0, psPE0, psSG0 );

    return (F(tgPM_FSEL)( fDistSq, F(tgPM_SQRT)( fDistSq ), -F(KTgMAX) ));
}


/* ---- V(tgCO_F_PE_ParamSq_SG) ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgCO_F_PE_ParamSq_SG)( TYPE *pfPE0, TYPE *pfPE1, TYPE *pfSG0, V(CPC_TgPARALLELOGRAM) psPE0, V(CPC_TgSEGMENT) psSG0 )
{
    return (V(tgCO_F_PE_ParamSq_LR11)( pfPE0, pfPE1, pfSG0, psPE0, &psSG0->m_vOrigin, &psSG0->m_vDirN ));
}


/* ---- V(tgCO_F_PE_Param_SG) ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgCO_F_PE_Param_SG)( TYPE *pfPE0, TYPE *pfPE1, TYPE *pfSG0, V(CPC_TgPARALLELOGRAM) psPE0, V(CPC_TgSEGMENT) psSG0 )
{
    const TYPE                          fDistSq = V(tgCO_F_PE_ParamSq_SG)( pfPE0, pfPE1, pfSG0, psPE0, psSG0 );

    return (F(tgPM_FSEL)( fDistSq, F(tgPM_SQRT)( fDistSq ), -F(KTgMAX) ));
}


/* ---- V(tgCO_F_PE_Test_SG) -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL V(tgCO_F_PE_Test_SG)( V(CPC_TgPARALLELOGRAM) psPE0, V(CPC_TgSEGMENT) psSG0 )
{
    return (V(tgCO_FI_PE_Test_LR11)( psPE0, &psSG0->m_vOrigin, &psSG0->m_vDirN ));
}


/* ---- V(tgCO_F_PE_Clip_Param_SG) -------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgRESULT V(tgCO_F_PE_Clip_Param_SG)( TYPE *pfSG0, TYPE *pfSG1, V(CPC_TgPARALLELOGRAM) psPE0, V(CPC_TgSEGMENT) psSG0 )
{
    return (V(tgCO_FI_PE_Clip_Param_LR11)( pfSG0, pfSG1, psPE0, &psSG0->m_vOrigin, &psSG0->m_vDirN ));
}


/* ---- V(tgCO_F_PE_Clip_SG) -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgRESULT V(tgCO_F_PE_Clip_SG)( V(PC_STg2_CO_Clip_List) psCL, V(CPC_TgPARALLELOGRAM) psPE0, V(CPC_TgSEGMENT) psSG0 )
{
    return (V(tgCO_FI_PE_Clip_LR11)( psCL, psPE0, &psSG0->m_vOrigin, &psSG0->m_vDirN ));
}


/* ---- V(tgCO_F_PE_Clip_Points) ---------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgRESULT V(tgCO_F_PE_Clip_Points)( TYPE *pfSG0, TYPE *pfSG1, V(CPC_TgPARALLELOGRAM) psPE0, V(CPC_TgVEC) pvS0, V(CPC_TgVEC) pvS1 )
{
    V(TgVEC)                            vD0;

    vD0 = V(F_SUB)( pvS1, pvS0 );
    return (V(tgCO_FI_PE_Clip_Param_LR11)( pfSG0, pfSG1, psPE0, pvS0, &vD0 ));
}