Sziasztok!
Egy olyan problémám támadt, hogy OpenGL-ben írnék egy programot (TravellingBusinessman).
Azt nem tudom megoldani, hogy amikor megváltoznak a koordináták, akkor azok megjelenjenek a képernyőn, mindig csak az első állapot jelenik meg.
(A program még nem tljes, eddig csak ezzel a frissítgetéssel szórakoztam)
Köszönöm a segítséget!
Üdv:Token
-----------------------------------------------------------------------------------------------
#include
#include
#include
#include
#include
#include
#include
FILE *f;
double *pp;
int *nn,CITY;
int i,j, adat;
double places[1000],proba[1000];
char c;
void tengely (void);
void display (void);
void reshape (int , int);
void plot (void);
void keyboard (unsigned char , int , int ) ;
void plotter ();
/***************************************************************************************************/
int main (int argc, char *argv[]) {
CITY=40;
for(j=0;j<5;j++){
for(i=0;i
places[2*i]=(double)(rand()%6);
places[(2*i)+1]=(double)(rand()%6);
}
pp=&places[0];
nn=&CITY;
plotter();
}
return 0;
}
/****************************************************************************************************/
/******************************* FÜGGVÉNYEK ***************************************/
/****************************************************************************************************/
void tengely (void) {
glColor3f(255,255,255);
glBegin(GL_LINES);
glVertex3f(-1000, 0, 0.0);
glVertex3f( 1000, 0, 0.0);
glVertex3f( 0, 1000, 0.0);
glVertex3f( 0, -1000, 0.0);
glEnd();
}
void plot (void) {
int i;
for(i=0;i<(*nn-1);i++) {
glMatrixMode(GL_MODELVIEW);
glColor3f(255,255,255);
glBegin(GL_LINES);
glVertex2d((10*pp[2*i]),(10*pp[(2*i)+1]));
glVertex2d((10*pp[2*i+2]),(10*pp[2*i+3]));
glEnd();
}
for(i=0;i<(*nn);i++) {
glColor3f(255,0,0);
glBegin(GL_POINTS);
glVertex2d((10*pp[2*i]),(10*pp[(2*i)+1]));
glEnd();
}
}
void display (void) {
glClearColor (0.0,0.0,0.0,1.0);
glClear (GL_COLOR_BUFFER_BIT);
glLoadIdentity();
gluLookAt (10.0, 0.0, 100.0, 10.0, 0.0, 0.0, 0.0, 100.0, 100.0);
glPointSize(5);
//tengely();
plot();
glutSwapBuffers();
}
void reshape (int w, int h) {
glViewport (0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (60, (GLfloat)w / (GLfloat)h, 1.0, 100.0);
glMatrixMode (GL_MODELVIEW);
}
void keyboard (unsigned char key, int x, int y) {
switch(key) {
case 27:
exit(0);
break;
default:
break;
}
}
void plotter (void) {
glutInitDisplayMode (GLUT_DOUBLE);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow ("EREDMÉNY");
glutDisplayFunc (display);
glutIdleFunc (display);
glutReshapeFunc (reshape);
glutKeyboardFunc (keyboard);
glutMainLoop ();
}
- 1134 megtekintés