Home

Resume

Blog

Teikitu


// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //
//  »Project«   Teikitu Gaming System (TgS) (∂)
//  »File«      TgS Collision - F - Triangle-Line.i_inc
//  »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
//  »Version«   4.0
//  »Keywords«  Collision;Distance;Closest;Intersect;Penetrate;Sweep;Triangle;Line;
// ------------------------------------------------------------------------------------------------------------------------------ //
//  Copyright: © 2002-2010, 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: 
//    Redistributions of source code must retain this copyright notice, this list of conditions and the following disclaimers. 
//    Redistributions 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. 
//  Neither the names of the copyright owner nor the names of its contributors may 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 ================================================================================================================= //

TgINLINE TYPE V(tgCO_F_DistSq_ST_LN)( V(CPCU_TgSTRI) psST0, V(CPCU_TgLINE) psLN0 )
{
    TYPE                                fST0,fST1, fLN0;

    return (V(tgCO_F_ParamSq_ST_LN)( &fST0,&fST1, &fLN0, psST0, psLN0 ));
}


TgINLINE TYPE V(tgCO_F_Dist_ST_LN)( V(CPCU_TgSTRI) psST0, V(CPCU_TgLINE) psLN0 )
{
    const TYPE                          fDistSq = V(tgCO_F_DistSq_ST_LN)( psST0, psLN0 );

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


TgINLINE TYPE V(tgCO_F_ClosestSq_ST_LN)( V(PCU_TgVEC) pvET0, V(PCU_TgVEC) pvLN0, V(CPCU_TgSTRI) psST0, V(CPCU_TgLINE) psLN0 )
{
    TYPE                                fST0,fST1, fLN0;
    const TYPE                          fDistSq = V(tgCO_F_ParamSq_ST_LN)( &fST0,&fST1, &fLN0, psST0, psLN0 );
    V(C_TgVEC)                          vK0 = V(F_MUL_SV)( fST0, psST0->m_sCT.m_sET.m_avEdge + 0 );
    V(C_TgVEC)                          vK1 = V(F_MUL_SV)( fST1, psST0->m_sCT.m_sET.m_avEdge + 2 );
    V(C_TgVEC)                          vK2 = V(F_MUL_SV)( fLN0, &psLN0->m_vDirN );
    V(C_TgVEC)                          vK3 = V(F_ADD_VV)( psST0->m_sCT.m_sET.m_sPT.m_avPoint, &vK0 );

    *pvLN0 = V(F_ADD_VV)( &psLN0->m_vOrigin, &vK2 );
    *pvET0 = V(F_SUB_VV)( &vK3, &vK1 );

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


TgINLINE TYPE V(tgCO_F_Closest_ST_LN)( V(PCU_TgVEC) pvET0, V(PCU_TgVEC) pvLN0, V(CPCU_TgSTRI) psST0, V(CPCU_TgLINE) psLN0 )
{
    const TYPE                          fDistSq = V(tgCO_F_ClosestSq_ST_LN)( pvET0, pvLN0, psST0, psLN0 );

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


TgINLINE TYPE V(tgCO_F_ParamSq_ST_LN)( PCU_TYPE pfST0, PCU_TYPE pfST1, PCU_TYPE pfLN0, V(CPCU_TgSTRI) psST0, V(CPCU_TgLINE) psLN0 )
{
    return (V(tgCO_FI_ParamSq_ST_LR00)( pfST0, pfST1, pfLN0, psST0, &psLN0->m_vOrigin, &psLN0->m_vDirN ));
}


TgINLINE TYPE V(tgCO_F_Param_ST_LN)( PCU_TYPE pfST0, PCU_TYPE pfST1, PCU_TYPE pfLN0, V(CPCU_TgSTRI) psST0, V(CPCU_TgLINE) psLN0 )
{
    const TYPE                          fDistSq = V(tgCO_F_ParamSq_ST_LN)( pfST0,pfST1, pfLN0, psST0, psLN0 );

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


TgINLINE TgBOOL V(tgCO_F_Test_ST_LN)( V(CPCU_TgSTRI) psST0, V(CPCU_TgLINE) psLN0 )
{
    TYPE                                fST0,fST1, fLN0;

    return (TgSUCCEEDED(V(tgCO_FI_Intersect_P_ST_LR00)( &fST0,&fST1, &fLN0, psST0, &psLN0->m_vOrigin,&psLN0->m_vDirN )));
}


TgINLINE TgRESULT V(tgCO_F_Intersect_ST_LN)( V(PCU_STg2_CO_Packet) psPacket, V(CPCU_TgSTRI) psST0, V(CPCU_TgLINE) psLN0 )
{
    TYPE                                fST0,fST1, fLN0;
    TgRESULT                            tgResult;

    if (TgFAILED(tgResult = V(tgCO_FI_Intersect_P_ST_LR00)( &fST0,&fST1, &fLN0, psST0, &psLN0->m_vOrigin,&psLN0->m_vDirN )))
    {
        return (tgResult);
    }
    else
    {
        V(C_TgVEC)                          vK0 = V(F_MUL_SV)( fLN0, &psLN0->m_vDirN );
        V(P_STg2_CO_Contact)                psContact;

        psContact = (V(P_STg2_CO_Contact))(psPacket->m.piContact + psPacket->m_niContact*psPacket->m_iStride);

        psContact->m_vS0 = V(F_ADD_VV)(  &psLN0->m_vOrigin, &vK0 );
        psContact->m_vN0 = psST0->m_sCT.m_sET.m_sPT.m_vNormal;
        psContact->m_fT0 = fLN0;
        psContact->m_fDepth = MKL(0.0);

        ++psPacket->m_niContact;

        return (TgS_OK);
    };
}


TgINLINE TgRESULT V(tgCO_F_Intersect_P_ST_LN)(
    PCU_TYPE pfST0, PCU_TYPE pfST1, PCU_TYPE pfLN0, V(CPCU_TgSTRI) psST0, V(CPCU_TgLINE) psLN0 )
{
    return (V(tgCO_FI_Intersect_P_ST_LR00)( pfST0,pfST1, pfLN0, psST0,&psLN0->m_vOrigin,&psLN0->m_vDirN ));
}


TgINLINE TgRESULT V(tgCO_F_Clip_ST_LN)( V(PCU_STg2_CO_Clip_List) psCL, V(CPCU_TgSTRI) psST0, V(CPCU_TgLINE) psLN0 )
{
    return (V(tgCO_FI_Clip_ST_LR00)( psCL, psST0, &psLN0->m_vOrigin,&psLN0->m_vDirN ));
}


TgINLINE TgRESULT V(tgCO_F_Clip_F_ST_LN)(
    V(PCU_STg2_CO_Clip_List) psCL, PCU_TgSINT32 piCode, V(CPCU_TgSTRI) psST0, V(CPCU_TgLINE) psLN0 )
{
    return (V(tgCO_FI_Clip_F_ST_LR00)( psCL, piCode, psST0, &psLN0->m_vOrigin,&psLN0->m_vDirN ));
}


TgINLINE TgRESULT V(tgCO_F_Clip_Param_ST_LN)( PCU_TYPE pfLN0, PCU_TYPE pfLN1, V(CPCU_TgSTRI) psST0, V(CPCU_TgLINE) psLN0 )
{
    return (V(tgCO_FI_Clip_Param_ST_LR00)( pfLN0,pfLN1, psST0, &psLN0->m_vOrigin,&psLN0->m_vDirN ));
}


TgINLINE TgRESULT V(tgCO_F_Clip_Param_F_ST_LN)(
    PCU_TYPE pfLN0, PCU_TYPE pfLN1, PCU_TgSINT32 piCode, V(CPCU_TgSTRI) psST0, V(CPCU_TgLINE) psLN0 )
{
    return (V(tgCO_FI_Clip_Param_F_ST_LR00)( pfLN0,pfLN1, piCode, psST0, &psLN0->m_vOrigin,&psLN0->m_vDirN ));
}


TgINLINE TgRESULT V(tgCO_FI_Clip_Param_ST_LR00)(
    PCU_TYPE pfLN0, PCU_TYPE pfLN1, V(CPCU_TgSTRI) psST0, V(CPCU_TgVEC) pvS0, V(CPCU_TgVEC) pvD0 )
{
    TgSINT32                            iCode;

    return (V(tgCO_FI_Clip_Param_F_ST_LR00)( pfLN0,pfLN1, &iCode, psST0, pvS0,pvD0 ));
}