Home

Resume

Blog

Teikitu


// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //
//  »Project«   Teikitu Gaming System (TgS) (∂)
//  »File«      TgS Collision - F - Capsule-Point.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;Capsule;Point;
// ------------------------------------------------------------------------------------------------------------------------------ //
//  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_CP_VT)( V(CPCU_TgTUBE) psCP0, V(CPCU_TgVEC) pvS0 )
{
    const TYPE                          fTest = V(tgCO_F_Dist_SG_VT)( &psCP0->m_sAX, pvS0 );
    const TYPE                          fDist = fTest - psCP0->m_fRadius;

    return (F(tgPM_FSEL)( fDist, fDist*fDist, -F(KTgMAX) ));
}


TgINLINE TYPE V(tgCO_F_Dist_CP_VT)( V(CPCU_TgTUBE) psCP0, V(CPCU_TgVEC) pvS0 )
{
    const TYPE                          fTest = V(tgCO_F_Dist_SG_VT)( &psCP0->m_sAX, pvS0 );
    const TYPE                          fDist = fTest - psCP0->m_fRadius;

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


TgINLINE TYPE V(tgCO_F_ClosestSq_CP_VT)( V(PCU_TgVEC) pfCP0, V(CPCU_TgTUBE) psCP0, V(CPCU_TgVEC) pvS0 )
{
    const TYPE                          fDist = V(tgCO_F_Closest_CP_VT)( pfCP0, psCP0, pvS0 );

    return (F(tgPM_FSEL)( fDist, fDist*fDist, -F(KTgMAX) ));
}


TgINLINE TYPE V(tgCO_F_Closest_CP_VT)( V(PCU_TgVEC) pvCP0, V(CPCU_TgTUBE) psCP0, V(CPCU_TgVEC) pvS0 )
{
    V(TgVEC)                            vCP0;

    const TYPE                          fTest =  V(tgCO_F_Closest_SG_VT)( &vCP0, &psCP0->m_sAX, pvS0 );
    const TYPE                          fDist = F(tgPM_FSEL)( fTest - psCP0->m_fRadius, fTest, MKL(-1.0) );
    V(C_TgVEC)                          vK0 = V(F_SUB_VV)( pvS0, &vCP0 );
    V(C_TgVEC)                          vK1 = V(F_MUL_SV)( psCP0->m_fRadius / fDist, &vK0 );

    *pvCP0 = V(F_ADD_VV)( &vCP0, &vK1 );

    return (F(tgPM_FSEL)( fDist, fDist - psCP0->m_fRadius, -F(KTgMAX) ));
}


TgINLINE TgBOOL V(tgCO_F_Test_CP_VT)( V(CPCU_TgTUBE) psCP0, V(CPCU_TgVEC) pvS0 )
{
    return (V(tgCO_F_Dist_SG_VT)( &psCP0->m_sAX, pvS0 ) <= psCP0->m_fRadius);
}