// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // // // Project: Talina Gaming System (TgS) (∂) // File: TgS Collision - Cylinder-Linear.inl // Author: Andrew Aye (EMail: andrew.aye@gmail.com, Web: http://www.andrewaye.com) // Version: 3.11 // // ------------------------------------------------------------------------------------------------------------------------------ // // // Copyright: © 2002-2008, 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". // // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // #if !defined(_TGS_COLLISION_CYLINDER_LINEAR_INL_) #define _TGS_COLLISION_CYLINDER_LINEAR_INL_ #pragma once // ============================================================================================================================== // // Functions used for internal use - primitive based functions should be the primary system calls. // A linear is a generic term used to describe the set of 1D primitives. To avoid code duplication these functions are normally // created through templates where two boolean template parameters are used to indicate if the free variable is closed on a // particular side of the number line. // tgCY0 Cylinder (Input) // tvS0 Point (Input) // tvD0 Direction (Input) // tyT0 Parametric parameter to generate point of interest #1 based on the segment (Output) // tyT1 Parametric parameter to generate point of interest #2 based on the segment (Output) // tvN0 Normal of contact corresponding to point of contact #1 (Output) // tvN1 Normal of contact corresponding to point of contact #2 (Output) // tgCL Container of points resulting from the clip operation (Output) // ============================================================================================================================== // namespace TGS { // START TGS /////////////////////////////////////////////////////////////////////////////////////////////////////// namespace COL { // START COL /////////////////////////////////////////////////////////////////////////////////////////////////////// // ============================================================================================================================== // template <typename TYPE, int DIM, bool bC0, bool bC1> TgRESULT TTgINT_CYLN<TYPE,DIM,bC0,bC1>::DO( TYPE *ptyT0, TYPE *ptyT1, PC_(VECTOR,DIM) ptvN0, PC_(VECTOR,DIM) ptvN1, CR_(CYLINDER,DIM) tgCY0, M_(VECTOR,DIM) tvS0, M_(VECTOR,DIM) tvD0 ) { TYPE tyT0, tyT1; C_TgRESULT tgResult = TTgINL_CYLN<TYPE,DIM,bC0,bC1>::DO( &tyT0,&tyT1, ptvN0,ptvN1, tgCY0, tvS0,tvD0 ); if (bC0) { tyT0 = P::FSEL( tyT0, tyT0, TYPE(0.0) ); }; if (bC1) { tyT1 = P::FSEL( tyT1 - TYPE(1.0), tyT1, TYPE(1.0) ); }; *ptyT0 = tyT0; *ptyT1 = tyT1; if (TgFAILED( tgResult ) || (bC0 && tyT0 < TYPE(0.0) && tyT1 <= TYPE(0.0)) || (bC1 && tyT0 >= TYPE(1.0) && tyT1 > TYPE(1.0))) { return (TgE_NOINTERSECT); } return (tgResult); }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // template <typename TYPE, int DIM, bool bC0, bool bC1> TgFORCEINLINE TgRESULT TTgCLP_CYLN<TYPE,DIM,bC0,bC1>::DO( PC_(CLIP_LIST,DIM) ptgCL, CR_(CYLINDER,DIM) tgCY0, M_(VECTOR,DIM) tvS0, M_(VECTOR,DIM) tvD0 ) { if (ptgCL->m_niMax - ptgCL->m_niPoint < 2) { return (TgE_FAIL); }; TYPE tyT0, tyT1; T_(VECTOR,DIM) tvN0, tvN1; C_TgRESULT tgResult = TTgINL_CYLN<TYPE,DIM,bC0,bC1>::DO( &tyT0,&tyT1, &tvN0,&tvN1, tgCY0, tvS0,tvD0 ); if (TgFAILED( tgResult )) { ptgCL->m_niPoint = 0; return (tgResult); }; // Limit the variable to the cap regions if (bC0) { tyT0 = P::FSEL( tyT0, tyT0, TYPE(0.0) ); }; if (bC1) { tyT1 = P::FSEL( tyT1 - TYPE(1.0), tyT1, TYPE(1.0) ); }; if ((bC0 && tyT0 < TYPE(0.0) && tyT1 <= TYPE(0.0)) || (bC1 && tyT0 >= TYPE(1.0) && tyT1 > TYPE(1.0))) { return (TgE_NOINTERSECT); } ptgCL->m_ptvPoint[ptgCL->m_niPoint++] = MATH::F_ADD( tvS0, MATH::F_MUL( tyT0, tvD0 ) ); ptgCL->m_ptvPoint[ptgCL->m_niPoint++] = MATH::F_ADD( tvS0, MATH::F_MUL( tyT1, tvD0 ) ); return (TgS_OK); }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // template <typename TYPE, int DIM, bool bC0, bool bC1> TgFORCEINLINE TgRESULT TTgCLP_CYLN<TYPE,DIM,bC0,bC1>::DO( TYPE *ptyT0, TYPE *ptyT1, CR_(CYLINDER,DIM) tgCY0, M_(VECTOR,DIM) tvS0, M_(VECTOR,DIM) tvD0 ) { T_(VECTOR,DIM) tvN0, tvN1; TYPE tyT0, tyT1; C_TgRESULT tgResult = TTgINL_CYLN<TYPE,DIM,bC0,bC1>::DO( &tyT0,&tyT1, &tvN0,&tvN1, tgCY0, tvS0,tvD0 ); if (TgFAILED( tgResult )) { return (tgResult); }; // Limit the variable to the cap regions if (bC0) { tyT0 = P::FSEL( tyT0, tyT0, TYPE(0.0) ); }; if (bC1) { tyT1 = P::FSEL( TYPE(1.0) - tyT1, tyT1, TYPE(1.0) ); }; *ptyT0 = tyT0; *ptyT1 = tyT1; if ((bC0 && tyT0 < TYPE(0.0) && tyT1 <= TYPE(0.0)) || (bC1 && tyT0 >= TYPE(1.0) && tyT1 > TYPE(1.0))) { return (TgE_NOINTERSECT); } return (TgS_OK); }; // ============================================================================================================================== // }; // END COL ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// }; // END TGS ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #endif // END ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////