// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // // »Project« Teikitu Gaming System (TgS) (∂) // »File« TgS Collision - F - Plane-Linear.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;Plane;Linear; // ------------------------------------------------------------------------------------------------------------------------------ // // 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 TgRESULT VI(tgCO_FI_Clip_Param_PN_LR)( PCU_TYPE pfT0, PCU_TYPE pfT1, V(CPCU_TgPLANE) psPN0, V(CPCU_TgVEC) pvS0, V(CPCU_TgVEC) pvD0 ) { const TYPE fC0 = V(tgCO_F_Dist_PN_VT)( psPN0, pvS0 ); V(C_TgVEC) vK0 = V(F_ADD_VV)( pvS0, pvD0 ); const TYPE fC1 = V(tgCO_F_Dist_PN_VT)( psPN0, &vK0 ); if (LR_CAP_0 && LR_CAP_1) { *pfT0 = F(tgPM_FSEL)( fC0, MKL(0.0), fC0 / (fC1 - fC0) ); *pfT1 = F(tgPM_FSEL)( fC1, MKL(1.0), fC1 / (fC1 - fC0) ); } else if (LR_CAP_0 && !LR_CAP_1) { *pfT0 = F(tgPM_FSEL)( fC0, MKL(0.0), fC0 / (fC1 - fC0) ); *pfT1 = F(tgPM_FSEL)( fC1, F(tgPM_FSEL)( fC0 - fC1, fC1 / (fC1 - fC0), F(KTgMAX) ), fC1 / (fC1 - fC0) ); } else { *pfT0 = F(tgPM_FSEL)( fC0, F(tgPM_FSEL)( fC0 - fC1,-F(KTgMAX), fC0 / (fC1 - fC0) ), fC0 / (fC1 - fC0) ); *pfT1 = F(tgPM_FSEL)( fC1, F(tgPM_FSEL)( fC0 - fC1, fC1 / (fC1 - fC0), F(KTgMAX) ), fC1 / (fC1 - fC0) ); } return (fC0 >= MKL(0.0) || fC1 >= MKL(0.0) ? TgS_OK : TgE_FAIL); } TgINLINE TgRESULT VI(tgCO_FI_Clip_PN_LR)( V(PCU_STg2_CO_Clip_List) psCL, V(CPCU_TgPLANE) psPN0, V(CPCU_TgVEC) pvS0, V(CPCU_TgVEC) pvD0 ) { TYPE fT0, fT1; if (psCL->m_niMax < 2) { return (TgE_FAIL); } if (TgFAILED(VI(tgCO_FI_Clip_Param_PN_LR)( &fT0,&fT1, psPN0, pvS0,pvD0 ))) { psCL->m_niPoint = 0; return (ETgE_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 (ETgE_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_VV)( pvS0, &vK0 ); psCL->m_avPoint[1] = V(F_ADD_VV)( pvS0, &vK1 ); psCL->m_niPoint = 2; return (TgS_OK); }; }