Home

Resume

Blog

Teikitu


// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //
//  »Project«   Teikitu Gaming System (TgS) (∂)
//  »File«      TgS Collision - F - Rectangle-Ray.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;Rectangle;Ray;
// ------------------------------------------------------------------------------------------------------------------------------ //
//  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 ================================================================================================================= //

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

TgINLINE TYPE V(tgCO_F_DistSq_RT_RY)( V(CPCU_TgRECTANGLE) psRT0, V(CPCU_TgRAY) psRY0 )
{
    TYPE                                fT0,fT1, fT2;

    return (V(tgCO_F_ParamSq_RT_RY)( &fT0,&fT1, &fT2, psRT0, psRY0 ));
}


TgINLINE TYPE V(tgCO_F_Dist_RT_RY)( V(CPCU_TgRECTANGLE) psRT0, V(CPCU_TgRAY) psRY0 )
{
    const TYPE                          fDistSq = V(tgCO_F_DistSq_RT_RY)( psRT0, psRY0 );

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


TgINLINE TYPE V(tgCO_F_ClosestSq_RT_RY)( V(PCU_TgVEC) pvRT0, V(PCU_TgVEC) pvRY0, V(CPCU_TgRECTANGLE) psRT0, V(CPCU_TgRAY) psRY0 )
{
    TYPE                                fT0,fT1, fT2;

    const TYPE                          fDistSq = V(tgCO_F_ParamSq_RT_RY)( &fT0,&fT1, &fT2, psRT0, psRY0 );
    V(C_TgVEC)                          vK0 = V(F_MUL_SV)( fT0, psRT0->m_avEdge + 0 );
    V(C_TgVEC)                          vK1 = V(F_MUL_SV)( fT1, psRT0->m_avEdge + 1 );
    V(C_TgVEC)                          vK2 = V(F_ADD_VV)( &psRT0->m_vOrigin, &vK0 );
    V(C_TgVEC)                          vK3 = V(F_MUL_SV)( fT2, &psRY0->m_vDirN);

    *pvRT0 = V(F_ADD_VV)( &vK2, &vK1 );
    *pvRY0 = V(F_ADD_VV)( &psRY0->m_vOrigin, &vK3 );

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


TgINLINE TYPE V(tgCO_F_Closest_RT_RY)( V(PCU_TgVEC) pvRT0, V(PCU_TgVEC) pvRY0, V(CPCU_TgRECTANGLE) psRT0, V(CPCU_TgRAY) psRY0 )
{
    const TYPE                          fDistSq = V(tgCO_F_ClosestSq_RT_RY)( pvRT0, pvRY0, psRT0, psRY0 );

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


TgINLINE TYPE V(tgCO_F_ParamSq_RT_RY)(
    PCU_TYPE pfRT0, PCU_TYPE pfRT1, PCU_TYPE pfRY0, V(CPCU_TgRECTANGLE) psRT0, V(CPCU_TgRAY) psRY0 )
{
    return (V(tgCO_FI_ParamSq_RT_LR10)( pfRT0,pfRT1, pfRY0, psRT0, &psRY0->m_vOrigin, &psRY0->m_vDirN ));
}


TgINLINE TYPE V(tgCO_F_Param_RT_RY)(
    PCU_TYPE pfRT0, PCU_TYPE pfRT1, PCU_TYPE pfRY0, V(CPCU_TgRECTANGLE) psRT0, V(CPCU_TgRAY) psRY0 )
{
    const TYPE                          fDistSq = V(tgCO_F_ParamSq_RT_RY)( pfRT0,pfRT1, pfRY0, psRT0, psRY0 );

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


TgINLINE TgBOOL V(tgCO_F_Test_RT_RY)( V(CPCU_TgRECTANGLE) psRT0, V(CPCU_TgRAY) psRY0 )
{
    return (V(tgCO_F_DistSq_RT_RY)( psRT0, psRY0 ) > MKL(0.0));
}


TgINLINE TgRESULT V(tgCO_F_Clip_RT_RY)( V(PCU_STg2_CO_Clip_List) psCL, V(CPCU_TgRECTANGLE) psRT0, V(CPCU_TgRAY) psRY0 )
{
    return (V(tgCO_FI_Clip_RT_LR10)( psCL, psRT0, &psRY0->m_vOrigin, &psRY0->m_vDirN));
}


TgINLINE TgRESULT V(tgCO_F_Clip_Param_RT_RY)( PCU_TYPE pfRY0, PCU_TYPE pfRY1, V(CPCU_TgRECTANGLE) psRT0, V(CPCU_TgRAY) psRY0 )
{
    return (V(tgCO_FI_Clip_Param_RT_LR10)( pfRY0,pfRY1, psRT0, &psRY0->m_vOrigin, &psRY0->m_vDirN));
}