void Listener::initialize(const Misc::ConfigurationFileSection& configFileSection) { /* Read the listener's name: */ std::string name=configFileSection.retrieveString("./name"); listenerName=new char[name.size()+1]; strcpy(listenerName,name.c_str()); /* Determine whether the listener is head-tracked: */ headTracked=configFileSection.retrieveValue<bool>("./headTracked",false); if(headTracked) { /* Retrieve head tracking device pointer: */ headDevice=findInputDevice(configFileSection.retrieveString("./headDevice").c_str()); if(headDevice==0) Misc::throwStdErr("Listener: Head device \"%s\" not found",configFileSection.retrieveString("./headDevice").c_str()); } else { /* Retrieve fixed head position/orientation: */ headDeviceTransformation=configFileSection.retrieveValue<TrackerState>("./headDeviceTransformation"); } /* Get head position and listening and up directions in head device coordinates: */ deviceHeadPosition=configFileSection.retrieveValue<Point>("./headPosition",Point::origin); deviceListenDirection=configFileSection.retrieveValue<Vector>("./listenDirection",Vector(0,1,0)); deviceUpDirection=configFileSection.retrieveValue<Vector>("./upDirection",Vector(0,0,1)); }
void Viewer::initialize(const Misc::ConfigurationFileSection& configFileSection) { /* Read the viewer's name: */ std::string name=configFileSection.retrieveString("./name"); viewerName=new char[name.size()+1]; strcpy(viewerName,name.c_str()); /* Determine whether the viewer is head-tracked: */ headTracked=configFileSection.retrieveValue<bool>("./headTracked",false); if(headTracked) { /* Retrieve head tracking device pointer: */ headDevice=findInputDevice(configFileSection.retrieveString("./headDevice").c_str()); if(headDevice==0) Misc::throwStdErr("Viewer: Head device \"%s\" not found",configFileSection.retrieveString("./headDevice").c_str()); } else { /* Retrieve fixed head position/orientation: */ headDeviceTransformation=configFileSection.retrieveValue<TrackerState>("./headDeviceTransformation"); } /* Get view direction and eye positions in head device coordinates: */ deviceViewDirection=configFileSection.retrieveValue<Vector>("./viewDirection",Vector(0,1,0)); deviceMonoEyePosition=configFileSection.retrieveValue<Point>("./monoEyePosition",Point::origin); deviceLeftEyePosition=configFileSection.retrieveValue<Point>("./leftEyePosition",Point::origin); deviceRightEyePosition=configFileSection.retrieveValue<Point>("./rightEyePosition",Point::origin); /* Create the viewer's light source: */ lightsource=getLightsourceManager()->createLightsource(true); /* Get head light enable flag: */ if(!configFileSection.retrieveValue<bool>("./headLightEnabled",true)) lightsource->disable(); /* Get head light position and direction in head device coordinates: */ headLightDevicePosition=configFileSection.retrieveValue<Point>("./headLightPosition",Point::origin); headLightDeviceDirection=configFileSection.retrieveValue<Vector>("./headLightDirection",Vector(0,1,0)); /* Retrieve head light settings: */ GLLight::Color headLightColor=configFileSection.retrieveValue<GLLight::Color>("./headLightColor",GLLight::Color(1.0f,1.0f,1.0f)); lightsource->getLight().diffuse=headLightColor; lightsource->getLight().specular=headLightColor; lightsource->getLight().spotCutoff=configFileSection.retrieveValue<GLfloat>("./headLightSpotCutoff",180.0f); lightsource->getLight().spotExponent=configFileSection.retrieveValue<GLfloat>("./headLightSpotExponent",0.0f); /* Initialize transient state if head tracking is disabled: */ if(!headTracked) { /* Initialize transient state: */ Point hlp=headDeviceTransformation.transform(headLightDevicePosition); lightsource->getLight().position=GLLight::Position(GLfloat(hlp[0]),GLfloat(hlp[1]),GLfloat(hlp[2]),1.0f); Vector hld=headDeviceTransformation.transform(headLightDeviceDirection); hld.normalize(); lightsource->getLight().spotDirection=GLLight::SpotDirection(GLfloat(hld[0]),GLfloat(hld[1]),GLfloat(hld[2])); } }
void VRScreen::initialize(const Misc::ConfigurationFileSection& configFileSection) { /* Read the screen's name: */ std::string name=configFileSection.retrieveString("./name"); screenName=new char[name.size()+1]; strcpy(screenName,name.c_str()); /* Determine whether screen is device-mounted: */ deviceMounted=configFileSection.retrieveValue<bool>("./deviceMounted",false); if(deviceMounted) { /* Retrieve the input device this screen is attached to: */ std::string deviceName=configFileSection.retrieveString("./deviceName"); device=findInputDevice(deviceName.c_str()); if(device==0) Misc::throwStdErr("VRScreen: Mounting device \"%s\" not found",deviceName.c_str()); } /* Retrieve screen position/orientation in physical or device coordinates: */ try { /* Try reading the screen transformation directly: */ transform=configFileSection.retrieveValue<ONTransform>("./transform"); } catch(std::runtime_error) { /* Fall back to reading the screen's origin and axis directions: */ Point origin=configFileSection.retrieveValue<Point>("./origin"); Vector horizontalAxis=configFileSection.retrieveValue<Vector>("./horizontalAxis"); Vector verticalAxis=configFileSection.retrieveValue<Vector>("./verticalAxis"); ONTransform::Rotation rot=ONTransform::Rotation::fromBaseVectors(horizontalAxis,verticalAxis); transform=ONTransform(origin-Point::origin,rot); } /* Read the screen's size: */ screenSize[0]=configFileSection.retrieveValue<Scalar>("./width"); screenSize[1]=configFileSection.retrieveValue<Scalar>("./height"); /* Apply a rotation around a single axis: */ Point rotateCenter=configFileSection.retrieveValue<Point>("./rotateCenter",Point::origin); Vector rotateAxis=configFileSection.retrieveValue<Vector>("./rotateAxis",Vector(1,0,0)); Scalar rotateAngle=configFileSection.retrieveValue<Scalar>("./rotateAngle",Scalar(0)); if(rotateAngle!=Scalar(0)) { ONTransform screenRotation=ONTransform::translateFromOriginTo(rotateCenter); screenRotation*=ONTransform::rotate(ONTransform::Rotation::rotateAxis(rotateAxis,Math::rad(rotateAngle))); screenRotation*=ONTransform::translateToOriginFrom(rotateCenter); transform.leftMultiply(screenRotation); } /* Apply an arbitrary pre-transformation: */ ONTransform preTransform=configFileSection.retrieveValue<ONTransform>("./preTransform",ONTransform::identity); transform.leftMultiply(preTransform); /* Finalize the screen transformation: */ transform.renormalize(); inverseTransform=Geometry::invert(transform); /* Check if the screen is projected off-axis: */ offAxis=configFileSection.retrieveValue<bool>("./offAxis",offAxis); if(offAxis) { /* Create the inverse of the 2D homography from clip space to rectified screen space in screen coordinates: */ PTransform2 sHomInv=PTransform2::identity; sHomInv.getMatrix()(0,0)=Scalar(2)/screenSize[0]; sHomInv.getMatrix()(0,2)=Scalar(-1); sHomInv.getMatrix()(1,1)=Scalar(2)/screenSize[1]; sHomInv.getMatrix()(1,2)=Scalar(-1); sHomInv.getMatrix()(2,2)=Scalar(1); /* Retrieve the 2D homography from clip space to projected screen space in screen coordinates: */ PTransform2 pHom=configFileSection.retrieveValue<PTransform2>("./homography"); /* Calculate the screen space homography: */ screenHomography=pHom*sHomInv; /* Calculate the clip space homography: */ PTransform2 hom=sHomInv*pHom; for(int i=0;i<3;++i) for(int j=0;j<3;++j) inverseClipHomography.getMatrix()(i<2?i:3,j<2?j:3)=hom.getMatrix()(i,j); /* Put in correction factors to keep the frustum's far plane in the same position: */ inverseClipHomography.getMatrix()(2,0)=inverseClipHomography.getMatrix()(3,0); inverseClipHomography.getMatrix()(2,1)=inverseClipHomography.getMatrix()(3,1); inverseClipHomography.doInvert(); } }