SixAxisSurfaceNavigationToolFactory::SixAxisSurfaceNavigationToolFactory(ToolManager& toolManager) :ToolFactory("SixAxisSurfaceNavigationTool",toolManager), canRoll(true), bankTurns(false),levelSpeed(5), canFly(true), probeSize(getDisplaySize()), maxClimb(getDisplaySize()), fixAzimuth(false), drawHud(true),hudColor(0.0f,1.0f,0.0f),hudRadius(float(getFrontplaneDist()*1.25f)),hudFontSize(float(getUiSize())*1.5f) { /* Initialize tool layout: */ layout.setNumValuators(6); /* Load class settings: */ Misc::ConfigurationFileSection cfs=toolManager.getToolClassSection(getClassName()); Vector trans; for(int i=0;i<3;++i) trans[i]=getDisplaySize(); trans=cfs.retrieveValue<Vector>("./translateFactors",trans); for(int i=0;i<3;++i) translateFactors[i]=trans[i]; Vector rot=cfs.retrieveValue<Vector>("./rotateFactors",Vector(180,180,180)); for(int i=0;i<3;++i) rotateFactors[i]=Math::rad(rot[i]); canRoll=cfs.retrieveValue<bool>("./canRoll",canRoll); bankTurns=cfs.retrieveValue<bool>("./bankTurns",bankTurns); levelSpeed=cfs.retrieveValue<Scalar>("./levelSpeed",levelSpeed); if(levelSpeed<Scalar(0)) levelSpeed=Scalar(0); canFly=cfs.retrieveValue<bool>("./canFly",canFly); probeSize=cfs.retrieveValue<Scalar>("./probeSize",probeSize); maxClimb=cfs.retrieveValue<Scalar>("./maxClimb",maxClimb); fixAzimuth=cfs.retrieveValue<bool>("./fixAzimuth",fixAzimuth); drawHud=cfs.retrieveValue<bool>("./drawHud",drawHud); hudColor=cfs.retrieveValue<Color>("./hudColor",hudColor); hudRadius=cfs.retrieveValue<float>("./hudRadius",hudRadius); hudFontSize=cfs.retrieveValue<float>("./hudFontSize",hudFontSize); /* Insert class into class hierarchy: */ ToolFactory* navigationToolFactory=toolManager.loadClass("SurfaceNavigationTool"); navigationToolFactory->addChildClass(this); addParentClass(navigationToolFactory); /* Set tool class' factory pointer: */ SixAxisSurfaceNavigationTool::factory=this; }
void HelicopterNavigationTool::initContext(GLContextData& contextData) const { /* Create and register a data item: */ DataItem* dataItem=new DataItem; contextData.addDataItem(this,dataItem); /* Create the digit display lists: */ float y=float(getFrontplaneDist())*1.25f; float s=y*0.0025f; glNewList(dataItem->displayListBase+0,GL_COMPILE); glBegin(GL_LINE_LOOP); glVertex3f(0.0f*s,0.0f,2.0f*s); glVertex3f(0.0f*s,0.0f,0.0f*s); glVertex3f(1.0f*s,0.0f,0.0f*s); glVertex3f(1.0f*s,0.0f,2.0f*s); glEnd(); glTranslatef(s*1.5f,0.0f,0.0f); glEndList(); glNewList(dataItem->displayListBase+1,GL_COMPILE); glBegin(GL_LINES); glVertex3f(0.0f*s,0.0f,2.0f*s); glVertex3f(0.0f*s,0.0f,0.0f*s); glEnd(); glTranslatef(s*0.5f,0.0f,0.0f); glEndList(); glNewList(dataItem->displayListBase+2,GL_COMPILE); glBegin(GL_LINE_STRIP); glVertex3f(0.0f*s,0.0f,2.0f*s); glVertex3f(1.0f*s,0.0f,2.0f*s); glVertex3f(1.0f*s,0.0f,1.0f*s); glVertex3f(0.0f*s,0.0f,1.0f*s); glVertex3f(0.0f*s,0.0f,0.0f*s); glVertex3f(1.0f*s,0.0f,0.0f*s); glEnd(); glTranslatef(s*1.5f,0.0f,0.0f); glEndList(); glNewList(dataItem->displayListBase+3,GL_COMPILE); glBegin(GL_LINE_STRIP); glVertex3f(0.0f*s,0.0f,2.0f*s); glVertex3f(1.0f*s,0.0f,2.0f*s); glVertex3f(1.0f*s,0.0f,0.0f*s); glVertex3f(0.0f*s,0.0f,0.0f*s); glEnd(); glBegin(GL_LINES); glVertex3f(0.0f*s,0.0f,1.0f*s); glVertex3f(1.0f*s,0.0f,1.0f*s); glEnd(); glTranslatef(s*1.5f,0.0f,0.0f); glEndList(); glNewList(dataItem->displayListBase+4,GL_COMPILE); glBegin(GL_LINE_STRIP); glVertex3f(0.0f*s,0.0f,2.0f*s); glVertex3f(0.0f*s,0.0f,1.0f*s); glVertex3f(1.0f*s,0.0f,1.0f*s); glEnd(); glBegin(GL_LINES); glVertex3f(1.0f*s,0.0f,2.0f*s); glVertex3f(1.0f*s,0.0f,0.0f*s); glEnd(); glTranslatef(s*1.5f,0.0f,0.0f); glEndList(); glNewList(dataItem->displayListBase+5,GL_COMPILE); glBegin(GL_LINE_STRIP); glVertex3f(1.0f*s,0.0f,2.0f*s); glVertex3f(0.0f*s,0.0f,2.0f*s); glVertex3f(0.0f*s,0.0f,1.0f*s); glVertex3f(1.0f*s,0.0f,1.0f*s); glVertex3f(1.0f*s,0.0f,0.0f*s); glVertex3f(0.0f*s,0.0f,0.0f*s); glEnd(); glTranslatef(s*1.5f,0.0f,0.0f); glEndList(); glNewList(dataItem->displayListBase+6,GL_COMPILE); glBegin(GL_LINE_STRIP); glVertex3f(0.0f*s,0.0f,2.0f*s); glVertex3f(0.0f*s,0.0f,0.0f*s); glVertex3f(1.0f*s,0.0f,0.0f*s); glVertex3f(1.0f*s,0.0f,1.0f*s); glVertex3f(0.0f*s,0.0f,1.0f*s); glEnd(); glTranslatef(s*1.5f,0.0f,0.0f); glEndList(); glNewList(dataItem->displayListBase+7,GL_COMPILE); glBegin(GL_LINE_STRIP); glVertex3f(0.0f*s,0.0f,2.0f*s); glVertex3f(1.0f*s,0.0f,2.0f*s); glVertex3f(1.0f*s,0.0f,0.0f*s); glEnd(); glTranslatef(s*1.5f,0.0f,0.0f); glEndList(); glNewList(dataItem->displayListBase+8,GL_COMPILE); glBegin(GL_LINE_LOOP); glVertex3f(0.0f*s,0.0f,2.0f*s); glVertex3f(0.0f*s,0.0f,0.0f*s); glVertex3f(1.0f*s,0.0f,0.0f*s); glVertex3f(1.0f*s,0.0f,2.0f*s); glEnd(); glBegin(GL_LINES); glVertex3f(0.0f*s,0.0f,1.0f*s); glVertex3f(1.0f*s,0.0f,1.0f*s); glEnd(); glTranslatef(s*1.5f,0.0f,0.0f); glEndList(); glNewList(dataItem->displayListBase+9,GL_COMPILE); glBegin(GL_LINE_STRIP); glVertex3f(1.0f*s,0.0f,1.0f*s); glVertex3f(0.0f*s,0.0f,1.0f*s); glVertex3f(0.0f*s,0.0f,2.0f*s); glVertex3f(1.0f*s,0.0f,2.0f*s); glVertex3f(1.0f*s,0.0f,0.0f*s); glEnd(); glTranslatef(s*1.5f,0.0f,0.0f); glEndList(); /* Draw the entire artificial horizon ribbon: */ glNewList(dataItem->displayListBase+10,GL_COMPILE); glColor3f(0.0f,1.0f,0.0f); /* Draw the climb ladder: */ glBegin(GL_LINES); glVertex3f(-y*0.1f,y,0.0f); glVertex3f( y*0.1f,y,0.0f); glEnd(); glEnable(GL_LINE_STIPPLE); glLineStipple(10,0xaaaaU); glBegin(GL_LINES); for(int i=0; i<9; ++i) { float angle=Math::rad(float(i+1)*10.0f); float ac=Math::cos(angle)*y; float as=Math::sin(angle)*y; glVertex3f(-y*0.1f,ac, as); glVertex3f( y*0.1f,ac, as); glVertex3f(-y*0.1f,ac,-as); glVertex3f( y*0.1f,ac,-as); } for(int i=0; i<9; ++i) { float angle=Math::rad(float(i*2+1)*5.0f); float ac=Math::cos(angle)*y; float as=Math::sin(angle)*y; glVertex3f(-y*0.075f,ac, as); glVertex3f( y*0.075f,ac, as); glVertex3f(-y*0.075f,ac,-as); glVertex3f( y*0.075f,ac,-as); } glEnd(); glDisable(GL_LINE_STIPPLE); /* Draw the climb labels: */ char buffer[10]; for(int i=-9; i<=9; ++i) { glPushMatrix(); float angle=float(i)*10.0f; glRotatef(angle,1.0f,0.0f,0.0f); glTranslatef(y*0.105f,y,-s); snprintf(buffer,sizeof(buffer),"%d",Math::abs(i*10)); for(char* bufPtr=buffer; *bufPtr!='\0'; ++bufPtr) glCallList(dataItem->displayListBase+(GLuint(*bufPtr)-GLuint('0'))); glPopMatrix(); } glEndList(); }
void HelicopterNavigationTool::display(GLContextData& contextData) const { if(isActive()) { /* Get the data item: */ DataItem* dataItem=contextData.retrieveDataItem<DataItem>(this); glPushAttrib(GL_ENABLE_BIT|GL_LINE_BIT); glDisable(GL_LIGHTING); glLineWidth(1.0f); glColor3f(0.0f,1.0f,0.0f); float y=float(getFrontplaneDist())*1.25f; glPushMatrix(); glMultMatrix(pre); glRotate(valuators[4]*Math::deg(factory->viewAngleFactors[0]),Vector(0,0,1)); glRotate(valuators[5]*Math::deg(factory->viewAngleFactors[1]),Vector(1,0,0)); glBegin(GL_LINES); glVertex3f(-y*0.02f,y, 0.00f); glVertex3f(-y*0.01f,y, 0.00f); glVertex3f( y*0.01f,y, 0.00f); glVertex3f( y*0.02f,y, 0.00f); glVertex3f( 0.00f,y,-y*0.02f); glVertex3f( 0.00f,y,-y*0.01f); glVertex3f( 0.00f,y, y*0.01f); glVertex3f( 0.00f,y, y*0.02f); glEnd(); /* Draw the flight path marker: */ Vector vel=currentOrientation.transform(currentVelocity); if(vel[1]>Scalar(0)) { vel*=y/vel[1]; Scalar maxVel=Misc::max(Math::abs(vel[0]),Math::abs(vel[2])); if(maxVel>=Scalar(y*0.5f)) { vel[0]*=Scalar(y*0.5f)/maxVel; vel[2]*=Scalar(y*0.5f)/maxVel; glColor3f(1.0f,0.0f,0.0f); } else glColor3f(0.0f,1.0f,0.0f); glBegin(GL_LINE_LOOP); glVertex3f(vel[0]-y*0.005f,vel[1],vel[2]+ 0.000f); glVertex3f(vel[0]+ 0.000f,vel[1],vel[2]-y*0.005f); glVertex3f(vel[0]+y*0.005f,vel[1],vel[2]+ 0.000f); glVertex3f(vel[0]+ 0.000f,vel[1],vel[2]+y*0.005f); glEnd(); } /* Draw the artificial horizon ribbon: */ glRotate(currentOrientation); Vector yAxis=currentOrientation.inverseTransform(Vector(0,1,0)); Scalar yAngle=Math::deg(Math::atan2(yAxis[0],yAxis[1])); glRotate(-yAngle,Vector(0,0,1)); glCallList(dataItem->displayListBase+10); glPopMatrix(); glPopAttrib(); } }