/** \brief Initialize the mixer from a config file. * * The mixer object will be initialized from the given config file. * This file may contain more than one branch with interface settings, * so the name of the child has to be specified. */ int T_TX_Mixer::init(SimpleXMLTransfer* cfg, std::string child) { #if DEBUG_TX_INTERFACE > 0 printf("T_TX_Mixer::init(cfg, child)\n"); printf(" <-- %s\n", child.c_str()); #endif SimpleXMLTransfer* mixer; SimpleXMLTransfer* item; SimpleXMLTransfer* inter; // store the child's name for writing back the settings child_in_cfg = child; printf("Loading mixer settings from %s:\n", child.c_str()); try { inter = cfg->getChild(child, true); mixer = inter->getChild("mixer", true); enabled = mixer->attributeAsInt("enabled", 1); dr_enabled = mixer->attributeAsInt("dr_enabled", 0); for (int i = T_AxisMapper::AILERON; i <= T_AxisMapper::PITCH; i++) { item = mixer->getChild(Global::inputDev->AxisStringsXML[i], true); trim_val[i] = item->getDouble("trim", 0.0); nrate_val[i] = item->getDouble("nrate", 1.0); srate_val[i] = item->getDouble("srate", 1.0); exp_val[i] = item->getDouble("exp", 0.0); mtravel_val[i] = item->getDouble("mtravel", -0.5); ptravel_val[i] = item->getDouble("ptravel", 0.5); } for (int i = 0; i < T_TX_Mixer::NUM_MIXERS; i++) { item = mixer->getChild(Global::inputDev->MixerStringsXML[i], true); mixer_enabled[i] = item->attributeAsInt("enabled", 0); mixer_src[i] = item->getDouble("src", T_AxisMapper::NOTHING); mixer_dst[i] = item->getDouble("dst", T_AxisMapper::NOTHING); mixer_val[i] = item->getDouble("val", 0.0); } } catch (XMLException e) { errMsg = e.what(); return 1; } return 0; }
void T_AxisMapper::init(SimpleXMLTransfer* cfgfile, std::string childname) { #if DEBUG_TX_INTERFACE > 0 printf("T_AxisMapper::init(cfg, child)\n"); printf(" <-- %s\n", childname.c_str()); #endif SimpleXMLTransfer* inter; SimpleXMLTransfer* bindings; SimpleXMLTransfer* group; SimpleXMLTransfer* item; child_in_cfg = childname; // try to load config try { inter = cfgfile->getChild(childname, true); bindings = inter->getChild("bindings", true); group = bindings->getChild("axes", true); for (int i = T_AxisMapper::AILERON; i <= T_AxisMapper::PITCH; i++) { int default_axis = -1; float default_polarity = 1.0; // special handling for some default values if (i == T_AxisMapper::AILERON) { default_axis = 0; } else if (i == T_AxisMapper::ELEVATOR) { default_axis = 1; if (iface->inputMethod() != T_TX_Interface::eIM_joystick) { default_polarity = -1.0; } } item = group->getChild(Global::inputDev->AxisStringsXML[i], true); c_func[i] = item->attributeAsInt("axis", default_axis); c_inv[i] = item->attributeAsDouble("polarity", default_polarity); } std::string radio = strU(bindings->attribute("radio_type", RadioTypeStrings[CUSTOM])); for (int n=0; n < NR_OF_RADIO_TYPES; n++) { if (radio.compare(strU(RadioTypeStrings[n])) == 0) { setRadioType(n); } } } catch (XMLException e) { fprintf(stderr, "*** T_AxisMapper: XMLException: %s\n", e.what()); } }
/** * Initialize the interface. * * The base class handles all hardware initialization for us, so we only * have to set up the correct control line states to power the interface. */ int T_TX_InterfaceSerPIC::init (SimpleXMLTransfer *config) { #if DEBUG_TX_INTERFACE > 0 std::cout << "T_TX_InterfaceSerPIC::init ()\n"; #endif int ret = T_TX_InterfaceSerial::init (config); if (ret == 0) { // initialized successfully, now turn on the power supply for the // interface hardware (careful, could throw an exception) try { setRts (true); setDtr (false); } catch (CharDevice::ConfigureDeviceException e) { setErrMsg ("Setting Rts/Dtr states failed."); cerr << "Serial interface initialization: " << getErrMsg () << endl; ret = 1; } int default_sync_byte = DEFAULT_SYNC_BYTE_19200; int default_button_channel = DEFAULT_BUTTON_CHANNEL_19200; if (T_TX_InterfaceSerial::getBaudRate() == 9600) { default_sync_byte = DEFAULT_SYNC_BYTE_9600; default_button_channel = DEFAULT_BUTTON_CHANNEL_9600; } // read sync and button byte settings from config file SimpleXMLTransfer *port = config->getChild(getXmlChildName() + ".port", true); ucSyncByte = port->attributeAsInt("sync", default_sync_byte); iSPIC_ButtonChannel = port->attributeAsInt("button_channel", default_button_channel); #if DEBUG_TX_INTERFACE > 0 std::cout << " Configured sync byte: 0x" << std::hex << int(ucSyncByte) << std::dec; std::cout << ", " << std::string((iSPIC_ButtonChannel == 0) ? "no" : "has") << " button channel"; std::cout << std::endl; #endif } return ret; }
CRRCAirplaneV2::CRRCAirplaneV2(SimpleXMLTransfer* xml) { printf("CRRCAirplaneV2(xml)\n"); // initialize the airplane's sound initSound(xml); // initialize the visual representation // first collect all relevant information from the model file std::string s; s = XMLModelFile::getGraphics(xml)->getString("model"); // Offset of center of gravity CRRCMath::Vector3 pCG; pCG = CRRCMath::Vector3(0, 0, 0); if (xml->indexOfChild("CG") >= 0) { SimpleXMLTransfer* i; i = xml->getChild("CG"); pCG.r[0] = i->attributeAsDouble("x", 0); pCG.r[1] = i->attributeAsDouble("y", 0); pCG.r[2] = i->attributeAsDouble("z", 0); if (i->attributeAsInt("units") == 1) pCG *= M_TO_FT; } // plib automatically loads the texture file, but it does not know which directory to use. // where is the object file? std::string of = FileSysTools::getDataPath("objects/" + s); // compile and set relative texture path std::string tp = of.substr(0, of.length()-s.length()-1-7) + "textures"; lVisID = Video::new_visualization(of, tp, pCG, xml); if (lVisID == INVALID_AIRPLANE_VISUALIZATION) { std::string msg = "Unable to open airplane model file \""; msg += s; msg += "\"\nspecified in \""; msg += xml->getSourceDescr(); msg += "\""; throw std::runtime_error(msg); } }
/** * Load the airplane specified in configfile. Throw a * std::runtime_error on failure. */ void Aircraft::load(SimpleXMLTransfer *configfile, FDMEnviroment* fdmEnvironment) { cleanup(); fdmInterface = new ModFDMInterface(); std::string filename = configfile->getString("airplane.file", "models/allegro.xml"); filename = air_to_xml_file_load(filename); try { SimpleXMLTransfer* xml = new SimpleXMLTransfer(filename); SimpleXMLTransfer* ap = configfile->getChild("airplane"); // Here we copy graphics and config preferences from crrcsim's config file // into the in-memory-copy of the airplane. This is because an airplane file // should not be altered by user preferences. XMLModelFile::SetGraphics(xml, ap->attributeAsInt("graphics", 0)); XMLModelFile::SetConfig (xml, ap->attributeAsInt("config", 0)); fdmInterface->loadAirplane(xml, fdmEnvironment, configfile); if (configfile->getInt("video.enabled", 1)) { model_ = new CRRCAirplaneLaRCSimSSG(xml, scene); } getFDM()->registerAnimations(getModel()->getAnimations()); delete xml; } catch (XMLException e) { std::string msg = "Error opening airplane specification file: "; msg += filename; msg += ": "; msg += e.what(); throw std::runtime_error(msg); } if (getFDM() == NULL) { throw std::runtime_error("Unable to load airplane specification file."); } }
/** \brief The constructor. * * Loads an airplane model from an xml description. The 3D model * will be added to the specified scenegraph. * * \param xml XML model description file * \param graph Pointer to the scenegraph which shall render the model */ CRRCAirplaneLaRCSimSSG::CRRCAirplaneLaRCSimSSG(SimpleXMLTransfer* xml, ssgBranch *graph) : CRRCAirplaneLaRCSim(xml), initial_trans(NULL), model_trans(NULL), model(NULL), shadow(NULL), shadow_trans(NULL) { printf("CRRCAirplaneLaRCSimSSG(xml, branch)\n"); std::string s; s = XMLModelFile::getGraphics(xml)->getString("model"); // plib automatically loads the texture file, but it does not know which directory to use. { // where is the object file? std::string of = FileSysTools::getDataPath("objects/" + s); // compile and set relative texture path std::string tp = of.substr(0, of.length()-s.length()-1-7) + "textures"; ssgTexturePath(tp.c_str()); // load model model = ssgLoad(of.c_str()); } if (model != NULL) { // Offset of center of gravity CRRCMath::Vector3 pCG; pCG = CRRCMath::Vector3(0, 0, 0); if (xml->indexOfChild("CG") >= 0) { SimpleXMLTransfer* i; i = xml->getChild("CG"); pCG.r[0] = i->attributeAsDouble("x", 0); pCG.r[1] = i->attributeAsDouble("y", 0); pCG.r[2] = i->attributeAsDouble("z", 0); if (i->attributeAsInt("units") == 1) pCG *= M_TO_FT; } // transform model from SSG coordinates to CRRCsim coordinates initial_trans = new ssgTransform(); model_trans = new ssgTransform(); graph->addKid(model_trans); model_trans->addKid(initial_trans); initial_trans->addKid(model); sgMat4 it = { {1.0, 0.0, 0.0, 0}, {0.0, 0.0, -1.0, 0}, {0.0, 1.0, 0.0, 0}, {pCG.r[1], pCG.r[2], -pCG.r[0], 1.0} }; initial_trans->setTransform(it); // add a simple shadow shadow = (ssgEntity*)initial_trans->clone(SSG_CLONE_RECURSIVE | SSG_CLONE_GEOMETRY | SSG_CLONE_STATE); makeShadow(shadow); shadow_trans = new ssgTransform(); graph->addKid(shadow_trans); shadow_trans->addKid(shadow); // add animations ("real" model only, without shadow) initAnimations(xml, model, &Global::inputs, animations); } else { std::string msg = "Unable to open airplane model file \""; msg += s; msg += "\"\nspecified in \""; msg += xml->getSourceDescr(); msg += "\""; throw std::runtime_error(msg); } }
ModelBasedScenery::ModelBasedScenery(SimpleXMLTransfer *xml, int sky_variant) : Scenery(xml, sky_variant), location(Scenery::MODEL_BASED) { ssgEntity *model = NULL; SimpleXMLTransfer *scene = xml->getChild("scene", true); getHeight_mode = scene->attributeAsInt("getHeight_mode", DEFAULT_HEIGHT_MODE); //std::cout << "----getHeight_mode : " << getHeight_mode <<std::endl; SceneGraph = new ssgRoot(); // Create an "invisible" state. This state actually makes a node // visible in a predefined way. This is used to visualize invisible // objects (e.g. collision boxes). invisible_state = new ssgSimpleState(); invisible_state->disable(GL_COLOR_MATERIAL); invisible_state->disable(GL_TEXTURE_2D); invisible_state->enable(GL_LIGHTING); invisible_state->enable(GL_BLEND); //invisible_state->setShadeModel(GL_SMOOTH); //invisible_state->setShininess(0.0f); invisible_state->setMaterial(GL_EMISSION, 0.0, 0.0, 0.0, 0.0); invisible_state->setMaterial(GL_AMBIENT, 1.0, 0.0, 0.0, 0.5); invisible_state->setMaterial(GL_DIFFUSE, 1.0, 0.0, 0.0, 0.5); invisible_state->setMaterial(GL_SPECULAR, 1.0, 0.0, 0.0, 0.5); // transform everything from SSG coordinates to CRRCsim coordinates initial_trans = new ssgTransform(); SceneGraph->addKid(initial_trans); //10.76 sgMat4 it = { {1, 0.0, 0.0, 0}, {0.0, 0.0, -1, 0}, {0.0, 1, 0.0, 0}, {0.0, 0.0, 0.0, 1.0} }; initial_trans->setTransform(it); // find all "objects" defined in the file int num_children = scene->getChildCount(); for (int cur_child = 0; cur_child < num_children; cur_child++) { SimpleXMLTransfer *kid = scene->getChildAt(cur_child); // only use "object" tags if (kid->getName() == "object") { std::string filename = kid->attribute("filename", "not_specified"); bool is_terrain = (kid->attributeAsInt("terrain", 1) != 0); bool is_visible = (kid->attributeAsInt("visible", 1) != 0); // PLIB automatically loads the texture file, // but it does not know which directory to use. // Where is the object file? std::string of = FileSysTools::getDataPath("objects/" + filename, TRUE); // compile and set relative texture path std::string tp = of.substr(0, of.length()-filename.length()-1-7) + "textures"; ssgTexturePath(tp.c_str()); // load model std::cout << "Loading 3D object \"" << of.c_str() << "\""; if (is_terrain) { std::cout << " (part of terrain)"; } if (!is_visible) { std::cout << " (invisible)"; } std::cout << std::endl; model = ssgLoad(of.c_str()); if (model != NULL) { if (!is_visible) { setToInvisibleState(model); } // The model may contain internal node attributes (e.g. for // integrated collision boxes). Parse these attributes now. evaluateNodeAttributes(model); // now parse the instances and place the model in the SceneGraph for (int cur_instance = 0; cur_instance < kid->getChildCount(); cur_instance++) { SimpleXMLTransfer *instance = kid->getChildAt(cur_instance); if (instance->getName() == "instance") { sgCoord coord; // try north/east/height first, then fallback to x/y/z try { coord.xyz[SG_X] = instance->attributeAsDouble("east"); } catch (XMLException &e) { coord.xyz[SG_X] = instance->attributeAsDouble("y", 0.0); } try { coord.xyz[SG_Y] = instance->attributeAsDouble("north"); } catch (XMLException &e) { coord.xyz[SG_Y] = instance->attributeAsDouble("x", 0.0); } try { coord.xyz[SG_Z] = instance->attributeAsDouble("height"); } catch (XMLException &e) { coord.xyz[SG_Z] = instance->attributeAsDouble("z", 0.0); } coord.hpr[0] = 180 - instance->attributeAsDouble("h", 0.0); coord.hpr[1] = -instance->attributeAsDouble("p", 0.0); coord.hpr[2] = -instance->attributeAsDouble("r", 0.0); std::cout << std::setprecision(1); std::cout << " Placing instance at " << coord.xyz[SG_X] << ";" << coord.xyz[SG_Y] << ";" << coord.xyz[SG_Z]; std::cout << ", orientation " << (180-coord.hpr[0]) << ";" << -coord.hpr[1] << ";" << -coord.hpr[2] << std::endl; std::cout << std::setprecision(6); ssgTransform *trans = new ssgTransform(); trans->setTransform(&coord); // In PLIB::SSG, intersection testing is done by a tree-walking // function. This can be influenced by the tree traversal mask // bits. The HOT and LOS flags are cleared for objects that are // not part of the terrain, so that the height-of-terrain and // line-of-sight algorithms ignore this branch of the tree. if (!is_terrain) { trans->clrTraversalMaskBits(SSGTRAV_HOT | SSGTRAV_LOS); } // Objects are made invisible by clearing the CULL traversal flag. // This means that ssgCullAndDraw will ignore this branch. if (!is_visible) { trans->clrTraversalMaskBits(SSGTRAV_CULL); } initial_trans->addKid(trans); trans->addKid(model); } } } } } // create actual terrain height model if (getHeight_mode == 1) { heightdata = new HD_TabulatedTerrain(SceneGraph); } else if (getHeight_mode == 2) { heightdata = new HD_TilingTerrain(SceneGraph); } else { heightdata = new HD_SsgLOSTerrain(SceneGraph); } //wind SimpleXMLTransfer *wind = xml->getChild("wind", true); std::string wind_filename = wind->attribute("filename",""); #if WINDDATA3D == 1 wind_data = 0;//default : no wind_data std::string wind_position_unit = wind->attribute("unit",""); try { flDefaultWindDirection = wind->attributeAsInt("direction"); ImposeWindDirection = true; } catch (XMLException) { // if not attribut "direction", normal mode } if (wind_position_unit.compare("m")==0) { wind_position_coef = FT_TO_M; } else { wind_position_coef = 1; } std::cout << "wind file name : " << wind_filename.c_str()<< std::endl; if (wind_filename.length() > 0) { wind_filename = FileSysTools::getDataPath(wind_filename); std::cout << "init wind ---------"; int n = init_wind_data((wind_filename.c_str())); std::cout << n << " points processed" << std::endl; } #else if (wind_filename.length() > 0) { new CGUIMsgBox("Insufficient configuration to read windfields."); } #endif }