Exemplo n.º 1
0
Element* Document::RecursiveParseCjsonItems(cJSON* item)
{
    //printf("RecursiveParseCjsonItems, type %d\n", item->type);
    
    // Turn the cJSON item into an Element object.
    Element* newElement = ConstructElementFromCjsonItem(item);
    
    // Assert that the parsing was successful.
    //assert(newElement != nullptr);
    if (newElement == nullptr)
    {
        return newElement;
    }
    
    // Special case... for arrays and objects we need to parse the
    // children.
    if (newElement->GetType() == ELEMENT_TYPE_ARRAY)
    {
        // Loop through the children.
        cJSON* childItem = item->child;
        std::size_t index = 0;
        while (childItem)
        {
            Element* childElement = RecursiveParseCjsonItems(childItem);
            if (childElement)
            {
                newElement->AddElement(index, *childElement);
            }
            childItem = childItem->next;
            index += 1;
        }        
    }
    else if (newElement->GetType() == ELEMENT_TYPE_OBJECT)
    {
        // Loop through the children.
        cJSON* childItem = item->child;
        while (childItem)
        {
            Element* childElement = RecursiveParseCjsonItems(childItem);
            if (childElement)
            {
                newElement->AddElement(childItem->string, *childElement);
            }
            childItem = childItem->next;
        }
    }
        
    return newElement;
}
Exemplo n.º 2
0
    void Framework::update()
    {
        if( bFirstFrame )
        {
            Pad::Create();
            bFirstFrame = false;
            g_ResourceStage = new GraphicData("data.txt");
            g_ResourceRobot = new GraphicData("robo.txt");
            g_Model[0] = g_ResourceRobot->CreateModel("robo");
            g_Model[1] = g_ResourceRobot->CreateModel("robo");

            Document doc;
            Element* root = doc.GetRoot();
            Element* tmp = new Element("Test");
            double p[3] = { 10,0,-10 };

            Attribute* a = new Attribute("Pos", "1,1,1");
            a->Set("Hehe",p,3);
            tmp->AddAttribute(a);
            root->AddElement(tmp);
            doc.Write("MyFirst.txt");
        }
        setFrameRate( 60 );
        g_cnt++;
        
        // View matrix 
        //camera.SetPos( Vector3(sin(g_cnt)*10, 1, cos(g_cnt)*10) );
        camera.SetPos( Vector3(0, 1, 10) );
        camera.SetTarget( Vector3(0,0,0) );
 
        Matrix44 matProjView;
        camera.CreateProjViewMatrix(&matProjView);        

        g_ResourceStage->GetBatch("batch")->Draw(matProjView);
        g_Model[0]->SetPos(Vector3(2,0,0));
        g_Model[0]->Draw(matProjView);

        g_Model[1]->SetPos(Vector3(-2,1,0));
        g_Model[1]->SetScale(Vector3(2,1,2));
        g_Model[1]->Draw(matProjView);

        enableDepthTest( true );

        if ( isEndRequested() ){            			
            SAFE_DELETE( g_ResourceStage );
            SAFE_DELETE( g_ResourceRobot );
            Pad::Destroy();
		}
    }