#include <math.h>
#include "../Common/Common.h"
#define SAMPLE_FILENAME "ExportScene02.fbx"
int main(int argc, char** argv)
{
    bool lResult;
    
    InitializeSdkObjects(lSdkManager, lScene);
    
    lResult = CreateScene(lScene);
    if(lResult == false)
    {
        FBXSDK_printf("\n\nAn error occurred while creating the scene...\n");
        DestroySdkObjects(lSdkManager, lResult);
        return 0;
    }
    
    
    const char* lSampleFileName = 
NULL;
 
    for( int i = 1; i < argc; ++i )
    {
        if( FBXSDK_stricmp(argv[i], "-test") == 0 ) continue;
        else if( !lSampleFileName ) lSampleFileName = argv[i];
    }
    if( !lSampleFileName ) lSampleFileName = SAMPLE_FILENAME;
    lResult = SaveScene(lSdkManager, lScene, lSampleFileName);
    if(lResult == false)
    {
        FBXSDK_printf("\n\nAn error occurred while saving the scene...\n");
        DestroySdkObjects(lSdkManager, lResult);
        return 0;
    }
    
    DestroySdkObjects(lSdkManager, lResult);
    return 0;
}
{
    FbxNode* lNurbs = CreateNurbs(pScene, 
"Nurbs");
 
    MapShapesOnNurbs(pScene, lNurbs);
    MapMaterial(pScene, lNurbs);
    MapTexture(pScene, lNurbs);
    
    AnimateNurbs(lNurbs, pScene);
    return true;
}
{
    
    double lUKnotVector[] = { -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0 };
    double lVKnotVector[] = { 0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 4.0, 4.0, 4.0 };
    int i, j;
    double lScale = 20.0;
    double lPi = 3.14159;
    double lYAngle[] = { 90.0, 90.0, 52.0, 0.0, -52.0, -90.0, -90.0 };
    double lRadius[] = { 0.0, 0.283, 0.872, 1.226, 0.872, 0.283, 0.0}; 
    for (i = 0; i < 7; i++) 
    {
        for (j = 0; j < 8; j++)
        {
            double lX = lScale * lRadius[i] * cos(lPi/4*j);
            double lY = lScale * sin(2*lPi/360*lYAngle[i]);
            double lZ = lScale * lRadius[i] * sin(lPi/4*j);
            double lWeight = 1.0;
            lVector4[8*i + j].
Set(lX, lY, lZ, lWeight);
 
        }
    }
    return lNode;
}
{
    int i, j;
    for (i = 0; i < 7; i++)
    {
        for (j = 0; j < 8; j++)
        {
            if (j < 3 || j > 6)
            {
                lVector4[8*i + j] = lExtremeLeft;
            }
            else
            {
                lVector4[8*i + j] = lExtremeRight;
            }
        }
    }
}
{
    int i, j;
    double lScale = 20.0;
    double lWeight = 1.0;
    double lX[] = { 0.9, 1.1, 0.0, -1.1, -0.9, -1.1, 0.0, 1.1 };
    double lZ[] = { 0.0, 1.1, 0.9, 1.1, 0.0, -1.1, -0.9, -1.1 };
    
    for (i = 0; i < 8; i++)
    {
        lVector4[i].
Set(0.0, lScale, 0.0, lWeight);
 
    }
    
    for (i = 1; i < 6; i++)
    {
        double lY = 1.0 - 0.5 * (i - 1);
        for (j = 0; j < 8; j++)
        {
            lVector4[8*i + j].
Set(lScale*lX[j], lScale*lY, lScale*lZ[j], lWeight);
 
        }
    }
    
    for (i = 48; i < 56; i++)
    {
        lVector4[i].
Set(0.0, -lScale, 0.0, lWeight);
 
    }
}
{
    
    MapStretchedShape(pScene, lBlendShapeChannel01);
    MapBoxShape(pScene, lBlendShapeChannel01);  
    
    MapBoxShape(pScene, lBlendShapeChannel02);  
    
    
};
{
    
    
    
    if (lMaterial)
        lMaterial->
Diffuse.ConnectSrcObject(lTexture);
 
    
    
    
    
    
    if (lMaterial)
        lMaterial->
Ambient.ConnectSrcObject(lTexture);
 
}
{
    
    if (!lGeometryElementMaterial)
    {
    }
    
    
}
{
    int lKeyIndex = 0;
    
    lAnimStackName = "Morph sphere into box";
        
        
        
    
    if (lCurve)
    {
        lKeyIndex = lCurve->
KeyAdd(lTime);
 
        lKeyIndex = lCurve->
KeyAdd(lTime);
 
        lKeyIndex = lCurve->
KeyAdd(lTime);
 
    }
    
    if (lCurve)
    {
        lKeyIndex = lCurve->
KeyAdd(lTime);
 
        lKeyIndex = lCurve->
KeyAdd(lTime);
 
    }
}