Gl Graph

Gl Graph Source of mathfunctiondrawable.cpp


 
#include "mathfunctiondrawable.h"
#include "math.h"
 
MathFunctionDrawable::MathFunctionDrawable()
{
}
 
float MathFunctionDrawable::getMinX()
{
    return -10;
}
 
float MathFunctionDrawable::getMaxX()
{
    return 10;
}
 
float MathFunctionDrawable::getMinY()
{
    return -10;
}
 
float MathFunctionDrawable::getMaxY()
{
    return 10;
}
 
void MathFunctionDrawable::draw_cercle(const int nb_step)
{
    const double step = M_PIl / nb_step;
    for (int i = 0; i < nb_step; i++)
    {
        double t1 = i*step;
        double X1 = cos(t1);
        double Y1 = sin(t1);
        double t2 = (i + 1) * step;
        double X2 = cos(t2);
        double Y2 = sin(t2);
 
        glBegin(GL_LINES);
        glVertex3d(X1, Y1, 0);
        glVertex3d(X2, Y2, 0);
        glEnd();
 
 
 
 
 
    }
    glColor3f(1.0,1.0, 1.0);
    tex1->bind();
 
 
    glBegin(GL_QUADS);
    glTexCoord2f(0,0);
    glVertex3d(0, 0, 0);
 
    glTexCoord2f(1,0);
    glVertex3d(10, 0, 0);
 
    glTexCoord2f(1,1);
    glVertex3d(10, 10, 0);
    glTexCoord2f(0,1);
    glVertex3d(0, 10, 0);
    glEnd();
    tex1->unbind();
 
    tex2->bind();
 
    glBegin(GL_QUADS);
    glTexCoord2f(0,0);
    glVertex3d(0, 0, -10);
 
    glTexCoord2f(1,0);
    glVertex3d(-10, 0, -10);
 
    glTexCoord2f(1,1);
    glVertex3d(-10, -10, -10);
    glTexCoord2f(0,1);
    glVertex3d(0, -10, -10);
    glEnd();
 
 
    glBegin(GL_QUADS);
    glTexCoord2f(0,0);
    glVertex3d(0, 0, 0);
 
    glTexCoord2f(1,0);
    glVertex3d(-10, 0, 0);
 
    glTexCoord2f(1,1);
    glVertex3d(-10, -10, 0);
    glTexCoord2f(0,1);
    glVertex3d(0, -10, 0);
    glEnd();
 
 
 
 
 
 
 
    tex2->unbind();
 
}
 
 
 
void MathFunctionDrawable::init()
{
    tex1=new GlTexture("tex1.png");
    tex2=new GlTexture("tex2.png");
}
 
void MathFunctionDrawable::draw()
{
 
    draw_cercle(100);
 
}