Home   Artículos   Recursos   Foros 
 

Graficador de Funciones - OpenGL


Este programa grafica funciones mediante OpenGL. Puede ser compilado con DEV C++ ó Visual C++ sin problemas.

Las descargas incluyen el archivo ejecutable y los DLL's necesarios.



 Programa ejecutandose
Programa ejecutandose

 

El programa no tiene analizador sint&actico, la ecuacion no puede modificarse en tiempo de ejecusión.

 

Parte de codigo fuente


void plotFunc3D(float d)
{	
  glNewList(GLobj, GL_COMPILE);
  glEnable(GL_NORMALIZE);
  glEnable(GL_LIGHTING);  
  float i,j,k;  
  float u[3], v[3], w[3], x[3], n[3];
  for (i = x_min; i<x_max; i+= d){        
    for (j = y_min; j<<y_max; j+= d){      
      glBegin(GL_TRIANGLES);    
      	evalfunc(i,j, &k);
        u[0] = i;  u[1] = j; u[2] = k;//cos(i*i+j*j);                        
        evalfunc(i+d,j, &k);
        v[0] = i+d; v[1] = j; v[2] = k;//cos((i+d)*(i+d)+j*j);       A 
        evalfunc(i+d,j+d, &k);
        w[0] = i+d; w[1] = j+d; w[2] = k;//cos((i+d)*(i+d)+(j+d)*(j+d));
        evalfunc(i,j+d, &k);
        x[0] = i; x[1] = j+d; x[2] = k;//cos(i*i+(j+d)*(j+d));
        cross(&n[0],u,v,w);
        glNormal3f(n[0], n[1], n[2]);
        glVertex3f(u[0], u[1], u[2]);
        glVertex3f(v[0], v[1], v[2]);
        glVertex3f(w[0], w[1], w[2]);        
        cross(&n[0],u,w,x);            
        glNormal3f(n[0], n[1], n[2]);
        glVertex3f(u[0], u[1], u[2]);
        glVertex3f(w[0], w[1], w[2]);
        glVertex3f(x[0], x[1], x[2]);        
      glEnd();
    }        
  }
  glDisable(GL_LIGHTING);
  glDisable(GL_NORMALIZE);

#if 0
  glLineWidth(0.5);
  glColor3f(1.0, 1.0, 0.0);
  glBegin(GL_LINE_LOOP);
    glVertex3f(x_min, y_min, z_min);
    glVertex3f(x_min, y_min, z_max);
    glVertex3f(x_min, y_max, z_max);
    glVertex3f(x_min, y_max, z_min);
  glEnd();
  
  glBegin(GL_LINE_LOOP);
    glVertex3f(x_max, y_min, z_min);
    glVertex3f(x_max, y_min, z_max);
    glVertex3f(x_max, y_max, z_max);
    glVertex3f(x_max, y_max, z_min);
  glEnd();
  
  glBegin(GL_LINE_LOOP);
    glVertex3f(x_min, y_min, z_min);
    glVertex3f(x_min, y_max, z_min);
    glVertex3f(x_max, y_max, z_min);
    glVertex3f(x_max, y_min, z_min);
  glEnd();
  
  glBegin(GL_LINE_LOOP);
    glVertex3f(x_min, y_min, z_max);
    glVertex3f(x_min, y_max, z_max);
    glVertex3f(x_max, y_max, z_max);
    glVertex3f(x_max, y_min, z_max);
  glEnd(); 
#endif  
  glEndList();
}

Funcion principal



int main(){      
  
  glutInitWindowSize(width, width);
  glutInitWindowPosition(200,200);
  glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);  
  (void)glutCreateWindow("glut demo");
  initGL();
  
  glutDisplayFunc(paintGL);
  glutReshapeFunc(resizeGL);
  glutMouseFunc(mousePressGL);
  glutMotionFunc(mouseMoveGL);
  glutKeyboardFunc(keyPressGL);
  glutMainLoop();  
  return 0;
}

 

Descargas

Acerca del Author

Nombre de usuario: yalmar
Blog/URL:
Fecha de envío: 2004-10-23
Ultima Actualización:
Visualizaciones: 12994
Nedstat Basic - Web site estadisticas gratuito
El contador para sitios web particulares