Ir ao conteúdo
  • Cadastre-se

Beatriz Yakamura

Membro Júnior
  • Posts

    6
  • Cadastrado em

  • Última visita

Reputação

8
  1. @V!OLADOR Funcionou, depois só precisei aplicar o scaling para que o polígono vermelho ficasse do tamanho do polígono azul. Obrigada! void display() { glClear(GL_COLOR_BUFFER_BIT); glLineWidth(2.0); // Desenhar polígono vermelho glPushMatrix(); // Salva a matriz atual na pilha glTranslatef(4.0, 4.0, 0.0); // Translada para a posição final desejada glRotatef(45.0, 0.0, 0.0, 1.0); // Rotaciona o sistema de coordenadas em 45 graus no eixo z glScalef(1.4, 1.4, 1.4); // Escala para o mesmo tamanho do polígono azul; glTranslatef(-4.0, -4.0, 0.0); // Translada para a origem (0, 0) glBegin(GL_LINES); glColor3f(1.0, 0.0, 0.0); glVertex2f(3.0, 4.0); glVertex2f(4.0, 5.0); glVertex2f(4.0, 5.0); glVertex2f(5.0, 4.0); glVertex2f(5.0, 4.0); glVertex2f(4.0, 3.0); glVertex2f(4.0, 3.0); glVertex2f(3.0, 4.0); glEnd(); glPopMatrix(); // Restaura a matriz anterior da pilha // Desenhar polígono azul glBegin(GL_LINES); glColor3f(0.0, 0.0, 1.0); glVertex2f(3.0, 5.0); glVertex2f(5.0, 5.0); glVertex2f(5.0, 5.0); glVertex2f(5.0, 3.0); glVertex2f(5.0, 3.0); glVertex2f(3.0, 3.0); glVertex2f(3.0, 3.0); glVertex2f(3.0, 5.0); glEnd(); glFlush(); }
  2. @Otávio Amorim Eu fiz assim, mas acho que não foi a abordagem correta, na saída o polígono aparece fora de posição. // Centra as coordenadas do polígono vermelho em (0,0) float centerX = (3.0 + 4.0 + 4.0 + 5.0) / 4.0; float centerY = (4.0 + 5.0 + 5.0 + 4.0) / 4.0; glTranslatef(-centerX, -centerY, 0.0); // Translada para centralizar o polígono vermelho glTranslatef(4.0, 4.0, 0.0); // Translada o sistema de coordenadas para o centro do polígono azul glRotatef(45.0, 0.0, 0.0, 1.0); // Rotaciona o sistema de coordenadas em 45 graus no eixo z glTranslatef(-4.0, -4.0, 0.0); // Translada o sistema de coordenadas de volta para a origem
  3. @Otávio Amorim Assim? A saída foi apenas o polígono azul. void display() { glClear(GL_COLOR_BUFFER_BIT); glLineWidth(2.0); glPushMatrix(); // salva a matriz atual na pilha glLoadIdentity(); // carrega a matriz identidade glTranslatef(4.0, 4.0, 0.0); // translada o sistema de coordenadas para o centro do polígono azul glRotatef(45.0, 0.0, 0.0, 1.0); // rotaciona o sistema de coordenadas em 45 graus no eixo z glTranslatef(-4.0, -4.0, 0.0); // translada o sistema de coordenadas de volta para a origem glBegin(GL_LINES); glColor3f(1.0, 0.0, 0.0); // poligono vermelho glVertex2f(3.0, 4.0); glVertex2f(4.0, 5.0); glVertex2f(4.0, 5.0); glVertex2f(5.0, 4.0); glVertex2f(5.0, 4.0); glVertex2f(4.0, 3.0); glVertex2f(4.0, 3.0); glVertex2f(3.0, 4.0); glEnd(); glPopMatrix(); // restaura a matriz anterior da pilha glBegin(GL_LINES); glColor3f(0.0, 0.0, 1.0); // poligono azul glVertex2f(3.0, 5.0); glVertex2f(5.0, 5.0); glVertex2f(5.0, 5.0); glVertex2f(5.0, 3.0); glVertex2f(5.0, 3.0); glVertex2f(3.0, 3.0); glVertex2f(3.0, 3.0); glVertex2f(3.0, 5.0); glEnd(); glFlush(); }
  4. Preciso determinar a sequência de operações em OpenGL que fazem com que o polígono vermelho seja desenhada na posição do polígono azul. #include <GL/glut.h> void init() { glClearColor(0.0, 0.0, 0.0, 0.0); gluOrtho2D(0.0, 6.0, 0.0, 6.0); } void display() { glClear(GL_COLOR_BUFFER_BIT); glLineWidth(2.0); glBegin(GL_LINES); glColor3f(1.0, 0.0, 0.0); // poligono vermelho glVertex2f(3.0, 4.0); glVertex2f(4.0, 5.0); glVertex2f(4.0, 5.0); glVertex2f(5.0, 4.0); glVertex2f(5.0, 4.0); glVertex2f(4.0, 3.0); glVertex2f(4.0, 3.0); glVertex2f(3.0, 4.0); glColor3f(0.0, 0.0, 1.0); // poligono azul glVertex2f(3.0, 5.0); glVertex2f(5.0, 5.0); glVertex2f(5.0, 5.0); glVertex2f(5.0, 3.0); glVertex2f(5.0, 3.0); glVertex2f(3.0, 3.0); glVertex2f(3.0, 3.0); glVertex2f(3.0, 5.0); glEnd(); glFlush(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(500, 500); glutCreateWindow("poligonos"); init(); glutDisplayFunc(display); glutMainLoop(); return 0; }

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

 

GRÁTIS: ebook Redes Wi-Fi – 2ª Edição

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!