void XMLScene::drawObjects() { vector<Node*> nodes = files[option]->sceneGraph->getNodes(); unsigned int fatherInd; string id=files[option]->sceneGraph->getRootId(); vector<Node*> sons; //searches for the father and gets sons for (fatherInd=0;fatherInd<nodes.size();fatherInd++) { if(id==nodes[fatherInd]->getId()) { break; } } sons=nodes[fatherInd]->getChildNodes(); if(nodes[fatherInd]->getDisplayList()) { if(nodes[fatherInd]->getDisplayListInd()==-1) { auxDrawObjects(sons,nodes[fatherInd]->getNodeAppearance()); GLuint index = glGenLists(1); nodes[fatherInd]->setDisplayListInd(index); glNewList(index, GL_COMPILE); nodes[fatherInd]->draw(nodes[fatherInd]->getNodeAppearance().second); auxDrawObjects(sons,nodes[fatherInd]->getNodeAppearance()); glEndList(); glPopMatrix(); glCallList(index); } else { glCallList(nodes[fatherInd]->getDisplayListInd()); glPopMatrix(); } } else { nodes[fatherInd]->draw(nodes[fatherInd]->getNodeAppearance().second); auxDrawObjects(sons,nodes[fatherInd]->getNodeAppearance()); glPopMatrix(); } }
void XMLScene::auxDrawObjectsRoot() { vector<string> childrenIds; vector<Node*> nodes = sceneGraph->getNodes(); vector<SceneObject*> objects; objects=nodes[0]->getObjects(); childrenIds=nodes[0]->getChildNodeIds(); glPushMatrix(); glMultMatrixf(& nodes[0]->transMatrix[0]); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); //set appearance if(nodes[0]->getNodeAppearance().second->getSWrap()!=nodes[0]->getTextS()) nodes[0]->setTextS(nodes[0]->getNodeAppearance().second->getSWrap()); if(nodes[0]->getNodeAppearance().second->getTWrap()!=nodes[0]->getTextT()) nodes[0]->setTextT(nodes[0]->getNodeAppearance().second->getTWrap()); nodes[0]->getNodeAppearance().second->apply(); if(nodes[0]->getDisplayList()) { glCallList(nodes[0]->getDisplayListId()); } else{ for (unsigned int j=0;j<objects.size();j++) { objects[j]->draw(); } } //if child is found if(childrenIds.size()>0) { auxDrawObjects(childrenIds,nodes[0]->getNodeAppearance()); } glPopMatrix(); }
void XMLScene::auxDrawObjects(vector<Node*> sons,pair<string,Appearance*> fatherAppearance) { //searches son position on vector unsigned int sonInd; vector<Node*> childrenIds; for (sonInd=0;sonInd<sons.size();sonInd++) { glPushMatrix(); childrenIds=sons[sonInd]->getChildNodes(); if(sons[sonInd]->getDisplayList()) { if(sons[sonInd]->getDisplayListInd()==-1) { if(childrenIds.size()>0) { if(sons[sonInd]->getNodeAppearance().first=="") { auxDrawObjects(childrenIds,fatherAppearance); } else auxDrawObjects(childrenIds,sons[sonInd]->getNodeAppearance()); } GLuint index = glGenLists(1); sons[sonInd]->setDisplayListInd(index); glNewList(index, GL_COMPILE); sons[sonInd]->draw(fatherAppearance.second); //if child is found if(childrenIds.size()>0) { if(sons[sonInd]->getNodeAppearance().first=="") { auxDrawObjects(childrenIds,fatherAppearance); } else auxDrawObjects(childrenIds,sons[sonInd]->getNodeAppearance()); } glEndList(); glPopMatrix(); glCallList(index); } else { glCallList(sons[sonInd]->getDisplayListInd()); glPopMatrix(); } } else { sons[sonInd]->draw(fatherAppearance.second); childrenIds=sons[sonInd]->getChildNodes(); //if child is found if(childrenIds.size()>0) { if(sons[sonInd]->getNodeAppearance().first=="") { auxDrawObjects(childrenIds,fatherAppearance); } else auxDrawObjects(childrenIds,sons[sonInd]->getNodeAppearance()); } glPopMatrix(); } } }
void XMLScene::auxDrawObjects(vector<string> sonIds,pair<string,Appearance*> fatherAppearance) { //searches son position on vector unsigned int sonInd; vector<string> childrenIds; vector<Node*> nodes = sceneGraph->getNodes(); vector<SceneObject*> objects; for (unsigned int j=0;j<sonIds.size();j++) { for (sonInd=0;sonInd<nodes.size();sonInd++) { if(sonIds[j]==nodes[sonInd]->getId()) { objects=nodes[sonInd]->getObjects(); childrenIds=nodes[sonInd]->getChildNodeIds(); glPushMatrix(); glMultMatrixf(& nodes[sonInd]->transMatrix[0]); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); //set appearance if(nodes[sonInd]->getNodeAppearance().first=="inherit") { if(fatherAppearance.second->getSWrap()!=nodes[sonInd]->getTextS()) nodes[sonInd]->setTextS(fatherAppearance.second->getSWrap()); if(fatherAppearance.second->getTWrap()!=nodes[sonInd]->getTextT()) nodes[sonInd]->setTextT(fatherAppearance.second->getTWrap()); fatherAppearance.second->apply(); } else { if(nodes[sonInd]->getNodeAppearance().second->getSWrap()!=nodes[sonInd]->getTextS()) nodes[sonInd]->setTextS(nodes[sonInd]->getNodeAppearance().second->getSWrap()); if(nodes[sonInd]->getNodeAppearance().second->getTWrap()!=nodes[sonInd]->getTextT()) nodes[sonInd]->setTextT(nodes[sonInd]->getNodeAppearance().second->getTWrap()); nodes[sonInd]->getNodeAppearance().second->apply(); } for (unsigned int j=0;j<objects.size();j++) { objects[j]->draw(); } //if child is found if(childrenIds.size()>0) { if(nodes[sonInd]->getNodeAppearance().first=="inherit") { auxDrawObjects(childrenIds,fatherAppearance); } else auxDrawObjects(childrenIds,nodes[sonInd]->getNodeAppearance()); } glPopMatrix(); } } } }