Generar un gráfico matemático con OpenGL

Por:yalmar, enviado 23 oct 2004
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.

matplot3D.png
Programa ejecutándose


El programa no tiene analizador sintáctico, la ecuación no puede modificarse en tiempo de ejecución.

Code: Seleccionar todo
  1. void plotFunc3D(float d)

  2. {      

  3.   glNewList(GLobj, GL_COMPILE);

  4.   glEnable(GL_NORMALIZE);

  5.   glEnable(GL_LIGHTING);  

  6.   float i,j,k;  

  7.   float u[3], v[3], w[3], x[3], n[3];

  8.   for (i = x_min; i<x_max; i+= d){        

  9.     for (j = y_min; j<<y_max; j+= d){      

  10.       glBegin(GL_TRIANGLES);    

  11.         evalfunc(i,j, &k);

  12.         u[0] = i;  u[1] = j; u[2] = k;//cos(i*i+j*j);                        

  13.         evalfunc(i+d,j, &k);

  14.         v[0] = i+d; v[1] = j; v[2] = k;//cos((i+d)*(i+d)+j*j);       A

  15.         evalfunc(i+d,j+d, &k);

  16.         w[0] = i+d; w[1] = j+d; w[2] = k;//cos((i+d)*(i+d)+(j+d)*(j+d));

  17.         evalfunc(i,j+d, &k);

  18.         x[0] = i; x[1] = j+d; x[2] = k;//cos(i*i+(j+d)*(j+d));

  19.         cross(&n[0],u,v,w);

  20.         glNormal3f(n[0], n[1], n[2]);

  21.         glVertex3f(u[0], u[1], u[2]);

  22.         glVertex3f(v[0], v[1], v[2]);

  23.         glVertex3f(w[0], w[1], w[2]);        

  24.         cross(&n[0],u,w,x);            

  25.         glNormal3f(n[0], n[1], n[2]);

  26.         glVertex3f(u[0], u[1], u[2]);

  27.         glVertex3f(w[0], w[1], w[2]);

  28.         glVertex3f(x[0], x[1], x[2]);        

  29.       glEnd();

  30.     }        

  31.   }

  32.   glDisable(GL_LIGHTING);

  33.   glDisable(GL_NORMALIZE);

  34.  

  35.   glEndList();

  36. }



Función Principal


Code: Seleccionar todo
  1. int main(){      

  2.  

  3.   glutInitWindowSize(width, width);

  4.   glutInitWindowPosition(200,200);

  5.   glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);  

  6.   (void)glutCreateWindow("glut demo");

  7.   initGL();

  8.  

  9.   glutDisplayFunc(paintGL);

  10.   glutReshapeFunc(resizeGL);

  11.   glutMouseFunc(mousePressGL);

  12.   glutMotionFunc(mouseMoveGL);

  13.   glutKeyboardFunc(keyPressGL);

  14.   glutMainLoop();  

  15.   return 0;

  16. }

Archivos Adjuntos

  • mathplot.zip 208,92 KiB
    Código fuente del programa

Debe estar registrado para poder descargar archivos Desea registrarse?

Otros Artículos en esta sección

¿Alguna duda? Sientete libre de hacer tus pruntas en nuestro:
foro de Visual C++ »