Home

Resume

Blog

Teikitu


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

/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
/*  TgS Common - Math API [Matrix] [F] */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */

/* ---- M(F_INIT_ROT) --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_INIT_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.f14 = MKL(0.0);
    pxM0->m.f21 = pxM1->m.f21; pxM0->m.f22 = pxM1->m.f22; pxM0->m.f23 = pxM1->m.f23; pxM0->m.f24 = MKL(0.0);
    pxM0->m.f31 = pxM1->m.f31; pxM0->m.f32 = pxM1->m.f32; pxM0->m.f33 = pxM1->m.f33; pxM0->m.f34 = MKL(0.0);
    pxM0->m.f41 = MKL(0.0); pxM0->m.f42 = MKL(0.0); pxM0->m.f43 = MKL(0.0); pxM0->m.f44 = MKL(1.0);
}

/* ---- M(F_INIT_T) ----------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_INIT_T)( M(PCU_TgMAT) pxM0, V(CPCU_TgVEC) pvS0 )
{
    pxM0->m.f11 = MKL(1.0); pxM0->m.f12 = MKL(0.0); pxM0->m.f13 = MKL(0.0); pxM0->m.f14 = pvS0->m_aData[0];
    pxM0->m.f21 = MKL(0.0); pxM0->m.f22 = MKL(1.0); pxM0->m.f23 = MKL(0.0); pxM0->m.f24 = pvS0->m_aData[1];
    pxM0->m.f31 = MKL(0.0); pxM0->m.f32 = MKL(0.0); pxM0->m.f33 = MKL(1.0); pxM0->m.f34 = pvS0->m_aData[2];
    pxM0->m.f41 = MKL(0.0); pxM0->m.f42 = MKL(0.0); pxM0->m.f43 = MKL(0.0); pxM0->m.f44 = MKL(1.0);
}


/* ---- M(FS_INIT_T) ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(FS_INIT_T)( M(PCU_TgMAT) pxM0, const TYPE fX, const TYPE fY, const TYPE fZ )
{
    pxM0->m.f11 = MKL(1.0); pxM0->m.f12 = MKL(0.0); pxM0->m.f13 = MKL(0.0); pxM0->m.f14 = fX;
    pxM0->m.f21 = MKL(0.0); pxM0->m.f22 = MKL(1.0); pxM0->m.f23 = MKL(0.0); pxM0->m.f24 = fY;
    pxM0->m.f31 = MKL(0.0); pxM0->m.f32 = MKL(0.0); pxM0->m.f33 = MKL(1.0); pxM0->m.f34 = fZ;
    pxM0->m.f41 = MKL(0.0); pxM0->m.f42 = MKL(0.0); pxM0->m.f43 = MKL(0.0); pxM0->m.f44 = MKL(1.0);
}


/* ---- M(F_Init_Euler) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_Init_Euler)( M(PCU_TgMAT) pxRet, V(CPCU_TgVEC) pvEul )
{
    M(FS_Set_Euler)( pxRet, pvEul->m.x, pvEul->m.y, pvEul->m.z );
    pxRet->m.f14 = MKL(0.0);
    pxRet->m.f24 = MKL(0.0);
    pxRet->m.f34 = MKL(0.0);
    pxRet->m_avRow[3] = V(KTgV_UNIT_W);
}


/* ---- M(FS_Init_Euler) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(FS_Init_Euler)( M(PCU_TgMAT) pxRet, const TYPE  fX, const TYPE  fY, const TYPE  fZ )
{
    M(FS_Set_Euler)( pxRet, fX, fY, fZ );
    pxRet->m.f14 = MKL(0.0);
    pxRet->m.f24 = MKL(0.0);
    pxRet->m.f34 = MKL(0.0);
    pxRet->m_avRow[3] = V(KTgV_UNIT_W);
}


/* ---- M(FS_Init_EulerX) ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(FS_Init_EulerX)( M(PCU_TgMAT) pxRet, const TYPE  fX )
{
    M(FS_Set_EulerX)( pxRet, fX );
    pxRet->m.f14 = MKL(0.0);
    pxRet->m.f24 = MKL(0.0);
    pxRet->m.f34 = MKL(0.0);
    pxRet->m_avRow[3] = V(KTgV_UNIT_W);
}


/* ---- M(FS_Init_EulerY) ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(FS_Init_EulerY)( M(PCU_TgMAT) pxRet, const TYPE  fY )
{
    M(FS_Set_EulerY)( pxRet, fY );
    pxRet->m.f14 = MKL(0.0);
    pxRet->m.f24 = MKL(0.0);
    pxRet->m.f34 = MKL(0.0);
    pxRet->m_avRow[3] = V(KTgV_UNIT_W);
}


/* ---- M(FS_Init_EulerZ) ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(FS_Init_EulerZ)( M(PCU_TgMAT) pxRet, const TYPE fZ )
{
    M(FS_Set_EulerZ)( pxRet, fZ );
    pxRet->m.f14 = MKL(0.0);
    pxRet->m.f24 = MKL(0.0);
    pxRet->m.f34 = MKL(0.0);
    pxRet->m_avRow[3] = V(KTgV_UNIT_W);
}


/* ---- M(F_Init_Quat) -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_Init_Quat)( M(PCU_TgMAT) pxRet, V(CPCU_TgVEC) pqR0 )
{
    M(F_Set_Quat)( pxRet, pqR0 );
    pxRet->m.f14 = MKL(0.0);
    pxRet->m.f24 = MKL(0.0);
    pxRet->m.f34 = MKL(0.0);
    pxRet->m_avRow[3] = V(KTgV_UNIT_W);
}


/* ---- M(F_CAT) -------------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_CAT)( M(PCU_TgMAT) pxRet, M(CPCU_TgMAT) pxM0, M(CPCU_TgMAT) pxM1 )
{
    M(F_CAT_IMPL)( pxRet, pxM0, pxM1 );
}


/* ---- M(F_INV_DET) ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_INV_DET)( M(PCU_TgMAT) pxRet, const TYPE fDet, M(CPCU_TgMAT) pxM1 )
{
    M(F_INV_DET_IMPL)(pxRet, fDet, pxM1);
}


/* ---- M(F_INV) -------------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_INV)( M(PCU_TgMAT) pxRet, M(CPCU_TgMAT) pxM1 )
{
    M(F_INV_DET)( pxRet, M(F_DET)(pxM1), pxM1 );
}


/* ---- M(F_DET) -------------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE M(F_DET)( M(CPCU_TgMAT) pxM1 )
{
    return (
          pxM1->m.f11*(pxM1->m.f22*(pxM1->m.f33*pxM1->m.f44 - pxM1->m.f34*pxM1->m.f43)
                        + pxM1->m.f23*(pxM1->m.f34*pxM1->m.f42 - pxM1->m.f32*pxM1->m.f44)
                        + pxM1->m.f24*(pxM1->m.f32*pxM1->m.f43 - pxM1->m.f33*pxM1->m.f42))
        - pxM1->m.f12*(pxM1->m.f21*(pxM1->m.f33*pxM1->m.f44 - pxM1->m.f34*pxM1->m.f43)
                        + pxM1->m.f23*(pxM1->m.f34*pxM1->m.f41 - pxM1->m.f31*pxM1->m.f44)
                        + pxM1->m.f24*(pxM1->m.f31*pxM1->m.f43 - pxM1->m.f33*pxM1->m.f41))
        + pxM1->m.f13*(pxM1->m.f21*(pxM1->m.f32*pxM1->m.f44 - pxM1->m.f34*pxM1->m.f42)
                        + pxM1->m.f22*(pxM1->m.f34*pxM1->m.f41 - pxM1->m.f31*pxM1->m.f44)
                        + pxM1->m.f24*(pxM1->m.f31*pxM1->m.f42 - pxM1->m.f32*pxM1->m.f41))
        - pxM1->m.f14*(pxM1->m.f21*(pxM1->m.f32*pxM1->m.f43 - pxM1->m.f33*pxM1->m.f42)
                        + pxM1->m.f22*(pxM1->m.f33*pxM1->m.f41 - pxM1->m.f31*pxM1->m.f43)
                        + pxM1->m.f23*(pxM1->m.f31*pxM1->m.f42 - pxM1->m.f32*pxM1->m.f41))
    );
}


/* ---- M(F_TX) --------------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) M(F_TX)( M(CPCU_TgMAT) ptxM0, V(CPCU_TgVEC) pvX0 )
{
    V(TgVEC)                            vRet;

    vRet.m.x = V(F_DOT)( ptxM0->m_avRow + 0, pvX0 );
    vRet.m.y = V(F_DOT)( ptxM0->m_avRow + 1, pvX0 );
    vRet.m.z = V(F_DOT)( ptxM0->m_avRow + 2, pvX0 );
    vRet.m.w = V(F_DOT)( ptxM0->m_avRow + 3, pvX0 );

    return (vRet);
}


/* ---- M(F_TX_P) ------------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) M(F_TX_P)( M(CPCU_TgMAT) pxTX, V(CPCU_TgVEC) pv3 )
{
    V(TgVEC)                            vRet;

    vRet.m.x = V( F_DOT3 )(pxTX->m_avRow + 0, pv3) + pxTX->m.f14;
    vRet.m.y = V( F_DOT3 )(pxTX->m_avRow + 1, pv3) + pxTX->m.f24;
    vRet.m.z = V( F_DOT3 )(pxTX->m_avRow + 2, pv3) + pxTX->m.f34;
    vRet.m.w = MKL(1.0);

    return (vRet);
}


/* ---- M(F_TX_V) ------------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) M(F_TX_V)( M(CPCU_TgMAT) pxTX, V(CPCU_TgVEC) pv3 )
{
    V(TgVEC)                            vRet;

    vRet.m.x = V( F_DOT3 )(pxTX->m_avRow + 0, pv3);
    vRet.m.y = V( F_DOT3 )(pxTX->m_avRow + 1, pv3);
    vRet.m.z = V( F_DOT3 )(pxTX->m_avRow + 2, pv3);
    vRet.m.w = MKL(0.0);

    return (vRet);
}


/* ---- M(F_Get_Col_0) -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) M(F_Get_Col_0)( M(CPCU_TgMAT) pxM0 )
{
    return (V(FS_SET)(pxM0->m.f11, pxM0->m.f21, pxM0->m.f31, pxM0->m.f41));
}


/* ---- M(F_Get_Col_1) -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) M(F_Get_Col_1)( M(CPCU_TgMAT) pxM0 )
{
    return (V(FS_SET)(pxM0->m.f12, pxM0->m.f22, pxM0->m.f32, pxM0->m.f42));
}


/* ---- M(F_Get_Col_2) -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) M(F_Get_Col_2)( M(CPCU_TgMAT) pxM0 )
{
    return (V(FS_SET)(pxM0->m.f13, pxM0->m.f23, pxM0->m.f33, pxM0->m.f43));
}


/* ---- M(F_Get_Col_3) -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) M(F_Get_Col_3)( M(CPCU_TgMAT) pxM0 )
{
    return (V(FS_SET)(pxM0->m.f14, pxM0->m.f24, pxM0->m.f34, pxM0->m.f44));
}


/* ---- M(FS_Matrix2Euler) ------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(FS_Matrix2Euler)( TYPE* pfX, TYPE* pfY, TYPE* pfZ, M(CPC_TgMAT) pxR0 )
{
    M34(FS_Matrix2Euler)( pfX, pfY, pfZ, (M34(CP_TgMAT))pxR0 );
}


/* ---- M(F_Matrix2Euler) ------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_Matrix2Euler)( V(PCU_TgVEC) pvEul, M(CPC_TgMAT) pxR0 )
{
    M34(F_Matrix2Euler)( pvEul, (M34(CP_TgMAT))pxR0 );
}


/* ---- M(F_Matrix2Quat) ------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_Matrix2Quat)( V(PCU_TgVEC) pvEul, M(CPC_TgMAT) pxR0 )
{
    M34(F_Matrix2Quat)( pvEul, (M34(CP_TgMAT))pxR0 );
}


/* ---- M(F_Init_Basis_From_Vector) ------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_Init_Basis_From_Vector)( M(PCU_TgMAT) pxRet, V(CPCU_TgVEC) pvAxis )
{
    M34(F_Init_Basis_From_Vector)( (M34(P_TgMAT))pxRet, pvAxis );
    pxRet->m_avRow[3] = V(KTgV_UNIT_W);
}




/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
/*  TgS Common - Math API [Matrix] [F] [44] */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */

/* ---- V(F_CAT_34_44) -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_CAT_34_44)( M(PCU_TgMAT) pxM0, M34(CPCU_TgMAT) pxM1, M(CPCU_TgMAT) pxM2 )
{
    TgUINT32                            ui0;

    for (ui0 = 0; ui0 < 3; ++ui0)
    {
        pxM0->m_aRowCol[ui0][0] =  pxM1->m_aRowCol[ui0][0] * pxM2->m_aRowCol[0][0]
                                   +  pxM1->m_aRowCol[ui0][1] * pxM2->m_aRowCol[1][0]
                                   +  pxM1->m_aRowCol[ui0][2] * pxM2->m_aRowCol[2][0]
                                   +  pxM1->m_aRowCol[ui0][3] * pxM2->m_aRowCol[3][0];
        pxM0->m_aRowCol[ui0][1] =  pxM1->m_aRowCol[ui0][0] * pxM2->m_aRowCol[0][1]
                                   +  pxM1->m_aRowCol[ui0][1] * pxM2->m_aRowCol[1][1]
                                   +  pxM1->m_aRowCol[ui0][2] * pxM2->m_aRowCol[2][1]
                                   +  pxM1->m_aRowCol[ui0][3] * pxM2->m_aRowCol[3][1];
        pxM0->m_aRowCol[ui0][2] =  pxM1->m_aRowCol[ui0][0] * pxM2->m_aRowCol[0][2]
                                   +  pxM1->m_aRowCol[ui0][1] * pxM2->m_aRowCol[1][2]
                                   +  pxM1->m_aRowCol[ui0][2] * pxM2->m_aRowCol[2][2]
                                   +  pxM1->m_aRowCol[ui0][3] * pxM2->m_aRowCol[3][2];
        pxM0->m_aRowCol[ui0][3] =  pxM1->m_aRowCol[ui0][0] * pxM2->m_aRowCol[0][3]
                                   +  pxM1->m_aRowCol[ui0][1] * pxM2->m_aRowCol[1][3]
                                   +  pxM1->m_aRowCol[ui0][2] * pxM2->m_aRowCol[2][3]
                                   +  pxM1->m_aRowCol[ui0][3] * pxM2->m_aRowCol[3][3];
    };

    pxM0->m_avRow[3] = pxM2->m_avRow[3];
}


/* ---- V(F_CAT_44_34) -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_CAT_44_34)( M(PCU_TgMAT) pxM0, M(CPCU_TgMAT) pxM1, M34(CPCU_TgMAT) pxM2 )
{
    TgUINT32                            ui0;

    for (ui0 = 0; ui0 < 4; ++ui0)
    {
        pxM0->m_aRowCol[ui0][0] =  pxM1->m_aRowCol[ui0][0] * pxM2->m_aRowCol[0][0]
                                   +  pxM1->m_aRowCol[ui0][1] * pxM2->m_aRowCol[1][0]
                                   +  pxM1->m_aRowCol[ui0][2] * pxM2->m_aRowCol[2][0];

        pxM0->m_aRowCol[ui0][1] =  pxM1->m_aRowCol[ui0][0] * pxM2->m_aRowCol[0][1]
                                   +  pxM1->m_aRowCol[ui0][1] * pxM2->m_aRowCol[1][1]
                                   +  pxM1->m_aRowCol[ui0][2] * pxM2->m_aRowCol[2][1];

        pxM0->m_aRowCol[ui0][2] =  pxM1->m_aRowCol[ui0][0] * pxM2->m_aRowCol[0][2]
                                   +  pxM1->m_aRowCol[ui0][1] * pxM2->m_aRowCol[1][2]
                                   +  pxM1->m_aRowCol[ui0][2] * pxM2->m_aRowCol[2][2];

        pxM0->m_aRowCol[ui0][3] =  pxM1->m_aRowCol[ui0][0] * pxM2->m_aRowCol[0][3]
                                   +  pxM1->m_aRowCol[ui0][1] * pxM2->m_aRowCol[1][3]
                                   +  pxM1->m_aRowCol[ui0][2] * pxM2->m_aRowCol[2][3]
                                   +  pxM1->m_aRowCol[ui0][3];
    };
}


/* ---- V(F_TR) --------------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_TR)( M(PCU_TgMAT) pxTX, M(CPCU_TgMAT) pxM0 )
{
    pxTX->m_aRowCol[0][0] = pxM0->m_aRowCol[0][0];
    pxTX->m_aRowCol[0][1] = pxM0->m_aRowCol[1][0];
    pxTX->m_aRowCol[0][2] = pxM0->m_aRowCol[2][0];
    pxTX->m_aRowCol[0][3] = pxM0->m_aRowCol[3][0];

    pxTX->m_aRowCol[1][0] = pxM0->m_aRowCol[0][1];
    pxTX->m_aRowCol[1][1] = pxM0->m_aRowCol[1][1];
    pxTX->m_aRowCol[1][2] = pxM0->m_aRowCol[2][1];
    pxTX->m_aRowCol[1][3] = pxM0->m_aRowCol[3][1];

    pxTX->m_aRowCol[2][0] = pxM0->m_aRowCol[0][2];
    pxTX->m_aRowCol[2][1] = pxM0->m_aRowCol[1][2];
    pxTX->m_aRowCol[2][2] = pxM0->m_aRowCol[2][2];
    pxTX->m_aRowCol[2][3] = pxM0->m_aRowCol[3][2];

    pxTX->m_aRowCol[3][0] = pxM0->m_aRowCol[0][3];
    pxTX->m_aRowCol[3][1] = pxM0->m_aRowCol[1][3];
    pxTX->m_aRowCol[3][2] = pxM0->m_aRowCol[2][3];
    pxTX->m_aRowCol[3][3] = pxM0->m_aRowCol[3][3];
}


/* ---- V(F_LookLH) ----------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_LookLH)( M(PCU_TgMAT) pxRet, V(CPCU_TgVEC) pvFrom, V(CPCU_TgVEC) pvTo, V(CPCU_TgVEC) pvUp )
{
    V(TgVEC)                            tvLook, tvRight, tvCamUp;
    TYPE                                fLength;

    /* VectorNorm and Build Orthonormal Camera Axis */
    tvLook = V(F_SUB)( pvTo, pvFrom );
    tvLook = V(F_NORM_LEN)( &fLength, &tvLook );
    if (F(tgCM_NR0)(fLength))
    {
        M(F_CLI)(pxRet);
        return;
    };

    tvRight = V(F_UCX_LEN)( &fLength, pvUp, &tvLook );
    if (F(tgCM_NR0)(fLength))
    {
        M(F_CLI)(pxRet);
        return;
    };

    tvCamUp = V(F_CX)( &tvLook, &tvRight );

    pxRet->m.f11 = tvRight.m.x;  pxRet->m.f21 = tvRight.m.y;  pxRet->m.f31 = tvRight.m.z;  pxRet->m.f41 = -V(F_DOT)( &tvRight, pvFrom );
    pxRet->m.f12 = tvCamUp.m.x;  pxRet->m.f22 = tvCamUp.m.y;  pxRet->m.f32 = tvCamUp.m.z;  pxRet->m.f42 = -V(F_DOT)( &tvCamUp, pvFrom );
    pxRet->m.f13 = tvLook.m.x;   pxRet->m.f23 = tvLook.m.y;   pxRet->m.f33 = tvLook.m.z;   pxRet->m.f43 = -V(F_DOT)( &tvLook, pvFrom );
    pxRet->m.f14 = MKL(0.0);     pxRet->m.f24 = MKL(0.0);     pxRet->m.f34 = MKL(0.0);     pxRet->m.f44 = MKL(1.0);
}


/* ---- V(F_LookRH) ----------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_LookRH)( M(PCU_TgMAT) pxRet, V(CPCU_TgVEC) pvFrom, V(CPCU_TgVEC) pvTo, V(CPCU_TgVEC) pvUp )
{
    V(TgVEC)                            tvLook, tvRight, tvCamUp;
    TYPE                                fLength;

    /* VectorNorm and Build Orthonormal Camera Axis */
    tvLook = V(F_SUB)( pvFrom, pvTo );
    tvLook = V(F_NORM_LEN)( &fLength, &tvLook );
    if (F(tgCM_NR0)(fLength))
    {
        M(F_CLI)(pxRet);
        return;
    };

    tvRight = V(F_UCX_LEN)( &fLength, pvUp, &tvLook );
    if (F(tgCM_NR0)(fLength))
    {
        M(F_CLI)(pxRet);
        return;
    };

    tvCamUp = V(F_CX)( &tvLook, &tvRight );

    pxRet->m.f11 = tvRight.m.x;  pxRet->m.f21 = tvRight.m.y;  pxRet->m.f31 = tvRight.m.z;  pxRet->m.f41 = V(F_DOT)( &tvRight, pvFrom );
    pxRet->m.f12 = tvCamUp.m.x;  pxRet->m.f22 = tvCamUp.m.y;  pxRet->m.f32 = tvCamUp.m.z;  pxRet->m.f42 = V(F_DOT)( &tvCamUp, pvFrom );
    pxRet->m.f13 = tvLook.m.x;   pxRet->m.f23 = tvLook.m.y;   pxRet->m.f33 = tvLook.m.z;   pxRet->m.f43 = V(F_DOT)( &tvLook, pvFrom );
    pxRet->m.f14 = MKL(0.0);     pxRet->m.f24 = MKL(0.0);     pxRet->m.f34 = MKL(0.0);     pxRet->m.f44 = MKL(1.0);
}


/* ---- V(F_Look) ------------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_Look)( M(PCU_TgMAT) pxRet, V(CPCU_TgVEC) pvFrom, V(CPCU_TgVEC) pvTo, V(CPCU_TgVEC) pvUp )
{
    M(F_LookLH)(pxRet, pvFrom, pvTo, pvUp);
}


/* ---- V(FS_PProjLH) --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(FS_PProjLH)( M(PCU_TgMAT) pxRet, const TYPE fViewWidth, const TYPE fViewHeight, const TYPE fMinZ, const TYPE fMaxZ )
{
    const TYPE                          fZR = fMaxZ - fMinZ;
    const TYPE                          fFoVx = (fMinZ + fMinZ) / fViewWidth;
    const TYPE                          fFoVy = (fMinZ + fMinZ) / fViewHeight;
    const TYPE                          fFoVz = fMaxZ * (fZR > MKL(0.0) ? MKL(1.0) / fZR : MKL(0.0));

    M(F_CLR)(pxRet);

    pxRet->m.f11 = fFoVx;
    pxRet->m.f22 = fFoVy;
    pxRet->m.f33 = fFoVz;
    pxRet->m.f34 = MKL(1.0);
    pxRet->m.f43 = -fFoVz * fMinZ;
}


/* ---- V(FS_PProjRH) --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(FS_PProjRH)( M(PCU_TgMAT) pxRet, const TYPE fViewWidth, const TYPE fViewHeight, const TYPE fMinZ, const TYPE fMaxZ )
{
    const TYPE                          fZR = fMinZ - fMaxZ;
    const TYPE                          fFoVx = MKL(2.0) * fMinZ / fViewWidth;
    const TYPE                          fFoVy = MKL(2.0) * fMinZ / fViewHeight;
    const TYPE                          fFoVz = fMaxZ * (fZR > MKL(0.0) ? MKL(1.0) / fZR : MKL(0.0));

    M(F_CLR)(pxRet);

    pxRet->m.f11 = fFoVx;
    pxRet->m.f22 = fFoVy;
    pxRet->m.f33 = fFoVz;
    pxRet->m.f34 = -MKL(1.0);
    pxRet->m.f43 = fFoVz * fMinZ;
}


/* ---- V(FS_PProj) ----------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(FS_PProj)( M(PCU_TgMAT) pxRet, const TYPE fViewWidth, const TYPE fViewHeight, const TYPE fMinZ, const TYPE fMaxZ )
{
    M(FS_PProjLH)(pxRet, fViewWidth, fViewHeight, fMinZ, fMaxZ);
}


/* ---- V(FS_PProj_OffsetLH) -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(FS_PProj_OffsetLH)(  M(PCU_TgMAT) pxRet, const TYPE fRight, const TYPE fLeft, const TYPE fTop, const TYPE fBottom, const TYPE fMinZ, const TYPE fMaxZ )
{
    const TYPE                          fXR = fRight - fLeft;
    const TYPE                          fYR = fTop - fBottom;
    const TYPE                          fZR = fMaxZ - fMinZ;
    const TYPE                          fFoVx = MKL(2.0) * fMinZ * (fXR > MKL(0.0) ? MKL(1.0) / fXR : MKL(0.0));
    const TYPE                          fFoVy = MKL(2.0) * fMinZ * (fYR > MKL(0.0) ? MKL(1.0) / fYR : MKL(0.0));
    const TYPE                          fFoVz = fMaxZ * (fZR > MKL(0.0) ? MKL(1.0) / fZR : MKL(0.0));

    M(F_CLR)(pxRet);

    pxRet->m.f11 = fFoVx;
    pxRet->m.f22 = fFoVy;
    pxRet->m.f31 = (fLeft + fRight) * (fXR > MKL(0.0) ? MKL(-1.0) / fXR : MKL(0.0));
    pxRet->m.f32 = (fTop + fBottom) * (fYR > MKL(0.0) ? MKL(-1.0) / fYR : MKL(0.0));
    pxRet->m.f33 = fFoVz;
    pxRet->m.f34 = MKL(1.0);
    pxRet->m.f43 = -fFoVz * fMinZ;
}


/* ---- V(FS_PProj_OffsetRH) -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(FS_PProj_OffsetRH)(  M(PCU_TgMAT) pxRet, const TYPE fRight, const TYPE fLeft, const TYPE fTop, const TYPE fBottom, const TYPE fMinZ, const TYPE fMaxZ )
{
    const TYPE                          fXR = fRight - fLeft;
    const TYPE                          fYR = fTop - fBottom;
    const TYPE                          fZR = fMaxZ - fMinZ;
    const TYPE                          fFoVx = MKL(2.0) * fMinZ * (fXR > MKL(0.0) ? MKL(1.0) / fXR : MKL(0.0));
    const TYPE                          fFoVy = MKL(2.0) * fMinZ * (fYR > MKL(0.0) ? MKL(1.0) / fYR : MKL(0.0));
    const TYPE                          fFoVz = fMaxZ * (fZR > MKL(0.0) ? MKL(1.0) / fZR : MKL(0.0));

    M(F_CLR)(pxRet);

    pxRet->m.f11 = fFoVx;
    pxRet->m.f22 = fFoVy;
    pxRet->m.f31 = (fLeft + fRight) * (fXR > MKL(0.0) ? MKL(1.0) / fXR : MKL(0.0));
    pxRet->m.f32 = (fTop + fBottom) * (fYR > MKL(0.0) ? MKL(1.0) / fYR : MKL(0.0));
    pxRet->m.f33 = fFoVz;
    pxRet->m.f34 = -MKL(1.0);
    pxRet->m.f43 = fFoVz * fMinZ;
}


/* ---- V(FS_PProj_Offset) ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(FS_PProj_Offset)(  M(PCU_TgMAT) pxRet, const TYPE fRight, const TYPE fLeft, const TYPE fTop, const TYPE fBottom, const TYPE fMinZ, const TYPE fMaxZ )
{
    M(FS_PProj_OffsetLH)(pxRet, fRight, fLeft, fTop, fBottom, fMinZ, fMaxZ);
}


/* ---- V(FS_PProj_FoVLH) ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(FS_PProj_FoVLH)( M(PCU_TgMAT) pxRet, const TYPE fFoV, const TYPE fAspect, const TYPE fMinZ, const TYPE fMaxZ )
{
    const TYPE                          fFoVy = MKL(1.0) / F(tgPM_TAN)( MKL(0.5) * fFoV );
    const TYPE                          fFoVx = fFoVy / fAspect;
    const TYPE                          fZR = fMaxZ - fMinZ;
    const TYPE                          fFoVz = fMaxZ * (fZR > MKL(0.0) ? MKL(1.0) / fZR : MKL(0.0));

    M(F_CLR)(pxRet);

    pxRet->m.f11 = fFoVx;
    pxRet->m.f22 = fFoVy;
    pxRet->m.f33 = fFoVz;
    pxRet->m.f34 = MKL(1.0);
    pxRet->m.f43 = -fFoVz * fMinZ;
}


/* ---- V(FS_PProj_FoVRH) ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(FS_PProj_FoVRH)( M(PCU_TgMAT) pxRet, const TYPE fFoV, const TYPE fAspect, const TYPE fMinZ, const TYPE fMaxZ )
{

    const TYPE                          fFoVy = MKL(1.0) / F(tgPM_TAN)( MKL(0.5) * fFoV );
    const TYPE                          fFoVx = fFoVy / fAspect;
    const TYPE                          fZR = fMaxZ - fMinZ;
    const TYPE                          fFoVz = fMaxZ * (fZR > MKL(0.0) ? MKL(1.0) / fZR : MKL(0.0));

    M(F_CLR)(pxRet);

    pxRet->m.f11 = fFoVx;
    pxRet->m.f22 = fFoVy;
    pxRet->m.f33 = fFoVz;
    pxRet->m.f34 = MKL(-1.0);
    pxRet->m.f43 = fFoVz * fMinZ;
}


/* ---- V(FS_PProj_FoV) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(FS_PProj_FoV)( M(PCU_TgMAT) pxRet, const TYPE fFoV, const TYPE fAspect, const TYPE fMinZ, const TYPE fMaxZ )
{
    M(FS_PProj_FoVLH)(pxRet, fFoV, fAspect, fMinZ, fMaxZ);
}


/* ---- V(FS_OrthoLH) --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
CLANG_WARN_DISABLE_PUSH(float-equal)
TgINLINE TgVOID M(FS_OrthoLH)( M(PCU_TgMAT) pxRet, const TYPE fViewWidth, const TYPE fViewHeight, const TYPE fMinZ, const TYPE fMaxZ )
{
    if ((MKL(0.0) == fViewWidth) || (MKL(0.0) == fViewHeight) || (fMinZ == fMaxZ))
    {
        TgWARNING_MSGF( TgFALSE, TgT("%-16.16s(%-32.32s): Invalid Function Parameter\n"), TgT("Matrix API"), TgT("F_OrthoLH") );
        M(F_CLR)(pxRet);
    }
    else
    {
        TYPE                                fFoVz = MKL(1.0) / (fMaxZ - fMinZ);

        M(F_CLI)(pxRet);

        pxRet->m.f11 = MKL(2.0) / fViewWidth;
        pxRet->m.f22 = MKL(2.0) / fViewHeight;
        pxRet->m.f33 = fFoVz;
        pxRet->m.f43 = -fFoVz * fMinZ;
        pxRet->m.f44 = MKL(1.0);
    };
}
CLANG_WARN_DISABLE_POP(float-equal)


/* ---- V(FS_OrthoRH) --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
CLANG_WARN_DISABLE_PUSH(float-equal)
TgINLINE TgVOID M(FS_OrthoRH)( M(PCU_TgMAT) pxRet, const TYPE fViewWidth, const TYPE fViewHeight, const TYPE fMinZ, const TYPE fMaxZ )
{
    if ((MKL(0.0) == fViewWidth) || (MKL(0.0) == fViewHeight) || (fMinZ == fMaxZ))
    {
        TgWARNING_MSGF( 0, TgT("%-16.16s(%-32.32s): Invalid Function Parameter\n"), TgT("Matrix API"), TgT("F_OrthoLH") );
        M(F_CLR)(pxRet);
    }
    else
    {
        TYPE                                fFoVz = MKL(1.0) / (fMinZ - fMaxZ);

        M(F_CLI)(pxRet);

        pxRet->m.f11 = MKL(2.0) / fViewWidth;
        pxRet->m.f22 = MKL(2.0) / fViewHeight;
        pxRet->m.f33 = fFoVz;
        pxRet->m.f43 = fFoVz * fMinZ;
        pxRet->m.f44 = MKL(1.0);
    };
}
CLANG_WARN_DISABLE_POP(float-equal)


/* ---- V(FS_Ortho) ----------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(FS_Ortho)( M(PCU_TgMAT) pxRet, const TYPE fViewWidth, const TYPE fViewHeight, const TYPE fMinZ, const TYPE fMaxZ )
{
    M(FS_OrthoLH)(pxRet, fViewWidth, fViewHeight, fMinZ, fMaxZ);
}


/* ---- V(FS_Ortho_OffsetLH) -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
CLANG_WARN_DISABLE_PUSH(float-equal)
TgINLINE TgVOID M(FS_Ortho_OffsetLH)(  M(PCU_TgMAT) pxRet, const TYPE fRight, const TYPE fLeft, const TYPE fTop, const TYPE fBottom, const TYPE fMinZ, const TYPE fMaxZ )
{
    if ((fRight == fLeft) || (fTop == fBottom) || (fMinZ == fMaxZ))
    {
        TgWARNING_MSGF( 0, TgT("%-16.16s(%-32.32s): Invalid Function Parameter\n"), TgT("Matrix API"), TgT("F_OrthoLH") );
        M(F_CLR)(pxRet);
    }
    else
    {
        TYPE                                fFoVx = MKL(2.0) / (fRight - fLeft);
        TYPE                                fFoVy = MKL(2.0) / (fTop - fBottom);
        TYPE                                fFoVz = MKL(1.0) / (fMaxZ - fMinZ);

        M(F_CLI)(pxRet);

        pxRet->m.f11 = fFoVx;
        pxRet->m.f22 = fFoVy;
        pxRet->m.f33 = fFoVz;
        pxRet->m.f41 = (fLeft + fRight) / (fLeft - fRight);
        pxRet->m.f42 = (fTop + fBottom) / (fBottom - fTop);
        pxRet->m.f43 = -fFoVz * fMinZ;
        pxRet->m.f44 = MKL(1.0);
    };
}


/* ---- V(FS_Ortho_OffsetRH) -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
CLANG_WARN_DISABLE_PUSH(float-equal)
TgINLINE TgVOID M(FS_Ortho_OffsetRH)(  M(PCU_TgMAT) pxRet, const TYPE fRight, const TYPE fLeft, const TYPE fTop, const TYPE fBottom, const TYPE fMinZ, const TYPE fMaxZ )
{
    if ((fRight == fLeft) || (fTop == fBottom) || (fMinZ == fMaxZ))
    {
        TgWARNING_MSGF( 0, TgT("%-16.16s(%-32.32s): Invalid Function Parameter\n"), TgT("Matrix API"), TgT("F_OrthoLH") );
        M(F_CLR)(pxRet);
    }
    else
    {
        TYPE                                fFoVx = MKL(2.0) / (fRight - fLeft);
        TYPE                                fFoVy = MKL(2.0) / (fTop - fBottom);
        TYPE                                fFoVz = MKL(1.0) / (fMinZ - fMaxZ);

        M(F_CLI)(pxRet);

        pxRet->m.f11 = fFoVx;
        pxRet->m.f22 = fFoVy;
        pxRet->m.f33 = fFoVz;
        pxRet->m.f41 = (fLeft + fRight) / (fLeft - fRight);
        pxRet->m.f42 = (fTop + fBottom) / (fBottom - fTop);
        pxRet->m.f43 = fFoVz * fMinZ;
        pxRet->m.f44 = MKL(1.0);
    };
}
CLANG_WARN_DISABLE_POP(float-equal)


/* ---- V(FS_Ortho_Offset) ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(FS_Ortho_Offset)(  M(PCU_TgMAT) pxRet, const TYPE fRight, const TYPE fLeft, const TYPE fTop, const TYPE fBottom, const TYPE fMinZ, const TYPE fMaxZ
 )
{
    M(FS_Ortho_OffsetLH)(pxRet, fRight, fLeft, fTop, fBottom, fMinZ, fMaxZ);
}