Vengo con un problemilla, necesito para un programa de graficación en C con GLUT. Dentro de este programa necesito graficar, usando lineas, figuras geométricas, cuyos n vértices son dados en un archivo txt proporcionado por el profesor, para ello tengo que guardar estos n vértices en un vector de la siguiente manera:
Mi problema es que no se me ocurre como leer estos n numero de vértices sin saber cuanto vale n ¿me explico?
Este es lo que hasta ahora tengo:
Código C:
Ver original
#include "GL/glut.h" #include "stdio.h" int vector[20]; void inicializa (){ glClearColor(1,1,1,0); glMatrixMode(GL_PROJECTION); gluOrtho2D(0,400,0,400); } void dibujador(int cant){ int i; glBegin(GL_LINES); for (i=0;i<cant;i++){ glVertex2i(vector[2*i],vector[2*i+1]); glVertex2i(vector[2*i+2],vector[2*i+3]); } glEnd(); } void ReadVector(){ int pos=0,i,o,cantidad; glClear(GL_COLOR_BUFFER_BIT); FILE *f; for(int i=0;i<(cantidad*2);i=i+2) vector[cantidad*2]=vector[0]; vector[cantidad*2+1]=vector[1]; glColor3f(0,0,0); dibujador(cantidad); for(int i=0;i<(cantidad*2);i=i+2) vector[cantidad*2]=vector[0]; vector[cantidad*2+1]=vector[1]; glColor3f(1,0,0); dibujador(cantidad); for(int i=0;i<(cantidad*2);i=i+2) vector[cantidad*2]=vector[0]; vector[cantidad*2+1]=vector[1]; glColor3f(0,1,0); dibujador(cantidad); for(int i=0;i<(cantidad*2);i=i+2) vector[cantidad*2]=vector[0]; vector[cantidad*2+1]=vector[1]; glColor3f(0,0,1); dibujador(cantidad); glFlush(); } int main(){ glutInitWindowSize(400,400); glutCreateWindow("Mauricio Rossainz Cruz"); inicializa(); glutDisplayFunc(ReadVector); glutMainLoop(); return 0; }
y este es el archivo Figuras_Practica_1.txt que estoy utilizando:
Código Archivo de texto:
Ver original
4 10 40 50 100 100 80 90 30 5 110 40 130 90 170 90 190 50 140 10 3 20 120 60 190 80 140 6 120 180 130 190 170 180 180 150 150 120 130 140
y este es el que DEBO de usar:
Código Archivo de texto:
Ver original
%------------------------ Figura 1 ------------------------ F1=[20.8398243,-207.4957014,25.95278797,-199.3790822,32.10166931,-192.3004205,36.86778436,-184.2027327,42.86437104,-176.1050764,48.23295845,-168.0074201,54.45293624,-159.9097639,57.7146853,-151.8121076,58.81407838,-143.7139918,52.9610491,-137.5386712,44.8632618,-133.5123206,36.76560555,-132.506781,28.6679493,-131.4599565,20.57029283,-133.4998799,12.4612788,-135.5097,6.18420252,-137.8587072,0.277392252,-141.5649094,-7.820331951,-143.5679322,-15.9179882,-144.4749485,-24.01564445,-145.4958592,-32.11330069,-146.4636363,-40.21161396,-147.4897873,-46.37966818,-153.4608443,-50.19289037,-151.2080709,-50.17219416,-143.1733646,-57.60159208,-139.0567327,-65.6992382,-137.4003474,-73.79689445,-137.487982,-81.8945507,-139.2830054,-89.99220695,-143.5046572,-98.08977756,-146.4659555,-100.1323371,-145.4680888,-92.99371272,-138.433699,-89.03082823,-130.4142549,-81.84041081,-126.3688366,-73.74220697,-122.4435674,-65.6445507,-116.8874232,-57.54690591,-110.880857,-50.21958367,-102.7847639,-45.17782518,-94.68710765,-40.22044091,-86.5894514,-39.1601883,-179.386644,124.1093555,-181.4803012,116.0116993,-182.5073168,107.914043,-183.4964747,99.8163868,-184.4916436,91.7187305,-186.4856945,83.61774429,-187.5046715,76.52396117,-189.4227696,68.42576181,-192.3815479,60.32810555,-195.4965152,52.2304493,-197.3860724,44.13279305,-197.5057877,36.0351368,-198.5564822,20.8398243,-207.4957014] %------------------------ Figura 2 ------------------------ F2=[43,22,42.5,23,42,24,42,25,42,26,42.5,27,43,28,43.5,29,44,30,44,31,44,32,44,33,44,34,44,35,44,36,44,37,44,38,44,39,44,40,43.5,41,43,42,43,43,43,44,43,45,43,46,42.5,47,42,48,42,49,42,50,42,51,42,52,42,53,42,54,42,55,42,56,41.5,57,41,58,40.5,59,40,60,39.5,61,39,62,38.5,63,38,64,37.5,65,37,66,36.5,67,36,68,35.5,69,35,70,34.5,71,34,72,34,73,34,74,34,75,34,76,34,77,34,78,34,79,34,80,34,81,34,82,33.5,83,33,84,33,85,33,86,32,87,31,88,30.5,89,30,90,29.5,91,29,92,29,93,29,94,29,95,29,96,28.5,97,28,98,27.5,99,27,100,27,101,27,102,26,103,25,104,24,104,23,104,22,104,21,104,20,103.5,19,103,18,102,17,101,16,100.5,15,100,14,99.5,13,99,12.5,98,12,97,11,97,10,97,9,97.5,8,98,7.5,98.5,7,99,7,100,7,101,7.5,102,8,103,8.5,104,9,105,9.5,106,10,107,10.5,108,11,109,11,110,11,111,11.5,112,12,113,12,114,12,115,12.5,116,13,117,13.5,118,14,119,13.5,120,13,121,14,120.5,15,120,15.5,121,16,122,16.5,122.5,17,123,18,122.5,19,122,20,121,21,120,22,119.5,23,119,24,119,25,119,26,118.5,27,118,28,117.5,29,117,30,116.5,31,116,32,116,33,116,34,115.5,35,115,36,114,37,113,38,112,39,111,40,110,41,109,42,108,43,107,44,106,45,105,46,104.5,47,104,48,103,49,102,50,102,51,102,52,101.5,53,101,54,100.5,55,100,56,100,57,100,58,99.5,59,99,60,98.5,61,98,62,97.5,63,97,64,97,65,97,66,96.5,67,96,68,96,69,96,70,96,71,96,72,95.5,73,95,74,95,75,95,76,95,77,95,79,95,81,96,83,96,85,96,87,96,89,96]