Ejemplo n.º 1
0
static void keyboard(unsigned char key, int, int) {
  switch (key) {
    case 27:
      exit(0);
    //case 'p':
    //  useAdvShadows = !useAdvShadows;
    //  cout << (useAdvShadows ? "Advanced shadow mode" : "Simple shadow mode") << endl;
    // glutPostRedisplay();
    //  break;
#ifdef NEW_SHADOW
    case '+':    
      if (useAdvShadows && advShadowType == TSM) {
        shadow.setTSMStep(shadow.getTSMStep()+1);
        glutPostRedisplay();
      }
      break;
    case '-':
      if (useAdvShadows && advShadowType == TSM) {
        shadow.setTSMStep(shadow.getTSMStep()-1);
        glutPostRedisplay();
      }
      break;
    case 'a':
      if (useAdvShadows && advShadowType == TSM) {
        shadow.tryTSMCorrection(!shadow.tryTSMCorrection());
        glutPostRedisplay();
      }
      break;
    case 'z':
      orthoRange *= 0.5f;
      if (orthoRange <= 0.0f) {
        orthoRange = 1.0f;
      }
      glutPostRedisplay();
      break;
    case 'Z':
      orthoRange *= 2.0f;
      glutPostRedisplay();
      break;
#endif
    case 's':
#ifndef NEW_SHADOW
      if (!useAdvShadows) {
        useAdvShadows = true;
        stype = Shadow::ST_CUSTOM;
        cout << "Shadow algorithm: Custom" << endl;
      } else {
        if (stype == Shadow::ST_CUSTOM) {
          stype = Shadow::ST_UNIFORM;
          cout << "Shadow algorithm: Uniform" << endl;
        } else if (stype == Shadow::ST_UNIFORM) {
          stype = Shadow::ST_LiSPSM;
          cout << "Shadow algorithm: LiSPSM" << endl;
        } else if (stype == Shadow::ST_LiSPSM) {
          stype = Shadow::ST_UNIFORM2;
          cout << "Shadow algorithm: Uniform v2" << endl;
        } else if (stype == Shadow::ST_UNIFORM2) {
          stype = Shadow::ST_LiSPSM2;
          cout << "Shadow algorithm: LiSPSM v2" << endl;
        } else if (stype == Shadow::ST_LiSPSM2) {
          useAdvShadows = false;
          cout << "Shadow algorithm: Basic" << endl;
        }
      }
#else
      if (useAdvShadows) {
        if (advShadowType == FOCUSED) {
          advShadowType = LiSPSM;
          shadow.useLiSPSM(true);
          shadow.useTSM(false);
          cout << "Shadow algorithm: LiSPSM" << endl;
        } else if (advShadowType == LiSPSM) {
          advShadowType = TSM;
          shadow.useLiSPSM(false);
          shadow.useTSM(true);
          cout << "Shadow algorithm: TSM" << endl;
        } else {
          useAdvShadows = false;
          cout << "Shadow algorithm: Default" << endl;
        }
      } else {
        useAdvShadows = true;
        advShadowType = FOCUSED;
        shadow.useLiSPSM(false);
        shadow.useTSM(false);
        cout << "Shadow algorithm: Focused" << endl;
      }
      if (useAdvShadows && advShadowType == TSM) {
        cprog->detach(cvert);
        cprog->detach(cfrag);
        cprog->attach(cvert_tsm);
        cprog->attach(cfrag_tsm);
        cprog->link();
        
        rprog->detach(rvert);
        rprog->detach(rfrag);
        rprog->attach(rvert_tsm);
        rprog->attach(rfrag_tsm);
        rprog->link();
        
      } else {
        if (useAdvShadows == false) {
          // just leave TSM mode
          cprog->detach(cvert_tsm);
          cprog->detach(cfrag_tsm);
          cprog->attach(cvert);
          cprog->attach(cfrag);
          cprog->link();
          
          rprog->detach(rvert_tsm);
          rprog->detach(rfrag_tsm);
          rprog->attach(rvert);
          rprog->attach(rfrag);
          rprog->link();
          
        }
      }
      //if (!useAdvShadows) {
      //  useAdvShadows = true;
      //  cout << "Shadow algorithm: Custom" << endl;
      //} else {
      //  useAdvShadows = false;
      //  cout << "Shadow algorithm: Basic" << endl;
      //}
#endif
      glutPostRedisplay();
      break;
    case 'd':
      if (dbview == DV_HULLS) {
        dbview = DV_PPS;
      } else if (dbview == DV_PPS) {
#ifdef NEW_SHADOW
        dbview = DV_NT;
      } else if (dbview == DV_NT) {
#endif
        dbview = DV_HULLS;
      }
      
      glutPostRedisplay();
      break;
    case 'l':
      switch (ltype) {
        case LT_DIR:
          ltype = LT_POINT;
          cout << "POINT LIGHT" << endl;
          break;
        case LT_POINT:
          ltype = LT_SPOT;
          cout << "SPOT LIGHT" << endl;
          break;
        case LT_SPOT:
          ltype = LT_DIR;
          cout << "DIR LIGHT" << endl;
        default:
          break;
      }
      glutPostRedisplay();
      break;
    case 'f':
      rprog->detach(rfrag);
      if (rfrag == rfrag_no) {
        rfrag = rfrag_2x2;
        cout << "PCF 2x2" << endl;
      } else if (rfrag == rfrag_2x2) {
        rfrag = rfrag_4x4;
        cout << "PCF 4x4" << endl;
      } else if (rfrag == rfrag_4x4) {
        rfrag = rfrag_disc;
        cout << "PCF: Poisson disc 12 samples" << endl;
      } else if (rfrag == rfrag_disc) {
        rfrag = rfrag_no;
        cout << "No PCF" << endl;
      }
      rprog->attach(rfrag);
      if (!rprog->link()) {
        cout << "Error changing fragment program: " << rprog->log() << endl;
      }
      glutPostRedisplay();
      break;
    default:
      return;
  }
}