void SixAxisNavigationToolFactory::Configuration::load(const Misc::ConfigurationFileSection& cfs) { /* Get parameters: */ translateFactor=cfs.retrieveValue<Scalar>("./translateFactor",translateFactor); translations=cfs.retrieveValue<Misc::FixedArray<Vector,3> >("./translationVectors",translations); rotateFactor=cfs.retrieveValue<Scalar>("./rotateFactor",rotateFactor); rotations=cfs.retrieveValue<Misc::FixedArray<Vector,3> >("./scaledRotationAxes",rotations); zoomFactor=cfs.retrieveValue<Scalar>("./zoomFactor",zoomFactor); if(cfs.hasTag("./navigationCenter")) navigationCenter=cfs.retrieveValue<Point>("./navigationCenter",navigationCenter); else followDisplayCenter=true; invertNavigation=cfs.retrieveValue<bool>("./invertNavigation",invertNavigation); showNavigationCenter=cfs.retrieveValue<bool>("./showNavigationCenter",showNavigationCenter); }
void SixAxisTransformToolFactory::Configuration::load(const Misc::ConfigurationFileSection& cfs) { /* Get parameters: */ translateFactor=cfs.retrieveValue<Scalar>("./translateFactor",translateFactor); translations=cfs.retrieveValue<Misc::FixedArray<Vector,3> >("./translationVectors",translations); rotateFactor=cfs.retrieveValue<Scalar>("./rotateFactor",rotateFactor); rotations=cfs.retrieveValue<Misc::FixedArray<Vector,3> >("./scaledRotationAxes",rotations); if(cfs.hasTag("./homePosition")) { followDisplayCenter=false; homePosition=cfs.retrieveValue<Point>("./homePosition",homePosition); } deviceGlyphType=cfs.retrieveValue<std::string>("./deviceGlyphType",deviceGlyphType); deviceGlyphMaterial=cfs.retrieveValue<GLMaterial>("./deviceGlyphMaterial",deviceGlyphMaterial); }
SoundContext::SoundContext(const Misc::ConfigurationFileSection& configFileSection,VruiState* sVruiState) :vruiState(sVruiState), #if ALSUPPORT_CONFIG_HAVE_OPENAL alDevice(0),alContext(0), #endif contextData(0), listener(findListener(configFileSection.retrieveString("./listenerName").c_str())), speedOfSound(float(getMeterFactor())*343.0f), dopplerFactor(1.0f), distanceAttenuationModel(CONSTANT) { /* Set sound context parameters from configuration file: */ speedOfSound=configFileSection.retrieveValue<float>("./speedOfSound",speedOfSound); dopplerFactor=configFileSection.retrieveValue<float>("./dopplerFactor",dopplerFactor); distanceAttenuationModel=configFileSection.retrieveValue<DistanceAttenuationModel>("./distanceAttenuationModel",distanceAttenuationModel); #if ALSUPPORT_CONFIG_HAVE_OPENAL /* Open the OpenAL device: */ std::string alDeviceName=configFileSection.retrieveValue<std::string>("./deviceName","Default"); alDevice=alcOpenDevice(alDeviceName!="Default"?alDeviceName.c_str():0); if(alDevice==0) Misc::throwStdErr("SoundContext::SoundContext: Could not open OpenAL sound device \"%s\"",alDeviceName.c_str()); /* Create a list of context attributes: */ ALCint alContextAttributes[9]; ALCint* attPtr=alContextAttributes; if(configFileSection.hasTag("./mixerFrequency")) { *(attPtr++)=ALC_FREQUENCY; *(attPtr++)=configFileSection.retrieveValue<ALCint>("./mixerFrequency"); } if(configFileSection.hasTag("./refreshFrequency")) { *(attPtr++)=ALC_REFRESH; *(attPtr++)=configFileSection.retrieveValue<ALCint>("./refreshFrequency"); } if(configFileSection.hasTag("./numMonoSources")) { *(attPtr++)=ALC_MONO_SOURCES; *(attPtr++)=configFileSection.retrieveValue<ALCint>("./numMonoSources"); } if(configFileSection.hasTag("./numStereoSources")) { *(attPtr++)=ALC_STEREO_SOURCES; *(attPtr++)=configFileSection.retrieveValue<ALCint>("./numStereoSources"); } *(attPtr++)=ALC_INVALID; /* Create an OpenAL context: */ alContext=alcCreateContext(alDevice,alContextAttributes); if(alContext==0) { alcCloseDevice(alDevice); Misc::throwStdErr("SoundContext::SoundContext: Could not create OpenAL context for sound device %s",alDeviceName.c_str()); } #endif /* Create an AL context data object: */ contextData=new ALContextData(101); /* Initialize the sound context's OpenAL context: */ makeCurrent(); #if ALSUPPORT_CONFIG_HAVE_OPENAL /* Set global OpenAL parameters: */ alSpeedOfSound(speedOfSound); alDopplerFactor(dopplerFactor); switch(distanceAttenuationModel) { case CONSTANT: alDistanceModel(AL_NONE); break; case INVERSE: alDistanceModel(AL_INVERSE_DISTANCE); break; case INVERSE_CLAMPED: alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED); break; case LINEAR: alDistanceModel(AL_LINEAR_DISTANCE); break; case LINEAR_CLAMPED: alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED); break; case EXPONENTIAL: alDistanceModel(AL_EXPONENT_DISTANCE); break; case EXPONENTIAL_CLAMPED: alDistanceModel(AL_EXPONENT_DISTANCE_CLAMPED); break; } #endif }
void VideoDevice::configure(const Misc::ConfigurationFileSection& cfg) { /* Check which components of the video format are stored in the configuration file section: */ unsigned int frameSize[2]={0,0}; bool haveFrameSize=false; if(cfg.hasTag("./width")&&cfg.hasTag("./height")) { /* Read the requested frame size as width and height: */ frameSize[0]=cfg.retrieveValue<unsigned int>("./width"); frameSize[1]=cfg.retrieveValue<unsigned int>("./height"); haveFrameSize=true; } if(cfg.hasTag("./frameSize")) { /* Read the requested frame size as a two-element array: */ Misc::CFixedArrayValueCoder<unsigned int,2> valueCoder(frameSize); cfg.retrieveValueWC<unsigned int*>("./frameSize",valueCoder); haveFrameSize=true; } double frameRate=0.0; bool haveFrameRate=false; if(cfg.hasTag("./frameRate")) { /* Read the requested frame rate as a double: */ frameRate=cfg.retrieveValue<double>("./frameRate"); haveFrameRate=true; } unsigned int pixelFormat=0; bool havePixelFormat=false; if(cfg.hasTag("./pixelFormat")) { /* Read a pixel format as a FourCC code: */ std::string fourCC=cfg.retrieveValue<std::string>("./pixelFormat"); if(fourCC.size()!=4) Misc::throwStdErr("Video::VideoDevice::configure: Invalid pixel format code \"%s\"",fourCC.c_str()); /* Convert the FourCC code to a pixel format: */ VideoDataFormat temp; temp.setPixelFormat(fourCC.c_str()); pixelFormat=temp.pixelFormat; havePixelFormat=true; } if(cfg.hasTag("./pixelFormatHex")) { /* Read a pixel format as a hexadecimal number: */ std::string hex=cfg.retrieveString("./pixelFormatHex"); if(hex.size()!=8) Misc::throwStdErr("Video::VideoDevice::configure: Invalid hexadecimal pixel format code \"%s\"",hex.c_str()); for(int i=0;i<8;++i) { if(hex[i]>='0'&&hex[i]<='9') pixelFormat=(pixelFormat<<4)|(hex[i]-'0'); else if(hex[i]>='A'&&hex[i]<='F') pixelFormat=(pixelFormat<<4)|(hex[i]-'A'+10); else if(hex[i]>='a'&&hex[i]<='f') pixelFormat=(pixelFormat<<4)|(hex[i]-'a'+10); else Misc::throwStdErr("Video::VideoDevice::configure: Invalid hexadecimal pixel format code \"%s\"",hex.c_str()); } havePixelFormat=true; } /* Get the list of the device's supported video formats: */ std::vector<VideoDataFormat> deviceFormats=getVideoFormatList(); /* Find the best-matching video format among the device's advertised formats: */ std::vector<VideoDataFormat>::iterator bestFormat=deviceFormats.end(); double bestMatch=0.0; for(std::vector<VideoDataFormat>::iterator dfIt=deviceFormats.begin();dfIt!=deviceFormats.end();++dfIt) { double match=1.0; if(haveFrameSize) for(int i=0;i<2;++i) match*=dfIt->size[i]>=frameSize[i]?double(frameSize[i])/double(dfIt->size[i]):double(dfIt->size[i])/double(frameSize[i]); if(haveFrameRate) { double dfRate=double(dfIt->frameIntervalDenominator)/double(dfIt->frameIntervalCounter); match*=dfRate>=frameRate?frameRate/dfRate:dfRate/frameRate; } if(havePixelFormat&&dfIt->pixelFormat!=pixelFormat) match*=0.75; if(bestMatch<match) { bestFormat=dfIt; bestMatch=match; } } if(bestFormat==deviceFormats.end()) // Can only happen if there are no device formats throw std::runtime_error("Video::VideoDevice::configure: No matching video formats found"); /* Set the selected video format: */ setVideoFormat(*bestFormat); }