// ********************************************************************** // PUCRS/FACIN // COMPUTAÇÃO GRÁFICA // // Programa básico para criar aplicações em OpenGL // // Marcio Sarroglia Pinho // pinho@inf.pucrs.br // ********************************************************************** #include #include #include #include #include "gl\glut.h" using namespace std; class Ponto { public: float x,y,z; char tipo; Ponto() { }; Ponto(float x,float y,float z, char tipo) { this->x=x; this->y=y; this->z=z;this->tipo=tipo; } }; Ponto *Esferas; int QtdTotal=0; int angulo=0; // ********************************************************************** // void init(void) // Inicializa os parâmetros globais de OpenGL // // ********************************************************************** void init(void) { srand(time(NULL)); string Nome = "4cpt.xyz"; //string Nome = "HIV_waterbox.xyz"; // Define a cor do fundo da tela (AZUL) glClearColor(0.0f, 0.0f, 1.0f, 1.0f); ifstream arq; arq.open(Nome.c_str(), ios::in); arq >> QtdTotal; Esferas = new Ponto[QtdTotal]; float x,y,z; char tipo; for (int i=0; i< QtdTotal; i++) { arq >> tipo; arq >> x; arq >> y; arq >> z; Esferas [i] = Ponto(x,y,z,tipo); } } // ********************************************************************** // void reshape( int w, int h ) // trata o redimensionamento da janela OpenGL // // ********************************************************************** void reshape( int w, int h ) { // Reset the coordinate system before modifying glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Define a área a ser ocupada pela área OpenGL dentro da Janela glViewport(0, 0, w, h); // Define os limites lógicos da área OpenGL dentro da Janela glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glOrtho(-50,50,-50,50,-300,300); } // ********************************************************************** // void display( void ) // // ********************************************************************** void DesenhaEsfera(float x, float y, float z) { glPushMatrix(); glTranslatef(x,y,z); glutWireSphere(5,10,10); glPopMatrix(); } // ********************************************************************** // void display( void ) // // ********************************************************************** void GeraCor(char tipo) { switch(tipo) { case 'N': glColor3f(1,0,0); break; case 'C': glColor3f(1,1,0); break; case '0': glColor3f(1,0,1); break; } //glColor3ub(rand()%256, rand()%256, rand()%256); } // ********************************************************************** // void display( void ) // // ********************************************************************** void DesenhaEsfera(int i) { GeraCor(Esferas[i].tipo); DesenhaEsfera(Esferas[i].x, Esferas[i].y, Esferas[i].z); } // ********************************************************************** // void display( void ) // // ********************************************************************** void display( void ) { // Limpa a tela coma cor de fundo glClear(GL_COLOR_BUFFER_BIT); // Define os limites lógicos da área OpenGL dentro da Janela glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glOrtho(-50,50,-50,50,-300,300); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // Coloque aqui as chamadas das rotinas que desenha os objetos // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< glLineWidth(3); glColor3f(1,1,1); glBegin(GL_LINES); glVertex2f(-10,0); glVertex2f(10,0); glEnd(); glLineWidth(3); glColor3f(0,1,0); glBegin(GL_LINES); glVertex2f(0,-10); glVertex2f(0,10); glEnd(); glRotatef(angulo,0,1,0); for(int i=0; i