bool FGOutput::Load(Element* el) { // Unlike the other FGModel classes, properties listed in the <output> section // are not intended to create new properties. For that reason, FGOutput // cannot load its XML directives with FGModel::Load(). // Instead FGModelLoader::Open() and FGModel::PreLoad() must be explicitely // called. FGModelLoader ModelLoader(this); Element* element = ModelLoader.Open(el); if (!element) return false; FGModel::PreLoad(element, PropertyManager); size_t idx = OutputTypes.size(); string type = element->GetAttributeValue("type"); FGOutputType* Output = 0; if (debug_lvl > 0) cout << endl << " Output data set: " << idx << " " << endl; type = to_upper(type); if (type == "CSV") { Output = new FGOutputTextFile(FDMExec); } else if (type == "TABULAR") { Output = new FGOutputTextFile(FDMExec); } else if (type == "SOCKET") { Output = new FGOutputSocket(FDMExec); } else if (type == "FLIGHTGEAR") { Output = new FGOutputFG(FDMExec); } else if (type == "QTJSBSIM") { Output = new FGUDPOutputSocket(FDMExec); } else if (type == "TERMINAL") { // Not done yet } else if (type != string("NONE")) { cerr << "Unknown type of output specified in config file" << endl; } if (!Output) return false; Output->SetIdx(idx); Output->Load(element); PostLoad(element, PropertyManager); OutputTypes.push_back(Output); Debug(2); return true; }
TexturedModel::TexturedModel(Model model, std::vector<glm::vec2> uvs, GLuint textureID) { this->setVaoID(model.getVaoID()); this->setVerticesVboID(model.getVerticesVboID()); this->setVertexCount(model.getVertexCount()); this->setScale(model.getScale()); this->setPosition(model.getPosition()); this->setTextured(true); ModelLoader modelLoader = ModelLoader(); GLfloat *uvsTemp = &uvs[0].x; int uvsSize = uvs.size() * 2 * sizeof(GLfloat); this->uvVboID = modelLoader.storeData(2, uvsTemp, uvsSize); this->setColor(false); this->setColorsVboID(model.getColorsVboID()); }
bool FGModel::Load(Element* el, bool preLoad) { FGModelLoader ModelLoader(this); Element* document = ModelLoader.Open(el); if (!document) return false; if (document->GetName() != el->GetName()) { cerr << el->ReadFrom() << " Read model '" << document->GetName() << "' while expecting model '" << el->GetName() << "'" << endl; return false; } bool result = true; if (preLoad) result = FGModelFunctions::Load(document, PropertyManager); if (document != el) { el->MergeAttributes(document); if (preLoad) { // After reading interface properties in a file, read properties in the // local model element. This allows general-purpose models to be defined // in a file, with overrides or initial loaded constants supplied in the // relevant element of the aircraft configuration file. LocalProperties.Load(el, PropertyManager, true); } Element* element = document->FindElement(); while (element) { el->AddChildElement(element); element->SetParent(el); element = document->FindNextElement(); } } return result; }
bool FGInput::Load(Element* el) { // Unlike the other FGModel classes, properties listed in the <input> section // are not intended to create new properties. For that reason, FGInput // cannot load its XML directives with FGModel::Load(). // Instead FGModelLoader::Open() and FGModel::PreLoad() must be explicitely // called. FGModelLoader ModelLoader(this); Element* element = ModelLoader.Open(el); if (!element) return false; FGModel::PreLoad(element, PropertyManager); unsigned int idx = InputTypes.size(); string type = element->GetAttributeValue("type"); FGInputType* Input = 0; if (debug_lvl > 0) cout << endl << " Input data set: " << idx << " " << endl; type = to_upper(type); if (type.empty() || type == "SOCKET") { Input = new FGInputSocket(FDMExec); } else if (type != string("NONE")) { cerr << "Unknown type of input specified in config file" << endl; } if (!Input) return false; Input->SetIdx(idx); Input->Load(element); PostLoad(element, PropertyManager); InputTypes.push_back(Input); Debug(2); return true; }
bool FGPropulsion::Load(Element* el) { FGModelLoader ModelLoader(this); Debug(2); ReadingEngine = false; double FuelDensity = 6.0; Name = "Propulsion Model: " + el->GetAttributeValue("name"); // Perform base class Pre-Load if (!FGModel::Load(el)) return false; // Process tank definitions first to establish the number of fuel tanks Element* tank_element = el->FindElement("tank"); while (tank_element) { Tanks.push_back(new FGTank(FDMExec, tank_element, numTanks)); if (Tanks.back()->GetType() == FGTank::ttFUEL) { FuelDensity = Tanks[numFuelTanks]->GetDensity(); numFuelTanks++; } else if (Tanks.back()->GetType() == FGTank::ttOXIDIZER) numOxiTanks++; else {cerr << "Unknown tank type specified." << endl; return false;} numTanks++; tank_element = el->FindNextElement("tank"); } numSelectedFuelTanks = numFuelTanks; numSelectedOxiTanks = numOxiTanks; ReadingEngine = true; Element* engine_element = el->FindElement("engine"); while (engine_element) { if (!ModelLoader.Open(engine_element)) return false; try { // Locate the thruster definition Element* thruster_element = engine_element->FindElement("thruster"); if (!thruster_element || !ModelLoader.Open(thruster_element)) throw("No thruster definition supplied with engine definition."); if (engine_element->FindElement("piston_engine")) { HavePistonEngine = true; if (!IsBound) bind(); Element *element = engine_element->FindElement("piston_engine"); Engines.push_back(new FGPiston(FDMExec, element, numEngines, in)); } else if (engine_element->FindElement("turbine_engine")) { HaveTurbineEngine = true; if (!IsBound) bind(); Element *element = engine_element->FindElement("turbine_engine"); Engines.push_back(new FGTurbine(FDMExec, element, numEngines, in)); } else if (engine_element->FindElement("turboprop_engine")) { HaveTurboPropEngine = true; if (!IsBound) bind(); Element *element = engine_element->FindElement("turboprop_engine"); Engines.push_back(new FGTurboProp(FDMExec, element, numEngines, in)); } else if (engine_element->FindElement("rocket_engine")) { HaveRocketEngine = true; if (!IsBound) bind(); Element *element = engine_element->FindElement("rocket_engine"); Engines.push_back(new FGRocket(FDMExec, element, numEngines, in)); } else if (engine_element->FindElement("electric_engine")) { HaveElectricEngine = true; if (!IsBound) bind(); Element *element = engine_element->FindElement("electric_engine"); Engines.push_back(new FGElectric(FDMExec, element, numEngines, in)); } else { cerr << engine_element->ReadFrom() << " Unknown engine type" << endl; return false; } } catch (std::string& str) { cerr << endl << fgred << str << reset << endl; return false; } numEngines++; engine_element = el->FindNextElement("engine"); } CalculateTankInertias(); if (el->FindElement("dump-rate")) DumpRate = el->FindElementValueAsNumberConvertTo("dump-rate", "LBS/MIN"); if (el->FindElement("refuel-rate")) RefuelRate = el->FindElementValueAsNumberConvertTo("refuel-rate", "LBS/MIN"); unsigned int i; for (i=0; i<Engines.size(); i++) { Engines[i]->SetFuelDensity(FuelDensity); } PostLoad(el, PropertyManager); return true; }
//The main function int Main::start() { //Init if (init() == -1) { fprintf(stderr, "Could not initialise the program\n"); return -1; } //Create the scene Scene scene = Scene(window); Camera* camera = scene.getCamera(); camera->setFOV(45); //Create the loaders ModelLoader loader = ModelLoader(); TextureLoader textureLoader = TextureLoader(); //Create the models Model texturedModel = loader.loadToVao_OBJ_Textured("models/cube.obj", "textures/cube.bmp", glm::vec3(-3, 0, -5)); Model monkey = loader.loadToVao_OBJ("models/suzanne.obj", glm::vec3(0, 0, -5)); monkey.texture(textureLoader.loadBMP_custom("textures/suzanne texture.bmp")); monkey.setReflectivity(0.0); //Create an array of the same entities and add them to the scene std::vector<Entity> cubes; std::vector<glm::vec3> positions; int numOfCubes = 1000; Cube cubeTemp = Cube(); //Create the positions array for (int i = 0; i < numOfCubes; i++) { positions.insert(positions.end(), glm::vec3(rand() % 100, rand() % 100, rand() % 100)); } //Generate cloned cubes and put them at different positions cubes = cubeTemp.cloneEntity(positions); //Add the cubes to the entity map for (int i = 0; i < cubes.size(); i++) { scene.addEntity(&cubes[i]); } //Add the models to the scene scene.addModel(texturedModel); scene.addModel(monkey); //Create the onclick function auto onClick = []() { exit(0); }; //Create the UIs UIButton button = UIButton(0.06f, 0.05f, glm::vec2(1, -1), window, onClick); button.setAlignment(UIButton::ALIGN_BOTTOM_RIGHT); button.texture(textureLoader.loadBMP_custom("textures/Exit.bmp")); UIElement* ui = &button; //Add the UI scene.addPauseUI(ui); //Main loop while (!window.shouldClose()) { //Run the scene scene.run(); //Run the UI //Swap the buffers and poll events glfwSwapBuffers(window.getWindow()); glfwPollEvents(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } //Terminate glfw glfwTerminate(); return 0; }