Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Common - Math API [Matrix] [F].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 ============================================================================================================================================================ */

/* ---- M(F_ADD) -------------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_ADD)( M(PCU_TgMAT) pxRet, M(CPCU_TgMAT) pxM0, M(CPCU_TgMAT) pxM1 )
{
    #define EQN(A) V(F_ADD)( pxM0->m_avRow + A, pxM1->m_avRow + A )
    MAT_ASSIGN
    #undef EQN
}


/* ---- M(F_MUL) -------------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_MUL)( M(PCU_TgMAT) pxRet, M(CPCU_TgMAT) pxM0, M(CPCU_TgMAT) pxM1 )
{
    #define EQN(A) V(F_MUL)( pxM0->m_avRow + A, pxM1->m_avRow + A )
    MAT_ASSIGN
    #undef EQN
}


/* ---- M(F_MUL_SM) ----------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_MUL_SM)( M(PCU_TgMAT) pxRet, const TYPE fScalar, M(CPCU_TgMAT) pxM1 )
{
    #define EQN(A) V(F_MUL_SV)( fScalar, pxM1->m_avRow + A )
    MAT_ASSIGN
    #undef EQN
}


/* ---- M(F_MUL_MS) ----------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_MUL_MS)( M(PCU_TgMAT) pxRet, M(CPCU_TgMAT) pxM0, const TYPE fScalar )
{
    #define EQN(A) V(F_MUL_VS)( pxM0->m_avRow + A, fScalar )
    MAT_ASSIGN
    #undef EQN
}


/* ---- M(F_DIV) -------------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_DIV)( M(PCU_TgMAT) pxRet, M(CPCU_TgMAT) pxM0, M(CPCU_TgMAT) pxM1 )
{
    #define EQN(A) V(F_DIV)( pxM0->m_avRow + A, pxM1->m_avRow + A )
    MAT_ASSIGN
    #undef EQN
}


/* ---- M(F_DIV_SM) ----------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_DIV_SM)( M(PCU_TgMAT) pxRet, const TYPE fScalar, M(CPCU_TgMAT) pxM1 )
{
    #define EQN(A) V(F_DIV_SV)( fScalar, pxM1->m_avRow + A )
    MAT_ASSIGN
    #undef EQN
}


/* ---- M(F_DIV_MS) ----------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_DIV_MS)( M(PCU_TgMAT) pxRet, M(CPCU_TgMAT) pxM0, const TYPE fScalar )
{
    #define EQN(A) V(F_DIV_VS)( pxM0->m_avRow + A, fScalar )
    MAT_ASSIGN
    #undef EQN
}


/* ---- M(F_SUB) -------------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_SUB)( M(PCU_TgMAT) pxRet, M(CPCU_TgMAT) pxM0, M(CPCU_TgMAT) pxM1 )
{
    #define EQN(A) V(F_SUB)( pxM0->m_avRow + A, pxM1->m_avRow + A )
    MAT_ASSIGN
    #undef EQN
}


/* ---- M(F_NEG) -------------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_NEG)( M(PCU_TgMAT) pxRet, M(CPCU_TgMAT) pxM0 )
{
    #define EQN(A) V(F_NEG)( pxM0->m_avRow + A )
    MAT_ASSIGN
    #undef EQN
}


/* ---- M(F_Set_Euler) -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_Set_Euler)( M(PCU_TgMAT) pxM0, V(CPCU_TgVEC) pvEul )
{
    M(FS_Set_Euler)( pxM0, pvEul->m.x, pvEul->m.y, pvEul->m.z );
}


/* ---- M(FS_Set_Euler) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(FS_Set_Euler)( M(PCU_TgMAT) pxM0, const TYPE fX, const TYPE fY, const TYPE fZ )
{
    TYPE                                fSinZ, fCosZ, fSinX, fCosX, fSinY, fCosY;

    F(tgPM_SINCOS)( &fSinX, &fCosX, fX ); /*« Roll */
    F(tgPM_SINCOS)( &fSinY, &fCosY, fY ); /*« Pitch */
    F(tgPM_SINCOS)( &fSinZ, &fCosZ, fZ ); /*« Yaw */

    pxM0->m.f11 = fCosY*fCosZ;
    pxM0->m.f12 = fCosY*fSinZ;
    pxM0->m.f13 = -fSinY;

    pxM0->m.f21 = fSinX*fSinY*fCosZ - fCosX*fSinZ;
    pxM0->m.f22 = fSinX*fSinY*fSinZ + fCosX*fCosZ;
    pxM0->m.f23 = fSinX*fCosY;

    pxM0->m.f31 = fCosX*fSinY*fCosZ + fSinX*fSinZ;
    pxM0->m.f32 = fCosX*fSinY*fSinZ - fSinX*fCosZ;
    pxM0->m.f33 = fCosX*fCosY;
}


/* ---- M(FS_Set_EulerX) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(FS_Set_EulerX)( M(PCU_TgMAT) pxM0, const TYPE fX )
{
    TYPE                                fSinX, fCosX;

    F(tgPM_SINCOS)( &fSinX, &fCosX, fX );

    pxM0->m.f11 = MKL(1.0); pxM0->m.f12 = MKL(0.0); pxM0->m.f13 = MKL(0.0);
    pxM0->m.f21 = MKL(0.0); pxM0->m.f22 = fCosX;   pxM0->m.f23 = fSinX;
    pxM0->m.f31 = MKL(0.0); pxM0->m.f32 = -fSinX;   pxM0->m.f33 = fCosX;
}


/* ---- M(FS_Set_EulerY) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(FS_Set_EulerY)( M(PCU_TgMAT) pxM0, const TYPE fY )
{
    TYPE                                fSinY, fCosY;

    F(tgPM_SINCOS)( &fSinY, &fCosY, fY );

    pxM0->m.f11 = fCosY;   pxM0->m.f12 = MKL(0.0); pxM0->m.f13 = -fSinY;
    pxM0->m.f21 = MKL(0.0); pxM0->m.f22 = MKL(1.0); pxM0->m.f23 = MKL(0.0);
    pxM0->m.f31 = fSinY;   pxM0->m.f32 = MKL(0.0); pxM0->m.f33 = fCosY;
}


/* ---- M(FS_Set_EulerZ) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(FS_Set_EulerZ)( M(PCU_TgMAT) pxM0, const TYPE fZ )
{
    TYPE                                fSinZ, fCosZ;

    F(tgPM_SINCOS)( &fSinZ, &fCosZ, fZ );

    pxM0->m.f11 = fCosZ;   pxM0->m.f12 = fSinZ;   pxM0->m.f13 = MKL(0.0);
    pxM0->m.f21 = -fSinZ;   pxM0->m.f22 = fCosZ;   pxM0->m.f23 = MKL(0.0);
    pxM0->m.f31 = MKL(0.0); pxM0->m.f32 = MKL(0.0); pxM0->m.f33 = MKL(1.0);
}


/* ---- M(F_Set_Quat) --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_Set_Quat)( M(PCU_TgMAT) pxM0, V(CPCU_TgVEC) pqR0 )
{
    const TYPE                          fXS = MKL(2.0) * pqR0->m.x;
    const TYPE                          fYS = MKL(2.0) * pqR0->m.y;
    const TYPE                          fZS = MKL(2.0) * pqR0->m.z;

    const TYPE                          fXX = fXS * pqR0->m.x;
    const TYPE                          fXY = fXS * pqR0->m.y;
    const TYPE                          fXZ = fXS * pqR0->m.z;
    const TYPE                          fXW = fXS * pqR0->m.w;

    const TYPE                          fYY = fYS * pqR0->m.y;
    const TYPE                          fYZ = fYS * pqR0->m.z;
    const TYPE                          fYW = fYS * pqR0->m.w;

    const TYPE                          fZZ = fZS * pqR0->m.z;
    const TYPE                          fZW = fZS * pqR0->m.w;

    pxM0->m.f11 = MKL(1.0) - (fYY + fZZ);
    pxM0->m.f12 = fXY + fZW;
    pxM0->m.f13 = fXZ - fYW;

    pxM0->m.f21 = fXY - fZW;
    pxM0->m.f22 = MKL(1.0) - (fXX + fZZ);
    pxM0->m.f23 = fYZ + fXW;

    pxM0->m.f31 = fXZ + fYW;
    pxM0->m.f32 = fYZ - fXW;
    pxM0->m.f33 = MKL(1.0) - (fXX + fYY);
}


/* ---- M(F_NaN) -------------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL M(F_NaN)( M(CPCU_TgMAT) pxM0 )
{
    TgUINT32                            uiIndex;

    for (uiIndex = 0; uiIndex < ROW * COL; ++uiIndex)
    {
        if (F(tgPM_NAN)(pxM0->m_aElement[uiIndex]))
        {
            return (TgTRUE);
        };
    };

    return (TgFALSE);
}


/* ---- M(F_CLI) -------------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_CLI)( M(PCU_TgMAT) pxM0 )
{
    TgSINT32                            iIndex;

    for (iIndex = 0; iIndex < ROW * COL; ++iIndex)
    {
        pxM0->m_aElement[iIndex] = ((iIndex % COL) == (iIndex / COL)) ? MKL(1.0) : MKL(0.0);
    };
}


/* ---- M(F_SET_ROT) ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_SET_ROT)( M(PCU_TgMAT) pxM0, M(CPCU_TgMAT) pxM1 )
{
    pxM0->m.f11 = pxM1->m.f11; pxM0->m.f12 = pxM1->m.f12; pxM0->m.f13 = pxM1->m.f13;
    pxM0->m.f21 = pxM1->m.f21; pxM0->m.f22 = pxM1->m.f22; pxM0->m.f23 = pxM1->m.f23;
    pxM0->m.f31 = pxM1->m.f31; pxM0->m.f32 = pxM1->m.f32; pxM0->m.f33 = pxM1->m.f33;
}


/* ---- M(F_SET_T) ------------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_SET_T)( M(PCU_TgMAT) pxM0, V(CPCU_TgVEC) pvS0 )
{
    pxM0->m.f14 = pvS0->m_aData[0];
    pxM0->m.f24 = pvS0->m_aData[1];
    pxM0->m.f34 = pvS0->m_aData[2];
}


/* ---- M(FS_SET_T) ------------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(FS_SET_T)( M(PCU_TgMAT) pxM0, const TYPE fX, const TYPE fY, const TYPE fZ )
{
    pxM0->m.f14 = fX;
    pxM0->m.f24 = fY;
    pxM0->m.f34 = fZ;
}