#include "../Common/Common.h"
#include "DisplayCommon.h"
const char * SAMPLE_FILENAME = "JointHierarchy.fbx";
int main(int argc, char** argv)
{
    bool lResult;
    
    InitializeSdkObjects(lSdkManager, lScene);    
    
    
    for( int i = 1, c = argc; i < c; ++i )
    {
        if( 
FbxString(argv[i]) == 
"-test" ) 
continue;
 
        else if( lFilePath.IsEmpty() ) lFilePath = argv[i];
    }
    if( lFilePath.IsEmpty() ) lFilePath = SAMPLE_FILENAME;
    FBXSDK_printf("\n\nFile: %s\n\n", lFilePath.Buffer());
    lResult = LoadScene(lSdkManager, lScene, lFilePath.Buffer());
    if(lResult == false)
    {
        FBXSDK_printf("\n\nAn error occurred while loading the scene...");
    }
    else
    {
        CompareTransformations( lScene->
GetRootNode(), lScene );
 
    }
    
    DestroySdkObjects(lSdkManager, lResult);
    return 0;
}
{
    {
        
        
        FbxAMatrix lParentTransform,lLocalTransform, lGlobalTransform;
 
        lGlobalTransform = CalculateGlobalTransform(pNode);
        if(lParentNode)
        {
            
            lParentTransform = CalculateGlobalTransform(lParentNode);
            
            lLocalTransform = lParentTransform.
Inverse() * lGlobalTransform;
 
        }
        else
            lLocalTransform = lGlobalTransform;
        
        if(lGlobal == lGlobalTransform)
        {
            for(int i = 0; i<4; ++i)
            {
                lHeader += lIndex;
                lHeader += ": ";
                Display4DVector(lHeader, lGlobal.
GetRow(i));
 
            }            
            FBXSDK_printf("\n");
        }
        else
        {
            FBXSDK_printf("Error: The two global transform results are not equal!\n");
            for(int i = 0; i<4; ++i)
            {
                FbxString lHeader(
"KFbxEvaluatorGlobalTransform Row_");
 
                lHeader += lIndex;
                lHeader += ": ";
                Display4DVector(lHeader, lGlobal.
GetRow(i));
 
            }            
            FBXSDK_printf("\n");
            for(int i = 0; i<4; ++i)
            {
                FbxString lHeader(
"FromScratchGlobalTransform Row_");
 
                lHeader += lIndex;
                lHeader += ": ";
                Display4DVector(lHeader, lGlobalTransform.
GetRow(i));
 
            }            
            FBXSDK_printf("\n");
        }
        if(lLocal == lLocalTransform)
        {
            for(int i = 0; i<4; ++i)
            {
                lHeader += lIndex;
                lHeader += ": ";
                Display4DVector(lHeader, lLocal.
GetRow(i));
 
            }            
            FBXSDK_printf("\n");
        }
        else
        {
            FBXSDK_printf("Error: The two local transform results are not equal!\n");
            for(int i = 0; i<4; ++i)
            {
                FbxString lHeader(
"KFbxEvaluatorLocalTransform Row_");
 
                lHeader += lIndex;
                lHeader += ": ";
                Display4DVector(lHeader, lLocal.
GetRow(i));
 
            }            
            FBXSDK_printf("\n");
            for(int i = 0; i<4; ++i)
            {
                FbxString lHeader(
"FromScratchLocalTransform Row_");
 
                lHeader += lIndex;
                lHeader += ": ";
                Display4DVector(lHeader, lLocalTransform.
GetRow(i));
 
            }            
            FBXSDK_printf("\n");
        }
    }
    for( int i = 0; i<lChildCount; i++)
    {
        CompareTransformations(pNode->
GetChild(i), pScene);
 
    }
}
{
    FbxAMatrix lTranlationM, lScalingM, lScalingPivotM, lScalingOffsetM, lRotationOffsetM, lRotationPivotM, \
 
                lPreRotationM, lRotationM, lPostRotationM, lTransform;
    if(!pNode)
    {
        return lTransform;
    }
    
    lTranlationM.
SetT(lTranslation);
 
    
    lRotationM.
SetR(lRotation);
 
    lPreRotationM.SetR(lPreRotation);
    lPostRotationM.
SetR(lPostRotation);
 
    
    lScalingM.
SetS(lScaling);
 
    
    lScalingOffsetM.
SetT(lScalingOffset);
 
    lScalingPivotM.
SetT(lScalingPivot);
 
    lRotationOffsetM.
SetT(lRotationOffset);
 
    lRotationPivotM.
SetT(lRotationPivot);
 
    
    if(lParentNode)
    {
        lParentGX = CalculateGlobalTransform(lParentNode);
    }
    else
    {
    }
    
    lParentGRM.
SetR(lParentGR);
 
    lLRM = lPreRotationM * lRotationM * lPostRotationM;
    
    
    
    FbxAMatrix lLSM, lParentGSM, lParentGRSM, lParentTM;
 
    lParentTM.
SetT(lParentGT);
 
    lParentGRSM = lParentTM.
Inverse() * lParentGX;
 
    lParentGSM = lParentGRM.
Inverse() * lParentGRSM;
 
    lLSM = lScalingM;
    
    {
        lGlobalRS = lParentGRM * lLRM * lParentGSM * lLSM;
    }
    {
        lGlobalRS = lParentGRM * lParentGSM * lLRM * lLSM;
    }
    {
        lParentLSM.
SetS(lParentLS);
 
        lGlobalRS = lParentGRM * lLRM * lParentGSM_noLocal * lLSM;
    }
    else
    {
        FBXSDK_printf("error, unknown inherit type! \n");
    }
    
    
    lTransform = lTranlationM * lRotationOffsetM * lRotationPivotM * lPreRotationM * lRotationM * lPostRotationM * lRotationPivotM.
Inverse()\
 
        * lScalingOffsetM * lScalingPivotM * lScalingM * lScalingPivotM.
Inverse();
 
    
    
    FbxVector4 lGlobalTranslation = lParentGX.
MultT(lLocalTWithAllPivotAndOffsetInfo);
 
    lGlobalT.
SetT(lGlobalTranslation);
 
    
    lTransform = lGlobalT * lGlobalRS;
    return lTransform;
}