Home

Resume

Blog

Teikitu


// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //
//  »Project«   Teikitu Gaming System (TgS) (∂)
//  »File«      TgS Collision - F - Rectangle [Util].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;Rectangle;
// ------------------------------------------------------------------------------------------------------------------------------ //
//  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_Clip_RT ---------------------------------------------------------------------------------------------------------- //
// Input:  psRT0: Rectangle primitive - F_Clip-space is the region defined by the infinite extrusion along the normal.
// Input:  tgCL: Contains a segment list that is to be clipped in-place.
// Output: tgCL: The resulting segment list.
// Return: Result Code.
// ------------------------------------------------------------------------------------------------------------------------------ //
TgRESULT V(tgCO_F_Clip_RT)( V(PCU_STg2_CO_Clip_List) psCL, V(CPCU_TgRECTANGLE) psRT0 )
{
    V(TgPLANE)                          sPlane;

    V(tgGM_Init_NP_PN)( &sPlane, psRT0->m_avEdge + 0, &psRT0->m_vOrigin );
    if (TgFAILED(V(tgCO_F_Clip_PN)( psCL, &sPlane )))
    {
        return (TgE_FAIL);
    };
    if (0 == psCL->m_niPoint) return (TgS_OK);

    V(tgGM_Set_Constant_PN)( &sPlane, V(tgGM_Query_Constant_PN)( &sPlane ) + V(F_LSQ)( psRT0->m_avEdge + 0 ) );
    V(tgGM_Negate_PN)( &sPlane );

    if (TgFAILED(V(tgCO_F_Clip_PN)( psCL, &sPlane )))
    {
        return (TgE_FAIL);
    };
    if (0 == psCL->m_niPoint) return (TgS_OK);

    V(tgGM_Init_NP_PN)( &sPlane, psRT0->m_avEdge + 1, &psRT0->m_vOrigin );
    if (TgFAILED(V(tgCO_F_Clip_PN)( psCL, &sPlane )))
    {
        return (TgE_FAIL);
    };
    if (0 == psCL->m_niPoint) return (TgS_OK);

    V(tgGM_Set_Constant_PN)( &sPlane, V(tgGM_Query_Constant_PN)( &sPlane ) + V(F_LSQ)( psRT0->m_avEdge + 1 ) );
    V(tgGM_Negate_PN)( &sPlane );

    if (TgFAILED(V(tgCO_F_Clip_PN)( psCL, &sPlane )))
    {
        return (TgE_FAIL);
    };
    return (TgS_OK);
}