Home

Resume

Blog

Teikitu


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

// ---- tgCO_F_Penetrate_BX_CX -------------------------------------------------------------------------------------------------- //
// Input:  tgPacket: The current series of contact points for this query-series, and contact generation parameters.
// Input:  tgBX0: Box primitive
// Input:  tgMH0: Mesh(Convex) primitive - contact points are generated on this primitive
// Return: Result Code
// ------------------------------------------------------------------------------------------------------------------------------ //
TgRESULT V(tgCO_F_Penetrate_BX_CX)(
    V(PCU_STg2_CO_Packet) psPacket, V(CPCU_TgBOX) psBX0, V(CPCU_TgSTRI) apsST, V(CPCU_TgBOXAA) apsBA, C_TgSINT32 niTri )
{
    C_TgSINT32                          niContact = psPacket->m_niContact;
    V(STg2_CO_Packet)                   sTriPacket;
    V(STg2_CO_Contact)                  asContact[8];
    TgSINT32                            iIdx;

    TgASSERT_PARAM(NULL != psPacket);
    TgASSERT_PARAM(NULL != psBX0);
    TgASSERT_PARAM(NULL != apsST && NULL != apsBA && 0 < niTri);

    sTriPacket.m.psContact = asContact;
    sTriPacket.m_fSweepTol = MKL(0.0);
    sTriPacket.m_fSnapTol = F(KTgEPS);
    sTriPacket.m_niContact = 0;
    sTriPacket.m_niMaxContact = 8;
    sTriPacket.m_iStride = sizeof( V(STg2_CO_Contact) );

    for (iIdx = 0; iIdx < niTri; ++iIdx)
    {
        V(P_STg2_CO_Contact)                psContact;
        TgSINT32                            niTri;

        //if (!V(tgCO_F_Test_BA_BX)( apsBA + iIdx, psBX0 ))
        //{
        //    continue;
        //};

        if (V(tgCO_F_Penetrate_ST_BX)( &sTriPacket, apsST + iIdx, psBX0 ) < 0)
        {
            continue;
        };

        for (niTri = 0; niTri < sTriPacket.m_niContact; ++niTri)
        {
            V(C_TgVEC)                          vK0 = V(F_MUL_SV)( asContact[niTri].m_fDepth, &asContact[niTri].m_vN0 );

            if (psPacket->m_niContact >= psPacket->m_niMaxContact)
            {
                return (ETgE_MAX_CONTACTS);
            };

            psContact = (V(P_STg2_CO_Contact))(psPacket->m.piContact + psPacket->m_niContact*psPacket->m_iStride);

            psContact->m_vS0 = V(F_ADD_VV)( &asContact[niTri].m_vS0, &vK0 );
            psContact->m_vN0 = V(F_NEG)( &asContact[niTri].m_vN0 );
            psContact->m_fT0 = MKL(0.0);
            psContact->m_fDepth = asContact[niTri].m_fDepth;

            ++psPacket->m_niContact;
        };
    };

    return (niContact != psPacket->m_niContact ? TgS_OK : ETgE_NO_INTERSECT);
}