Beispiel #1
0
void Click(int button, int state, int x, int y)
{
    double posX, posY;
    switch(button)
    {
    case 0:
        posX = ((double)x / (double)graphWin.xWinFunc()) * (graphWin.xMax() - graphWin.xMin()) + graphWin.xMin();
        posY = ((1 - (double)y / (double)graphWin.yWinFunc())) * (graphWin.yMax() - graphWin.yMin()) + graphWin.yMin();
        dessinerCourbe(posX, posY);
        break;
    }
}
void drawFunctions()
{
    const float STEP = graphWin.findSmartStepX();
    glPointSize(2.0f);

    //Draw selected  (f(x))
    for(float x=graphWin.xMin(); x<graphWin.xMax(); x+=STEP)
        graphWin.plot(x, f(x), 1.0f,0.5f,0.0f);

    //Draw f(x) = x
    for(float x=graphWin.xMin(); x<graphWin.xMax(); x+=STEP)
        graphWin.plot( x, x, 0.5f,0.5f,0.5f);

    //Draw g(x)
    for(float x=graphWin.xMin()+STEP; x<graphWin.xMax(); x+=STEP)
        graphWin.plot(x, g(x), 1.0f,0.5f,1.0f);

    clear();
    printHeader();
    std::cout << "x est compris dans l'ensemble [" << graphWin.xMin() << ";" << graphWin.xMax() << "[" << std::endl;
    std::cout << "y est compris dans l'ensemble [" << graphWin.yMin() << ";" << graphWin.yMax() << "[" << std::endl << std::endl;
    std::cout << "Information graphique : " << std::endl
              << "- Fonction choisie (f(x)) en orange" << std::endl
              << "- Fonction h(x) = x, en gris" << std::endl
              << "- Fonction g(x) = x + l*f(x), l = 1, en rose" << std::endl
              << "- Les axes x,y en bleu " << std::endl
              << "- Les vecteurs unitaires en rouge " << std::endl
              << "- Les solutions de la fonction en vert" << std::endl << std::endl;

    vector<long double> solutions = findRoot();
    std::cout << "Solutions : " << std::endl;

    glColor3f(0.0f, 1.0f, 0.0f);
    glPointSize(10);

    //Draw solutions
    for(unsigned int i = 0;i < solutions.size(); ++i)
    {
        std::cout << "[" << i << "] -> " << static_cast<double>(solutions[i]) << std::endl;
        glBegin( GL_POINTS );
            glVertex3d(solutions[i], 0, 0.0);
        glEnd();
    }
}
void Reshape(int w, int h)
{
  if (h == 0) h = 1;
  if (w == 0) w = 1;
  glViewport(0, 0, w, h);

  graphWin.setWinPixels( w, h );

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();

  float xRatio = static_cast<float>(w)/static_cast<float>(graphWin.xWinFunc());
  float yRatio = static_cast<float>(h)/static_cast<float>(graphWin.yWinFunc());

  // Volume de clipping : (left, right, bottom, top, near, far)
  glOrtho(graphWin.xMin()*xRatio, graphWin.xMax()*xRatio, graphWin.yMin()*yRatio, graphWin.yMax()*yRatio, -2.0f, 2.0f);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
}