Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Common - Geometry 3D - Ray.i_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_RY_Reset) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_RY_Reset)( V(PCU_TgRAY) psRY0 )
{
    psRY0->m_vOrigin = V(FS_SETP)( MKL(0.0), MKL(0.0), MKL(0.0) );
    psRY0->m_vDirN = V(FS_SETV)( MKL(0.0), MKL(0.0), MKL(0.0) );
}


/* ---- V(tgGM_RY_Is_Valid) --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL V(tgGM_RY_Is_Valid)( V(CPCU_TgRAY) psRY1 )
{
    if (TgTRUE != V(F_Is_Point_Valid)(&psRY1->m_vOrigin))
    {
        return (TgFALSE);
    };

    if (TgTRUE != V(F_Is_Vector_Valid)(&psRY1->m_vDirN) || TgTRUE == F(tgCM_NR0)( V(F_LEN)(&psRY1->m_vDirN) ))
    {
        return (TgFALSE);
    };

    return (TgTRUE);
}


/* ---- V(tgGM_RY_BA) --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_RY_BA)( V(PCU_TgBOXAA) psBA0, V(CPCU_TgRAY) UNUSED_PARAM psRY0 )
{
    V(tgGM_BA_Set_Invalid)( psBA0 );
}


/* ---- V(tgGM_RY_Sweep_BA) --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_RY_Sweep_BA)( V(PCU_TgBOXAA) psBA0, V(CPCU_TgRAY) UNUSED_PARAM psRY0, V(CPCU_TgVEC) UNUSED_PARAM pvDT )
{
    V(tgGM_BA_Set_Invalid)( psBA0 );
}


/* ---- V(tgGM_RY_Project) ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_RY_Project)( PCU_TYPE ptyMin, PCU_TYPE ptyMax, V(CPCU_TgRAY) psRY1, V(CPCU_TgVEC) pvDN )
{
    const TYPE                          fS0_AX = V(F_DOT)( &psRY1->m_vOrigin, pvDN );
    const TYPE                          fD0_AX = V(F_DOT)( &psRY1->m_vDirN, pvDN );

    TgGEOM_ASSERT_PARAM(0 != ptyMin && 0 != ptyMax && TgTRUE == V(tgGM_RY_Is_Valid)(psRY1) && TgTRUE == V(F_Is_Vector_Valid)(pvDN));

    *ptyMin = F(tgPM_FSEL)( fD0_AX, fS0_AX, -F(KTgMAX) );
    *ptyMax = F(tgPM_FSEL)( fD0_AX, F(KTgMAX), fS0_AX );
}


/* ---- V(tgGM_RY_Is_Contained) ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL V(tgGM_RY_Is_Contained)( V(CPCU_TgRAY) psRY1, V(CPCU_TgVEC) pvS0 )
{
    V(C_TgVEC)                          vDS = V(F_SUB)( pvS0, &psRY1->m_vOrigin );
    const TYPE                          fDS = F(tgCM_MAX)( V(F_DOT)(&vDS, &psRY1->m_vDirN), MKL(0.0) );
    V(C_TgVEC)                          tvS1 = V(F_MUL_SV)( fDS, &psRY1->m_vDirN );
    V(C_TgVEC)                          tvS2 = V(F_ADD)( &tvS1, &psRY1->m_vOrigin );
    V(C_TgVEC)                          tvS3 = V(F_SUB)( pvS0, &tvS2 );

    return (F(tgCM_NR0)( V(F_LEN)(&tvS3)) );
}


/* ---- V(tgGM_RY_TX) --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_RY_TX)( V(PCU_TgRAY) psRY0, M34(CPCU_TgMAT) pxM0 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE != M34(F_NaN)(pxM0));

    psRY0->m_vOrigin = M34(F_TX_P)( pxM0, &psRY0->m_vOrigin );
    psRY0->m_vDirN = M34(F_TX_V)( pxM0, &psRY0->m_vDirN );
}


/* ---- V(tgGM_RY_Copy_TX) ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_RY_Copy_TX)( V(PCU_TgRAY) psRY0, V(CPCU_TgRAY) psRY1, M34(CPCU_TgMAT) pxM0 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_RY_Is_Valid)(psRY1) && !M34(F_NaN)(pxM0));

    psRY0->m_vOrigin = M34(F_TX_P)( pxM0, &psRY1->m_vOrigin );
    psRY0->m_vDirN = M34(F_TX_V)( pxM0, &psRY1->m_vDirN );
}


/* ---- V(tgGM_RY_Init) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_RY_Init)( V(PCU_TgRAY) psRY0, V(CPCU_TgVEC) pvS0, V(CPCU_TgVEC) pvDN )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Point_Valid)( pvS0 ) && TgTRUE == V(F_Is_Vector_Valid)(pvDN));

    psRY0->m_vOrigin = *pvS0;
    psRY0->m_vDirN = *pvDN;
}


/* ---- V(tgGM_RY_Copy) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_RY_Copy)( V(PCU_TgRAY) psRY0, V(CPCU_TgRAY) psRY1 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_RY_Is_Valid)(psRY1));

    psRY0->m_vOrigin = psRY1->m_vOrigin;
    psRY0->m_vDirN = psRY1->m_vDirN;
}


/* ---- V(tgGM_RY_Set_Origin) ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_RY_Set_Origin)( V(PCU_TgRAY) psRY0, V(CPCU_TgVEC) pvS0 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Point_Valid)( pvS0 ));
    psRY0->m_vOrigin = *pvS0;
}


/* ---- V(tgGM_RY_Set_DirN) --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_RY_Set_DirN)( V(PCU_TgRAY) psRY0, V(CPCU_TgVEC) pvDN )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Vector_Valid)(pvDN));
    psRY0->m_vDirN = *pvDN;
}


/* ---- V(tgGM_RY_Query_Origin) ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(CP_TgVEC) V(tgGM_RY_Query_Origin)( V(CPCU_TgRAY) psRY1 )
{
    return (&psRY1->m_vOrigin);
}


/* ---- V(tgGM_RY_Query_DirN) ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(CP_TgVEC) V(tgGM_RY_Query_DirN)( V(CPCU_TgRAY) psRY1 )
{
    return (&psRY1->m_vDirN);
}


#if defined(TgCOMPILE_NATIVE_VECTOR)

/* ---- V(tgGM_RY_M_TX) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_RY_M_TX)( V(PCU_TgRAY) psRY0, M34(CPCU_TgMAT) pxM0 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE != M34(F_NaN)( pxM0 ));

    psRY0->m_vOrigin.m_mData = M34(M_TX_P)(  pxM0, psRY0->m_vOrigin.m_mData );
    psRY0->m_vDirN.m_mData = M34(M_TX_V)(  pxM0, psRY0->m_vDirN.m_mData );
}


/* ---- V(tgGM_RY_Copy_M_TX) -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_RY_Copy_M_TX)( V(PCU_TgRAY) psRY0, V(CPCU_TgRAY) psRY1, M34(CPCU_TgMAT) pxM0 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_RY_Is_Valid)( psRY1 ) && TgTRUE != M34(F_NaN)( pxM0 ));

    psRY0->m_vOrigin.m_mData = M34(M_TX_P)(  pxM0, psRY1->m_vOrigin.m_mData );
    psRY0->m_vDirN.m_mData = M34(M_TX_V)(  pxM0, psRY1->m_vDirN.m_mData );
}

/*# defined(TgCOMPILE_NATIVE_VECTOR) */
#endif