FlashlightTool::FlashlightTool(const ToolFactory* sFactory,const ToolInputAssignment& inputAssignment) :UtilityTool(sFactory,inputAssignment), lightsource(0),active(false) { /* Create a light source: */ lightsource=getLightsourceManager()->createLightsource(true,factory->light); lightsource->disable(); }
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])); } }
Viewer::Viewer(void) :viewerName(0), headTracked(false),headDevice(0), headDeviceTransformation(TrackerState::identity), deviceViewDirection(0,1,0), deviceMonoEyePosition(Point::origin), deviceLeftEyePosition(Point::origin), deviceRightEyePosition(Point::origin), lightsource(0), headLightDevicePosition(Point::origin), headLightDeviceDirection(0,1,0) { /* Create the viewer's light source: */ lightsource=getLightsourceManager()->createLightsource(true); /* Disable the light source by default: */ lightsource->disable(); }
Viewer::~Viewer(void) { delete[] viewerName; if(lightsource!=0) getLightsourceManager()->destroyLightsource(lightsource); }
FlashlightTool::~FlashlightTool(void) { /* Destroy the light source: */ getLightsourceManager()->destroyLightsource(lightsource); }