Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Common - Geometry 3D - Box.c_inc
    »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
    »Version«   4.51 / »GUID« A9981407-3EC9-42AF-8B6F-8BE6DD919615                                                                                                        */
/*   -------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
/*  Copyright: © 2002-2017, 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:
        Redistribution of source code must retain this copyright notice, this list of conditions and the following disclaimers.
        Redistribution 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.
    The name of the author may not 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".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/* == Common ============================================================================================================================================================ */

/* ---- V(tgGM_BX_Is_Valid) --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgBOOL V(tgGM_BX_Is_Valid)( V(CPCU_TgBOX) psBX1 )
{
    if (TgTRUE != V(F_Is_Point_Valid)(&psBX1->m.m.vOrigin))
    {
        return (TgFALSE);
    };

    /* Axes must be valid vectors and the lengths should be valid positive values. */
    if (TgTRUE != V(F_Is_Vector_Valid)(psBX1->m.m.avAxis + 0) || !(psBX1->m_vExtent.m.x >= MKL(0.0)) ||
        TgTRUE != V(F_Is_Vector_Valid)(psBX1->m.m.avAxis + 1) || !(psBX1->m_vExtent.m.y >= MKL(0.0)) ||
        TgTRUE != V(F_Is_Vector_Valid)(psBX1->m.m.avAxis + 2) || !(psBX1->m_vExtent.m.z >= MKL(0.0)))
    {
        return (TgFALSE);
    };

    if (   TgTRUE != F(tgCM_NR1)(V(F_LSQ)(psBX1->m.m.avAxis + 0))
        || TgTRUE != F(tgCM_NR1)(V(F_LSQ)(psBX1->m.m.avAxis + 1))
        || TgTRUE != F(tgCM_NR1)(V(F_LSQ)(psBX1->m.m.avAxis + 2)))
    {
        return (TgFALSE);
    };

    if ( /* All axes should be normal with respect to each other */
        TgTRUE != F(tgCM_NR0)(V(F_DOT)(psBX1->m.m.avAxis + 0, psBX1->m.m.avAxis + 1)) ||
        TgTRUE != F(tgCM_NR0)(V(F_DOT)(psBX1->m.m.avAxis + 0, psBX1->m.m.avAxis + 2)) ||
        TgTRUE != F(tgCM_NR0)(V(F_DOT)(psBX1->m.m.avAxis + 1, psBX1->m.m.avAxis + 2))
    )
    {
        return (TgFALSE);
    };

    return (TgTRUE);
}


/* ---- V(tgGM_BX_BA) --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID V(tgGM_BX_BA)( V(PCU_TgBOXAA) psBA0, V(CPCU_TgBOX) psBX1 )
{
    V(C_TgVEC)                          tvE0 = V(F_MUL_SV)(psBX1->m_vExtent.m.x, psBX1->m.m.avAxis + 0);
    V(C_TgVEC)                          tvE1 = V(F_MUL_SV)(psBX1->m_vExtent.m.y, psBX1->m.m.avAxis + 1);
    V(C_TgVEC)                          tvE2 = V(F_MUL_SV)(psBX1->m_vExtent.m.z, psBX1->m.m.avAxis + 2);
    V(C_TgVEC)                          tvE3 = V(F_SUB)(&tvE1, &tvE0);
    V(C_TgVEC)                          tvE4 = V(F_SUB)(&tvE2, &tvE0);
    V(C_TgVEC)                          tvE5 = V(F_SUB)(&tvE2, &tvE1);

    const TYPE                          fA0 = F(tgPM_FSEL)(tvE4.m.x, tvE0.m.x, tvE2.m.x);
    const TYPE                          fA1 = F(tgPM_FSEL)(tvE4.m.y, tvE0.m.y, tvE2.m.y);
    const TYPE                          fA2 = F(tgPM_FSEL)(tvE4.m.z, tvE0.m.z, tvE2.m.z);
    const TYPE                          fA3 = F(tgPM_FSEL)(tvE5.m.x, tvE1.m.x, tvE2.m.x);
    const TYPE                          fA4 = F(tgPM_FSEL)(tvE5.m.y, tvE1.m.y, tvE2.m.y);
    const TYPE                          fA5 = F(tgPM_FSEL)(tvE5.m.z, tvE1.m.z, tvE2.m.z);

    const TYPE                          fA6 = F(tgPM_FSEL)(tvE5.m.x, tvE2.m.x, tvE1.m.x);
    const TYPE                          fA7 = F(tgPM_FSEL)(tvE5.m.y, tvE2.m.y, tvE1.m.y);
    const TYPE                          fA8 = F(tgPM_FSEL)(tvE5.m.z, tvE2.m.z, tvE1.m.z);
    const TYPE                          fA9 = F(tgPM_FSEL)(tvE4.m.x, tvE2.m.x, tvE0.m.x);
    const TYPE                          fAA = F(tgPM_FSEL)(tvE4.m.y, tvE2.m.y, tvE0.m.y);
    const TYPE                          fAB = F(tgPM_FSEL)(tvE4.m.z, tvE2.m.z, tvE0.m.z);

    const TYPE                          fX0 = F(tgPM_FSEL)(tvE3.m.x, fA0, fA3);
    const TYPE                          fY0 = F(tgPM_FSEL)(tvE3.m.y, fA1, fA4);
    const TYPE                          fZ0 = F(tgPM_FSEL)(tvE3.m.z, fA2, fA5);
    const TYPE                          fX1 = F(tgPM_FSEL)(tvE3.m.x, fA6, fA9);
    const TYPE                          fY1 = F(tgPM_FSEL)(tvE3.m.y, fA7, fAA);
    const TYPE                          fZ1 = F(tgPM_FSEL)(tvE3.m.z, fA8, fAB);

    V(C_TgVEC)                          tvMin = V(FS_SETV)(fX0, fY0, fZ0);
    V(C_TgVEC)                          tvON = V(F_ADD)(&psBX1->m.m.vOrigin, &tvMin);
    V(C_TgVEC)                          tvMax = V(FS_SETV)(fX1, fY1, fZ1);
    V(C_TgVEC)                          tvOX = V(F_ADD)(&psBX1->m.m.vOrigin, &tvMax);

    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_BX_Is_Valid)(psBX1));

    V(tgGM_BA_Init_PT)( psBA0, &tvON );
    V(tgGM_BA_Union_PT)( psBA0, &tvOX );
}