#include "../Common/Common.h"
#define SAMPLE_FILENAME "Camera.fbx"
#define GET_MAX(a, b)   (a) < (b) ?  (b) : (a)
double ComputePixelRatio( double pWidth, double pHeight, double pScreenRatio);
void DisplayCameraInfo(
FbxNode* pNode);
 
static bool gVerbose = true;
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" ) gVerbose = 
false;
 
        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 
    {
        if( lScene)
        {
            
            
            FBXSDK_printf("\n\rInspect camera's attributes from the scene...\n");
            
            if( gVerbose ) DisplayCameraInfo(lRootNode);
            
            FbxCamera* lMyCamera = CreateMyCamera(lScene);
 
            FBXSDK_printf("\n\rInspect camera's attributes from the scene...\n");
            if( gVerbose ) DisplayCameraInfo(lRootNode);
            
            
            FBXSDK_printf("\n\rInspect camera's attributes from the scene...\n");
            if( gVerbose ) DisplayCameraInfo(lRootNode);
        }
        else
        {
            FBXSDK_printf("\n\nNull scene...\n");
        }
    }
    
    DestroySdkObjects(lSdkManager, lResult);
    return 0;
}
void DisplayCameraInfo(
FbxNode* pNode)
 
{
    if(!pNode)
        return;
    
    {
        FBXSDK_printf( 
"/*-----------------Camera: %s----------------------*/\n\r", lCamera->
GetName());
 
        
        double lResolutionHeight = 0.0;
        double lResolutionWidth = 0.0;
        
        
        
        switch( lCameraFormat)
        {
            FBXSDK_printf( "Camera format is customized.\n");
            break;
            FBXSDK_printf( "Camera format is NTSC.\n");
            lResolutionWidth = 640;
            lResolutionHeight = 480;
            break;
            FBXSDK_printf( "Camera format is D1 NTSC.\n");
            lResolutionWidth = 720;
            lResolutionHeight = 486;
            break;
            FBXSDK_printf( "Camera format is PAL.\n");
            lResolutionWidth = 570;
            lResolutionHeight = 486;
            break;
            FBXSDK_printf( "Camera format is D1 PAL.\n");
            lResolutionWidth = 720;
            lResolutionHeight = 576;
            break;
            FBXSDK_printf( "Camera format is HD.\n");
            lResolutionWidth = 1980;
            lResolutionHeight = 1080;
            break;
            FBXSDK_printf( "Camera format is 640x480.\n");
            lResolutionWidth = 640;
            lResolutionHeight = 480;
            break;
            FBXSDK_printf( "Camera format is 320x200.\n");
            lResolutionWidth = 320;
            lResolutionHeight = 200;
            break;
            FBXSDK_printf( "Camera format is 320x240.\n");
            lResolutionWidth = 320;
            lResolutionHeight = 240;
            break;
            FBXSDK_printf( "Camera format is 128x128.\n");
            lResolutionWidth = 128;
            lResolutionHeight = 128;
            break;
            FBXSDK_printf( "Camera format is full screen.\n");
            lResolutionWidth = 1280;
            lResolutionHeight = 1024;
            break;
        default:
            FBXSDK_printf( "Unknown camera format.\n");
            break;
        }
        
        {
            
            
            
            
            double lScreenRatio     = 4 / 3; 
            {
                lScreenRatio    = 16 / 9; 
            }
            double lInspectedPixelRatio = ComputePixelRatio( lResolutionWidth, lResolutionHeight, lScreenRatio);
            if( lPixeltRatio != lInspectedPixelRatio)
            {
                FBXSDK_printf( "Camera pixel ratio is not right.\n\rRevise the ratio: %lf to %lf.\n\n", lPixeltRatio, lInspectedPixelRatio);
                lPixeltRatio = lInspectedPixelRatio;
            }
            else
            {
                FBXSDK_printf( "camera pixel ratio is %lf.\n", lPixeltRatio);
            }
            
            
            switch( lCameraAspectRatioMode)
            {
                FBXSDK_printf( "Camera aspect ratio mode is window size.\n");
                break;
                FBXSDK_printf( "Camera aspect ratio mode is fixed ratio.\n");
                break;
                FBXSDK_printf( "Camera aspect ratio mode is fixed resolution.\n");
                break;
                FBXSDK_printf( "Camera aspect ratio mode is fixed width.\n");
                break;
                FBXSDK_printf( "Camera aspect ratio mode is fixed height.\n");
                break;
            default:
                FBXSDK_printf( "Unknown camera aspect ratio mode.\n");
                break;
            }
            
            {
                double lInspectedAspectHeight = 0.0;
                double lInspectedAspectWidth = 0.0;
                switch( lCameraAspectRatioMode)
                {
                default:
                    break;
                    if( lAspectHeight != 1.0)
                    {
                        FBXSDK_printf( "Camera aspect height should be 1.0 in fixed ratio mode.\n\rRevise the height: %lf to 1.0.\n\n", lAspectHeight);
                        lAspectHeight = 1.0;
                    }                    
                    lInspectedAspectWidth = lResolutionWidth / lResolutionHeight * lPixeltRatio;
                    if( lAspectWidth != lInspectedAspectWidth)
                    {
                        FBXSDK_printf( "Camera aspect width is not right.\n\rRevise the width: %lf to %lf.\n\n", lAspectWidth, lInspectedAspectWidth);
                        lAspectWidth = lInspectedAspectWidth;
                    }
                    break;
                    if( lAspectWidth != lResolutionWidth)
                    {
                        FBXSDK_printf( "Camera aspect width is not right.\n\rRevise the width: %lf to %lf.\n\n", lAspectWidth, lResolutionWidth);
                        lAspectWidth = lResolutionWidth;
                    }
                    if( lAspectHeight != lResolutionHeight)
                    {
                        FBXSDK_printf( "Camera aspect height is not right.\n\rRevise the height: %lf to %lf.\n\n", lAspectHeight, lResolutionHeight);
                        lAspectHeight = lResolutionHeight;
                    }  
                    break;
                    lInspectedAspectHeight = lResolutionHeight / lResolutionWidth;
                    if( lAspectHeight != lInspectedAspectHeight)
                    {
                        FBXSDK_printf( "Camera aspect height is not right.\n\rRevise the height: %lf to %lf.\n\n", lAspectHeight, lInspectedAspectHeight);
                        lAspectHeight = lInspectedAspectHeight;
                    }
                    break;
                    lInspectedAspectWidth = lResolutionWidth / lResolutionHeight;
                    if( lAspectWidth != lInspectedAspectWidth)
                    {
                        FBXSDK_printf( "Camera aspect width is not right.\n\rRevise the width: %lf to %lf.\n\n", lAspectWidth, lInspectedAspectWidth);
                        lAspectHeight = lInspectedAspectWidth;
                    }
                    break;
                }
            }
            FBXSDK_printf( "Camera aspect width: %lf .\n Camera aspect height: %lf .\n", lAspectWidth, lAspectHeight);
            
            double lInspectedApertureHeight = 0.0;
            double lInspectedApertureWidth = 0.0;
            
            
            
            switch( lApertureFormat)
            {
                FBXSDK_printf( "Camera aperture format is customized.\n");
                break;
                FBXSDK_printf( "Camera aperture format is 16mm theatrical.\n");
                lInspectedApertureWidth = 0.4040;
                lInspectedApertureHeight = 0.2950;
                break;
                FBXSDK_printf( "Camera aperture format is super 16mm.\n");
                lInspectedApertureWidth = 0.4930;
                lInspectedApertureHeight = 0.2920;
                break;
                FBXSDK_printf( "Camera aperture format is 35mm academy.\n");
                lInspectedApertureWidth = 0.8640;
                lInspectedApertureHeight = 0.6300;
                break;
                FBXSDK_printf( "Camera aperture format is 35mm TV projection.\n");
                lInspectedApertureWidth = 0.8160;
                lInspectedApertureHeight = 0.6120;
                break;
                FBXSDK_printf( "Camera aperture format is 35mm full projection.\n");
                lInspectedApertureWidth = 0.9800;
                lInspectedApertureHeight = 0.7350;
                break;
                FBXSDK_printf( "Camera aperture format is 35mm 185 projection.\n");
                lInspectedApertureWidth = 0.8250;
                lInspectedApertureHeight = 0.4460;
                break;
                FBXSDK_printf( "Camera aperture format is 35mm anamorphic.\n");
                lInspectedApertureWidth = 0.8640;
                lInspectedApertureHeight = 0.7320;
                break;
                FBXSDK_printf( "Camera aperture format is 70mm projection.\n");
                lInspectedApertureWidth = 2.0660;
                lInspectedApertureHeight = 0.9060;
                break;
                FBXSDK_printf( "Camera aperture format is vistavision.\n");
                lInspectedApertureWidth = 1.4850;
                lInspectedApertureHeight = 0.9910;
                break;
                FBXSDK_printf( "Camera aperture format is dynavision.\n");
                lInspectedApertureWidth = 2.0800;
                lInspectedApertureHeight = 1.4800;
                break;
                FBXSDK_printf( "Camera aperture format is imax.\n");
                lInspectedApertureWidth = 2.7720;
                lInspectedApertureHeight = 2.0720;
                break;
            default:
                FBXSDK_printf( "Unknown camera aperture format.\n");
                break;
            }
            
            
            switch( lApertureMode)
            {
                
                FBXSDK_printf( "Camera aperture mode is horizontal and vertical.\n");
                break;
                
                FBXSDK_printf( "Camera aperture mode is horizontal.\n");
                break;
                
                FBXSDK_printf( "Camera aperture mode is vertical.\n");
                break;
                
                FBXSDK_printf( "Camera aperture mode is focal length.\n");
                break;
            default:
                FBXSDK_printf( "Unknown camera aperture mode.\n");
                break;
            }
            
            
            
            {
                
                if( lApertureWidth != lInspectedApertureWidth)
                {
                    FBXSDK_printf( "Camera aperture width is not right.\n\rRevise the width: %lf inches to %lf inches.\n\n", lApertureWidth, lInspectedApertureWidth);
                    lApertureWidth = lInspectedApertureWidth;
                }
                
                if( lApertureHeight != lInspectedApertureHeight)
                {
                    FBXSDK_printf( "Camera aperture height is not right.\n\rRevise the height: %lf inches to %lf inches.\n\n", lApertureHeight, lInspectedApertureHeight);
                    lApertureHeight = lInspectedApertureHeight;
                }
                
                double lInspectedApertureRatio = lApertureWidth / lApertureHeight;
                if( lApertureRatio != lInspectedApertureRatio)
                {
                    FBXSDK_printf( "Camera aperture ratio is not right.\n\rRevise the ratio: %lf to %lf.\n\n", lApertureRatio, lInspectedApertureRatio);
                    lApertureRatio = lInspectedApertureRatio;
                }
            }
            FBXSDK_printf( "Camera aperture width: %lf inches.\n\rCamera aperture height: %lf inches.\n", lApertureWidth, lApertureHeight);
            FBXSDK_printf( "Camera aperture ratio is %lf.\n\n", lApertureRatio);
            
            
            
            {
                
                if( lFocalLength != lComputedFocalLength)
                {
                    FBXSDK_printf( "Camera focal length is not right.\n\rRevise the focal length: %lf mm to %lf mm.\n\n", lFocalLength, lComputedFocalLength);
                    lFocalLength = lComputedFocalLength;
                }
                else
                {
                    FBXSDK_printf( "Camera focal length is %lf mm.\n", lFocalLength);
                }
                FBXSDK_printf("Camera horizontal FOV: %lf.\n\rCamera vertical FOV: %lf.\n ", lFocalAngleX, lFocalAngleY);
            }
            {
                
                if( lFocalAngle != lComputedFOV)
                {
                    FBXSDK_printf( "Camera FOV is not right.\n\rRevise the FOV: %lf degrees to %lf degrees.\n\n", lFocalAngle, lComputedFOV);
                    lFocalAngle = lComputedFOV;
                }
                else
                {
                    FBXSDK_printf( "Camera FOV is %lf degrees.\n", lFocalAngle);
                }
                 FBXSDK_printf( "Camera focal length is %lf mm.\n", lFocalLength);
            }
            else
            {
                
                if( lFocalLength != lComputedFocalLength)
                {
                    FBXSDK_printf( "Camera focal length is not right.\n\rRevise the focal length: %lf mm to %lf mm.\n\n", lFocalLength, lComputedFocalLength);
                    lFocalLength = lComputedFocalLength;
                }
                else
                {
                    FBXSDK_printf( "Camera focal length is %lf mm.\n", lFocalLength);
                }
                FBXSDK_printf("Camera FOV: %lf.\n", lFocalAngle);
            }
            FBXSDK_printf( "Camera squeeze ratio is %lf \n", lFilmSqueezeRatio);
        }
        FBXSDK_printf( 
"/*-----------------Camera: %s----------------------*/\n\r", lCamera->
GetName());
 
    }
    
    for (i = 0; i < lCount; i++)
    {
    }
}
{
    if(!pScene)
    
    
    
    
    
    
    
    
    
    double lFOV = 45;
    
    
    return lMyCamera;
}
double ComputePixelRatio( double pWidth, double pHeight, double pScreenRatio)
{
    if( pWidth < 0.0 || pHeight < 0.0)
        return 0.0;
    pWidth = GET_MAX( pWidth, 1.0 );
    pHeight = GET_MAX( pHeight, 1.0 );
    double lResolutionRatio = (double) pWidth / pHeight;
    return pScreenRatio / lResolutionRatio;
}