Home

Resume

Blog

Teikitu


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

/* ---- 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];
}


/* ---- 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;
}


/* ---- 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);
}


/* ---- 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);
}


/* ---- 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);
}


/* ---- 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);
}


/* ---- 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);
}


/* ---- 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);
}


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

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

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

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

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


/* ---- M(F_INV_DET) ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_INV_DET)( M(PCU_TgMAT) pxRet, const TYPE fDet, M(CPCU_TgMAT) pxM1 )
{
    if (F(tgCM_NR0)(fDet))
    {
        TgERROR_MSGF( 0, TgT("%-16.16s(%-32.32s): Matrix is Singular - Zero Matrix returned.\n"), TgT("Math"), TgT("F_INV") );
        M(F_CLR)( pxRet );
    }
    else
    {
        const TYPE                              fInvDet = MKL(1.0) / fDet;

        pxRet->m.f11 = fInvDet*(pxM1->m.f22 * pxM1->m.f33 - pxM1->m.f23 * pxM1->m.f32);
        pxRet->m.f12 = -fInvDet*(pxM1->m.f12 * pxM1->m.f33 - pxM1->m.f13 * pxM1->m.f32);
        pxRet->m.f13 = fInvDet*(pxM1->m.f12 * pxM1->m.f23 - pxM1->m.f13 * pxM1->m.f22);
        pxRet->m.f14 = -(pxRet->m.f11*pxM1->m.f14 + pxRet->m.f12*pxM1->m.f24 + pxRet->m.f13*pxM1->m.f34);

        pxRet->m.f21 = -fInvDet*(pxM1->m.f21 * pxM1->m.f33 - pxM1->m.f23 * pxM1->m.f31);
        pxRet->m.f22 = fInvDet*(pxM1->m.f11 * pxM1->m.f33 - pxM1->m.f13 * pxM1->m.f31);
        pxRet->m.f23 = -fInvDet*(pxM1->m.f11 * pxM1->m.f23 - pxM1->m.f13 * pxM1->m.f21);
        pxRet->m.f24 = -(pxRet->m.f21*pxM1->m.f14 + pxRet->m.f22*pxM1->m.f24 + pxRet->m.f23*pxM1->m.f34);

        pxRet->m.f31 = fInvDet*(pxM1->m.f21 * pxM1->m.f32 - pxM1->m.f22 * pxM1->m.f31);
        pxRet->m.f32 = -fInvDet*(pxM1->m.f11 * pxM1->m.f32 - pxM1->m.f12 * pxM1->m.f31);
        pxRet->m.f33 = fInvDet*(pxM1->m.f11 * pxM1->m.f22 - pxM1->m.f12 * pxM1->m.f21);
        pxRet->m.f34 = -(pxRet->m.f31*pxM1->m.f14 + pxRet->m.f32*pxM1->m.f24 + pxRet->m.f33*pxM1->m.f34);
    };
}


/* ---- 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.f23*pxM1->m.f32) +
        pxM1->m.f12*(pxM1->m.f23*pxM1->m.f31 - pxM1->m.f21*pxM1->m.f33) +
        pxM1->m.f13*(pxM1->m.f21*pxM1->m.f32 - pxM1->m.f22*pxM1->m.f31)
    );
}


/* ---- 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 = pvX0->m.w;

    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, MKL(0.0)));
}


/* ---- 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, MKL(0.0)));
}


/* ---- 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, MKL(0.0)));
}


/* ---- 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, MKL(1.0)));
}


/* ---- M(FS_Matrix2Euler) ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(FS_Matrix2Euler)( TYPE* pfX, TYPE* pfY, TYPE* pfZ, M(CPC_TgMAT) pxR0 )
{
    if (MKL(1.0) - pxR0->m.f13 <= F(KTgEPS))
    {
        *pfX = F(tgPM_ATAN2)( pxR0->m.f21, pxR0->m.f31 );
        *pfY = -F(KTgF_HALF_PI);
        *pfZ = MKL(0.0);
    }
    else if (F(KTgEPS) >= MKL(1.0) + pxR0->m.f13)
    {
        *pfX = F(tgPM_ATAN2)( pxR0->m.f21, pxR0->m.f31 );
        *pfY = F(KTgF_HALF_PI);
        *pfZ = MKL(0.0);
    }
    else
    {
        *pfX = F(tgPM_ATAN2)( pxR0->m.f23, pxR0->m.f33 );
        *pfY = F(tgPM_ASIN)( -pxR0->m.f13 );
        *pfZ = F(tgPM_ATAN2)( pxR0->m.f12, pxR0->m.f11 );
    };
}


/* ---- M(F_Matrix2Euler) ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_Matrix2Euler)( V(PCU_TgVEC) pvEul, M(CPC_TgMAT) pxR0 )
{
    pvEul->m.w = MKL(0.0);
    M(FS_Matrix2Euler)( &pvEul->m.x, &pvEul->m.y, &pvEul->m.z, pxR0 );
}


/* ---- M(F_Matrix2Quat) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_Matrix2Quat)( V(PCU_TgVEC) pqR0, M(CPC_TgMAT) pxR0 )
{
    const TYPE                          fTrace = pxR0->m.f11 + pxR0->m.f22 + pxR0->m.f33;

    if (fTrace > F(KTgEPS))
    {
        const TYPE                          fSqrt = F(tgPM_SQRT)( fTrace + MKL(1.0) );
        const TYPE                          fScale = MKL(0.5) / fSqrt;

        pqR0->m.x = (pxR0->m.f32 - pxR0->m.f23)*fScale;
        pqR0->m.y = (pxR0->m.f13 - pxR0->m.f31)*fScale;
        pqR0->m.z = (pxR0->m.f21 - pxR0->m.f12)*fScale;
        pqR0->m.w = MKL(0.5)*fSqrt;
    }
    else
    {
        if (pxR0->m.f11 > pxR0->m.f22 && pxR0->m.f11 > pxR0->m.f33)
        {
            const TYPE                          fDiag = MKL(1.0) + pxR0->m.f11 - pxR0->m.f22 - pxR0->m.f33;
            const TYPE                          fSqrt = F(tgPM_SQRT)( fDiag );
            const TYPE                          fScale = MKL(0.5) / fSqrt;

            pqR0->m.x = MKL(0.5)*fSqrt;
            pqR0->m.y = (pxR0->m.f12 + pxR0->m.f21)*fScale;
            pqR0->m.z = (pxR0->m.f13 + pxR0->m.f31)*fScale;
            pqR0->m.w = (pxR0->m.f23 - pxR0->m.f32)*fScale;
        }
        else if (pxR0->m.f22 > pxR0->m.f33)
        {
            const TYPE                          fDiag = MKL(1.0) + pxR0->m.f22 - pxR0->m.f11 - pxR0->m.f33;
            const TYPE                          fSqrt = F(tgPM_SQRT)( fDiag );
            const TYPE                          fScale = MKL(0.5) / fSqrt;

            pqR0->m.x = (pxR0->m.f12 + pxR0->m.f21)*fScale;
            pqR0->m.y = MKL(0.5)*fSqrt;
            pqR0->m.z = (pxR0->m.f23 + pxR0->m.f32)*fScale;
            pqR0->m.w = (pxR0->m.f13 - pxR0->m.f31)*fScale;
        }
        else
        {
            const TYPE                          fDiag = MKL(1.0) + pxR0->m.f33 - pxR0->m.f11 - pxR0->m.f22;
            const TYPE                          fSqrt = F(tgPM_SQRT)( fDiag );
            const TYPE                          fScale = MKL(0.5) / fSqrt;

            pqR0->m.x = (pxR0->m.f13 + pxR0->m.f31)*fScale;
            pqR0->m.y = (pxR0->m.f23 + pxR0->m.f32)*fScale;
            pqR0->m.z = MKL(0.5)*fSqrt;
            pqR0->m.w = (pxR0->m.f12 - pxR0->m.f21)*fScale;
        };
    };
}


/* ---- M(F_Init_Basis_From_Vector) ------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_Init_Basis_From_Vector)( M(PCU_TgMAT) pxRet, V(CPCU_TgVEC) pvAxis )
{
    const TYPE fXZ = F(tgPM_SQRT)( pvAxis->m_aData[0] * pvAxis->m_aData[0] + pvAxis->m_aData[2] * pvAxis->m_aData[2] );

    TgERROR((V(F_Is_Vector_Valid)(pvAxis)) && (F(tgCM_NR1)(V(F_LSQ)(pvAxis))));

    if (F(tgCM_NR0)(fXZ))
    {
        /* The parameter axis is within absolute tolerance of the standard ortho-normal definition (y-axis) It is sufficient to return the identity basis.  The identity */
        /* function can not be used since the matrix being used could include other information (like translation) which should not be destroyed. */

        M(F_CLI)(pxRet);
    }
    else
    {
        const TYPE                          fInvXZ = MKL(1.0) / fXZ;

        /*  Since the axis is known to be different from the standard y-axis - it is trivial to construct another basis vector by taking the cross product of the two */
        /* vectors.  Simplified this becomes: */

        pxRet->m.f11 = -pvAxis->m.z * fInvXZ;
        pxRet->m.f12 = pvAxis->m.x;
        pxRet->m.f13 = -pvAxis->m.x*pvAxis->m.y;
        pxRet->m.f14 = MKL(0.0);

        pxRet->m.f21 = MKL(0.0);
        pxRet->m.f22 = pvAxis->m.y;
        pxRet->m.f23 = pvAxis->m.x*pvAxis->m.x + pvAxis->m.z*pvAxis->m.z;
        pxRet->m.f24 = MKL(0.0);

        pxRet->m.f31 = pvAxis->m.x * fInvXZ;
        pxRet->m.f32 = pvAxis->m.z;
        pxRet->m.f33 = -pvAxis->m.z*pvAxis->m.y;
        pxRet->m.f34 = MKL(0.0);
    };
}




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

/* ---- V(F_TR) --------------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID M(F_TR)( M44(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] = MKL(0.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] = MKL(0.0);

    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] = MKL(0.0);

    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] = MKL(1.0);
}


/* ---- M(F_LookLH_V4) -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
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.f12 = tvRight.m.y;  pxRet->m.f13 = tvRight.m.z;  pxRet->m.f14 = -V(F_DOT)(&tvRight, pvFrom);
    pxRet->m.f21 = tvCamUp.m.x;  pxRet->m.f22 = tvCamUp.m.y;  pxRet->m.f23 = tvCamUp.m.z;  pxRet->m.f24 = -V(F_DOT)(&tvCamUp, pvFrom);
    pxRet->m.f31 = tvLook.m.x;   pxRet->m.f32 = tvLook.m.y;   pxRet->m.f33 = tvLook.m.z;   pxRet->m.f34 = -V(F_DOT)(&tvLook, pvFrom);
}


/* ---- M(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.f12 = tvRight.m.y;  pxRet->m.f13 = tvRight.m.z;  pxRet->m.f14 = V(F_DOT)( &tvRight, pvFrom );
    pxRet->m.f21 = tvCamUp.m.x;  pxRet->m.f22 = tvCamUp.m.y;  pxRet->m.f23 = tvCamUp.m.z;  pxRet->m.f24 = V(F_DOT)( &tvCamUp, pvFrom );
    pxRet->m.f31 = tvLook.m.x;   pxRet->m.f32 = tvLook.m.y;   pxRet->m.f33 = tvLook.m.z;   pxRet->m.f34 = V(F_DOT)( &tvLook, pvFrom );
}


/* ---- M(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);
}