void Window::createActions(void) { saveAct = new QAction(tr("&Save..."), this); saveAct->setShortcut(QKeySequence::Save); saveAct->setStatusTip(tr("Save rendered image")); saveAct->setDisabled(true); connect(saveAct, SIGNAL(triggered()), this, SLOT(save())); exitAct = new QAction(tr("E&xit"), this); exitAct->setShortcut(QKeySequence::Quit); exitAct->setStatusTip(tr("Exit the application")); connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); rsAct = new QAction(tr("&Read scene"), this); rsAct->setStatusTip(tr("Read serialized scene")); connect(rsAct, SIGNAL(triggered()), this, SLOT(readScene())); wsAct = new QAction(tr("&Write scene"), this); wsAct->setStatusTip(tr("Write serialized scene")); connect(wsAct, SIGNAL(triggered()), this, SLOT(writeScene())); readmeAct = new QAction(tr("&ReadMe"), this); readmeAct->setStatusTip(tr("Show ReadMe information")); readmeAct->setDisabled(true); connect(readmeAct, SIGNAL(triggered()), this, SLOT(readme())); aboutAct = new QAction(tr("&About"), this); aboutAct->setStatusTip(tr("Show the application's About box")); connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); }
ModelResource* ModelBaseUnmanagedFactory::createModelResource( const string& p_name, const string* p_path/*=NULL*/) { ModelResource* model = NULL; // Check and read the file AglScene* scene = readScene(p_name,p_path); // if (scene) { vector<ModelResource*>* models = createAllModelData(scene,1); if ((*models)[0]!=NULL) { model = (*models)[0]; readAndStoreEmpties(-1,model,scene); // read leftover empties } } else { model = getFallback(); } // cleanup delete scene; return model; }
bool RayTracer::loadScene( char* fn ) { try { scene = readScene( fn ); } catch( ParseError pe ) { fl_alert( "ParseError: %s\n", pe ); return false; } if( !scene ) return false; buffer_width = 256; buffer_height = (int)(buffer_width / scene->getCamera()->getAspectRatio() + 0.5); bufferSize = buffer_width * buffer_height * 3; buffer = new unsigned char[ bufferSize ]; // separate objects into bounded and unbounded scene->initScene(); // Add any specialized scene loading code here //add a spot light to scene m_bSceneLoaded = true; return true; }
int main(int argc, char** argv) { //Create the scene readScene("ModernHouse"); rayTracing(); save_png_to_file("image.png"); //Create the window glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(H_RES, V_RES); glutInitWindowPosition(500, 200); glutCreateWindow("Ray tracing"); glClearColor(1.0, 1.0, 1.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); gluOrtho2D(0.0, H_RES, 0.0, V_RES); //Call to callback function glutDisplayFunc(display); glutMainLoop(); display(); return (EXIT_SUCCESS); }
/* * public: */ ScenePointer SceneLoader::loadScene(const QString &filePath) const { QFile sceneFile(filePath); sceneFile.open(QIODevice::ReadOnly); if (!sceneFile.isOpen()) { std::cerr << "Unable to open file at path '" << filePath.toUtf8().constData() << "'" << std::endl; return ScenePointer(NULL); } QDomDocument document; QString errorMessge; int errorLine, errorColumn; if (!document.setContent(&sceneFile, &errorMessge, &errorLine, &errorColumn)) { std::cerr << "XML parsing error at line " << errorLine << ", column " << errorColumn << ": " << errorMessge.toUtf8().constData() << std::endl; return ScenePointer(NULL); } QDomElement rootElement = document.documentElement(); ScenePointer scene = readScene(rootElement); if (scene == NULL) { std::cerr << "Failed scene file parsing, check scene format" << std::endl; } return scene; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); // this->setWindowFlags(Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint); key = 0; resolution_w = 600; resolution_h = 600; labelCity = new QLabel(this); labelCity->setGeometry(200,10,resolution_w,resolution_h); labelCity->setStyleSheet("background-color: rgb(0, 0, 0);"); t_timer = new QTimer(); connect(t_timer, SIGNAL(timeout()), this, SLOT(PaintCity())); t_timer->start(30);//60 QDir dir; QString dir_string = dir.absolutePath(); QStringList list_path = dir_string.split("/"); QString aux = list_path[list_path.size() - 1];//Obtener unicamnete el ultimo int length = aux.length(); dir_string.remove(dir_string.length() - length, dir_string.length()); dir_string+= "QtTrafficLights/"; //qDebug() << dir_string; QString scenefile = dir_string + "config.xml"; readScene(scenefile); d_h_street = d_s_block * m_v_streets + m_v_streets; d_v_street = d_s_block * n_h_streets + n_h_streets; //_T = d_h_street >= d_v_street ? (d_h_street / 2.0) / m_v_streets : (d_v_street / 2.0) / n_h_streets; str_info+= "Distancia H: " + QString::number(d_h_street) + "\n" + "Distancia V: " + QString::number(d_h_street) + "\n"; // "Tiempo P: " + QString::number(_P) + "\n"; ui->txt_info->setText(str_info); qi_city = new QImage (d_h_street, d_v_street, QImage::Format_RGB888); tmp_screen = new int*[d_v_street]; for (int i = 0; i < d_v_street; i++) tmp_screen[i] = new int[d_h_street]; screen = new int*[d_v_street]; for (int i = 0; i < d_v_street; i++) screen[i] = new int[d_h_street]; }
// 导入场景 bool XMLSceneSerializer::importScene(DataStreamPtr& stream, IScene* scene) { m_scene = scene; // 打开XML文件 if(!openXML(stream)) return false; // 遍历所有Scene for (TiXmlElement* element = m_xmlDoc->RootElement()->FirstChildElement("Scene"); element != 0; element = element->NextSiblingElement("Scene")) { readScene(element); } return true; }
Scene *readScene( const string& filename ) { ifstream ifs( filename.c_str() ); if( !ifs ) { cerr << "Error: couldn't read scene file " << filename << endl; return NULL; } try { return readScene( ifs ); } catch( ParseError& pe ) { cout << "Parse error: " << pe << endl; return NULL; } }
Scene::Scene(char* path) { shapes = new vector<Shape *>(); lights = new vector<Light *>(); outputPath = string("test.png"); maxDepth = 5; attenuation[0] = 1.0; attenuation[1] = 0.0; attenuation[2] = 0.0; transformations.push(identity3D()); ambient = Color(0.2, 0.2, 0.2); numSamples = 1; lensSize = 0; readScene(path); totalPix = width * height; }
int main(int argc, char **argv) { readScene("scene.txt"); glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); glutInitWindowSize(im_size, im_size); glutCreateWindow("fuckplanets"); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-viewport_size / 2, viewport_size / 2, -viewport_size / 2, viewport_size / 2, -viewport_size / 2, viewport_size / 2); glMatrixMode(GL_MODELVIEW); glutDisplayFunc(Display); glutMainLoop(); return 0; }
bool RayTracer::loadScene( char* fn ) { try { scene = readScene( fn ); } catch( ParseError pe ) { fl_alert( "ParseError: %s\n", pe ); return false; } if( !scene ) return false; buffer_width = 256; buffer_height = (int)(buffer_width / scene->getCamera()->getAspectRatio() + 0.5); bufferSize = buffer_width * buffer_height * 3; cornerBufferSize = (buffer_width + 1) * (buffer_height + 1) * 3; bufferFilledSize = buffer_width * buffer_height; buffer = new unsigned char[ bufferSize ]; cornerBuffer = new unsigned char[cornerBufferSize]; bufferFilled = new bool[bufferFilledSize]; // separate objects into bounded and unbounded scene->initScene(); // Add any specialized scene loading code here m_bSceneLoaded = true; scene->setAmbient(ambient); scene->setAccelMode(useAccelShading); return true; }
vector<ModelResource*>* ModelBaseFactory::createModelResources( const string& p_name, const string* p_path) { InstanceInstruction currentInstance={p_name,AglMatrix::identityMatrix()}; // vector<ModelResource*>* models = NULL; vector<InstanceInstruction>* instanceInstructions = new vector<InstanceInstruction>(); int instanceCount = 0; // Check and read the file do { if (!instanceInstructions->empty()) instanceInstructions->pop_back(); int modelFoundId = m_modelResourceCache->getResourceId(currentInstance.filename); // --------------------- // New mesh // --------------------- if (modelFoundId==-1) // if it does not exist, create new { AglScene* scene = readScene(currentInstance.filename,p_path); // if (scene) { // DEBUGWARNING(( ("Loading meshes from "+currentInstance.filename+" instance="+toString(instanceCount)).c_str() )); if (instanceCount==0) { // just a normal mesh, just copy resource instructions models = createAllModelData(¤tInstance, scene, instanceInstructions); // read leftover empties if ((*models)[0]!=NULL) { ModelResource* model = (*models)[0]; SourceData source={scene,NULL,NULL,-1,string("")}; readAndStoreEmpties(source,model,currentInstance.transform, ¤tInstance,instanceInstructions); readAndStoreParticleSystems(source,model); } } else { // an instance needs to add(instead of copy) to original collection from // the instance's read collection. // it also needs to copy the model resource data vector<ModelResource*>* prefetched = createAllModelData(¤tInstance, scene, instanceInstructions); // read leftover empties ModelResource* root = (*prefetched)[0]; if (root!=NULL) { SourceData source={scene,NULL,NULL,-1,string("")}; readAndStoreEmpties(source,root,currentInstance.transform, ¤tInstance,instanceInstructions); readAndStoreParticleSystems(source,root); } // ModelResourceCollection* modelresourceCollection = m_modelResourceCache->getResource(currentInstance.filename); unsigned int start = modelresourceCollection->rootIndex+1; unsigned int size = prefetched->size(); for (unsigned int n=start;n<size;n++) { ModelResource* model = new ModelResource( *(*prefetched)[n] ); // mesh transform model->transform *= currentInstance.transform; // models->push_back(model); } } } else { models->push_back(getFallback()); } // cleanup m_scenes.push_back(scene); //delete scene; } else // the mesh already exists { // --------------------- // Existing mesh // --------------------- if (instanceCount==0) { // just a normal mesh, just copy resource instructions models = &m_modelResourceCache->getResource(currentInstance.filename)->collection; } else { // an instance needs to add to original collection from the instance's collection // it also needs to copy the model resource data ModelResourceCollection* modelresourceCollection = m_modelResourceCache->getResource(currentInstance.filename); vector<ModelResource*>* prefetched = &modelresourceCollection->collection; unsigned int root = modelresourceCollection->rootIndex; unsigned int size = prefetched->size(); for (unsigned int n=0;n<size;n++) { ModelResource* model = new ModelResource( *(*prefetched)[n] ); // mesh transform model->transform *= currentInstance.transform; AglMatrix* base= &(model->transform); // instances for (unsigned int x=0;x<model->instances.size();x++) { InstanceInstruction instruction = model->instances[x]; instruction.transform *= currentInstance.transform; instanceInstructions->push_back(instruction); } // if (n!=root) models->push_back(model); else delete model; } } } // read and prepare next instance if file had any instances specified if (!instanceInstructions->empty()) { currentInstance = instanceInstructions->back(); } instanceCount++; } while (!instanceInstructions->empty()); delete instanceInstructions; return models; }