[an error occurred while processing this directive]
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // // // Project: Talina Gaming System (TgS) (∂) // File: TgS Collision - Plane-Ray.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_PLANE_RAY_INL_) #define _TGS_COLLISION_PLANE_RAY_INL_ #pragma once // ============================================================================================================================== // // F_Dist[Sq], F_Closest[Sq] - Return the minimal distance [squared] between the primitives or negative type max if intersecting. // tgPN0 Plane (Input) // tgRY0 Ray (Input) // tgPacket Container of points resulting from a contact generator. Generation parameters provided as well. (Input/Ouput) // tvPN0 The point of closest proximity on the plane. (Output) // tvRY0 The point of closest proximity on the ray. (Output) // tgPacket Container of points resulting from a contact generator. Generation parameters provided as well. (Input/Ouput) // tyRY0 Parametric parameter to generate point of interest based on the ray. (Output) // tyRY0 Parametric parameter to generate point of interest based on the ray. (Output) // tgCL Container of points resulting from the clip operation. (Output) // ============================================================================================================================== // namespace TGS { // START TGS /////////////////////////////////////////////////////////////////////////////////////////////////////// namespace COL { // START COL /////////////////////////////////////////////////////////////////////////////////////////////////////// // ============================================================================================================================== // template <typename TYPE, int DIM> TgFORCEINLINE TYPE F_DistSq( CR_(PLANE,DIM) tgPN0, CR_(RAY,DIM) tgRY0 ) { const TYPE tyDist = F_Sign_Dist( tgPN0, tgRY0.Query_Origin() ); const TYPE tyD1_N = MATH::F_DOT(tgPN0.Query_Normal(),tgRY0.Query_DirN()); return (P::FSEL( tyDist, P::FSEL( tyD1_N, tyDist*tyDist , -LIMITS<TYPE>::MAX ), -LIMITS<TYPE>::MAX )); }; template <typename TYPE, int DIM> TgFORCEINLINE TYPE F_Dist( CR_(PLANE,DIM) tgPN0, CR_(RAY,DIM) tgRY0 ) { const TYPE tyDist = F_Sign_Dist( tgPN0, tgRY0.Query_Origin() ); const TYPE tyD1_N = MATH::F_DOT(tgPN0.Query_Normal(),tgRY0.Query_DirN()); return (P::FSEL( tyDist, P::FSEL( tyD1_N, tyDist , -LIMITS<TYPE>::MAX ), -LIMITS<TYPE>::MAX )); }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // template <typename TYPE, int DIM> TgFORCEINLINE TYPE F_ClosestSq( PC_(VECTOR,DIM) ptvPN0, PC_(VECTOR,DIM) ptvRY0, CR_(PLANE,DIM) tgPN0, CR_(RAY,DIM) tgRY0 ) { TYPE tyDist = F_Sign_Dist( tgPN0, tgRY0.Query_Origin() ); const TYPE tyD1_N = MATH::F_DOT(tgPN0.Query_Normal(),tgRY0.Query_DirN()); tyDist = P::FSEL( tyDist, P::FSEL( tyD1_N, tyDist , TYPE(-1.0) ), TYPE(-1.0) ); *ptvPN0 = MATH::F_SUB( tgRY0.Query_Origin(), MATH::F_MUL( tyDist, tgPN0.Query_Normal() ) ); *ptvRY0 = tgRY0.Query_Origin(); return (P::FSEL( tyDist, tyDist*tyDist, -LIMITS<TYPE>::MAX )); }; template <typename TYPE, int DIM> TgFORCEINLINE TYPE F_Closest( PC_(VECTOR,DIM) ptvPN0, PC_(VECTOR,DIM) ptvRY0, CR_(PLANE,DIM) tgPN0, CR_(RAY,DIM) tgRY0 ) { TYPE tyDist = F_Sign_Dist( tgPN0, tgRY0.Query_Origin() ); const TYPE tyD1_N = MATH::F_DOT(tgPN0.Query_Normal(),tgRY0.Query_DirN()); tyDist = P::FSEL( tyDist, P::FSEL( tyD1_N, tyDist , TYPE(-1.0) ), TYPE(-1.0) ); *ptvPN0 = MATH::F_SUB( tgRY0.Query_Origin(), MATH::F_MUL( tyDist, tgPN0.Query_Normal() ) ); *ptvRY0 = tgRY0.Query_Origin(); return (P::FSEL( tyDist, tyDist, -LIMITS<TYPE>::MAX )); }; template <typename TYPE, int DIM> TgFORCEINLINE TYPE F_ClosestSq( PC_(VECTOR,DIM) ptvPN0, TYPE *ptyRY0, CR_(PLANE,DIM) tgPN0, CR_(RAY,DIM) tgRY0 ) { TYPE tyDist = F_Sign_Dist( tgPN0, tgRY0.Query_Origin() ); const TYPE tyD1_N = MATH::F_DOT(tgPN0.Query_Normal(),tgRY0.Query_DirN()); tyDist = P::FSEL( tyDist, P::FSEL( tyD1_N, tyDist , TYPE(-1.0) ), TYPE(-1.0) ); *ptvPN0 = MATH::F_SUB( tgRY0.Query_Origin(), MATH::F_MUL( tyDist, tgPN0.Query_Normal() ) ); *ptyRY0 = TYPE(0.0); return (P::FSEL( tyDist, tyDist*tyDist, -LIMITS<TYPE>::MAX )); }; template <typename TYPE, int DIM> TgFORCEINLINE TYPE F_Closest( PC_(VECTOR,DIM) ptvPN0, TYPE *ptyRY0, CR_(PLANE,DIM) tgPN0, CR_(RAY,DIM) tgRY0 ) { TYPE tyDist = F_Sign_Dist( tgPN0, tgRY0.Query_Origin() ); const TYPE tyD1_N = MATH::F_DOT(tgPN0.Query_Normal(),tgRY0.Query_DirN()); tyDist = P::FSEL( tyDist, P::FSEL( tyD1_N, tyDist , TYPE(-1.0) ), TYPE(-1.0) ); *ptvPN0 = MATH::F_SUB( tgRY0.Query_Origin(), MATH::F_MUL( tyDist, tgPN0.Query_Normal() ) ); *ptyRY0 = TYPE(0.0); return (P::FSEL( tyDist, tyDist, -LIMITS<TYPE>::MAX )); }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // template <typename TYPE, int DIM> TgFORCEINLINE TgBOOL F_Contact_Test( CR_(PLANE,DIM) tgPN0, CR_(RAY,DIM) tgRY0 ) { return (F_Sign_Dist( tgPN0, tgRY0.Query_Origin() ) <= TYPE(0.0) || MATH::F_DOT(tgPN0.Query_Normal(),tgRY0.Query_DirN()) < TYPE(0.0)); }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // template <typename TYPE, int DIM> TgFORCEINLINE TgRESULT F_Contact_Intersect( TYPE *ptyRY0, CR_(PLANE,DIM) tgPN0, CR_(RAY,DIM) tgRY0 ) { TgASSERT(tgPN0.Is_Valid() && tgRY0.Is_Valid()) const TYPE tyDist = F_Sign_Dist( tgPN0, tgRY0.Query_Origin() ); const TYPE tyD1_N = tgPN0.Query_Normal()*tgRY0.Query_DirN(); if (Near_Zero( tyD1_N ) || !( (tyDist > TYPE(0.0)) ^ (tyD1_N > TYPE(0.0)) )) { return (TgE_NOINTERSECT); }; *ptyRY0 = -tyDist / tyD1_N; return (TgS_OK); }; template <typename TYPE, int DIM> TgFORCEINLINE TgRESULT F_Contact_Intersect( PC_(CONTACT_PACKET,DIM) ptgPacket, CR_(PLANE,DIM) tgPN0, CR_(RAY,DIM) tgRY0 ) { TgASSERT((TgSIZE)ptgPacket->m_iStride >= sizeof( P_(CONTACT,DIM) )) TgASSERT(tgPN0.Is_Valid() && tgRY0.Is_Valid()) if (0 == ptgPacket->m_niMaxContact || ptgPacket->m_niContact >= ptgPacket->m_niMaxContact || NULL == ptgPacket->m_ptgContact) { return (TgE_FAIL); }; const TYPE tyDist = F_Sign_Dist( tgPN0, tgRY0.Query_Origin() ); const TYPE tyD1_N = MATH::F_DOT( tgPN0.Query_Normal(), tgRY0.Query_DirN() ); if (Near_Zero( tyD1_N ) || !( (tyDist > TYPE(0.0)) ^ (tyD1_N > TYPE(0.0)) )) { return (TgE_NOINTERSECT); }; const TYPE tyT0 = -tyDist / tyD1_N; P_(CONTACT,DIM) ptgContact; ptgContact = (P_(CONTACT,DIM))((PC_TgUINT08)ptgPacket->m_ptgContact + ptgPacket->m_niContact*ptgPacket->m_iStride); ptgContact->m_tvPos = MATH::F_ADD( tgRY0.Query_Origin(), MATH::F_MUL( tyT0, tgRY0.Query_DirN() ) ); ptgContact->m_tvNormal = MATH::F_MUL( P::FSEL( tyDist, TYPE(1.0), TYPE(-1.0) ), tgPN0.Query_Normal() ); ptgContact->m_tyT0 = tyT0; ptgContact->m_tyDepth = TYPE(0.0); ++ptgPacket->m_niContact; return (TgS_OK); }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // template <typename TYPE, int DIM> TgFORCEINLINE TgRESULT F_Clip( TYPE *ptyRY0, TYPE *ptyRY1, CR_(PLANE,DIM) tgPN0, CR_(RAY,DIM) tgRY0 ) { return (TTgCLP_PNLN<TYPE,DIM,1,0>::DO( ptyRY0,ptyRY1, tgPN0, tgRY0.Query_Origin(),tgRY0.Query_DirN() )); }; template <typename TYPE, int DIM> TgFORCEINLINE TgRESULT F_Clip( PC_(CLIP_LIST,DIM) ptgCL, CR_(PLANE,DIM) tgPN0, CR_(RAY,DIM) tgRY0 ) { return (TTgCLP_PNLN<TYPE,DIM,1,0>::DO( ptgCL, tgPN0, tgRY0.Query_Origin(),tgRY0.Query_DirN() )); }; // ============================================================================================================================== // }; // END COL ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// }; // END TGS ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #endif // END ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////[an error occurred while processing this directive]