PRACTICA 1: ROTACIÓN Y TRASLACIÓN
#include <windows.h>#include <C:\GLUT\include\GL\glut.h>
#include <stdlib.h>
#include <math.h>
float cx=0,cy=0,lado=50;
float r,g,b,dx,dy,pi=3.141592653;
int ancho=500,alto=500,linea=8,inc=1,radio;
void cuadro(int lado, float r, float g, float b)
{
glColor3f(r,g,b);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(lado, lado);glVertex2f(-lado, lado);
glColor3f(r,g-1,b);
glVertex2f(-lado, -lado);glVertex2f(lado, -lado);
glEnd();
}
void key(unsigned char c, int x, int y)
{
if (c==27){exit(0);}
if (c=='a'){inc = inc + 10;}
if (c=='s'){inc = inc - 10;}
glutPostRedisplay();
}
void circulo(float radio,float r,float g,float b,float m)
{
glBegin(GL_POLYGON);
glColor3f(r,g,b);
glVertex2f(cx, cy);
for (float i=0; i< m; i+=0.1)
{
dx=radio*cos(i)+cx;
dy=radio*sin(i)+cy;
glVertex2f(dx, dy);
}
glEnd();
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
//SOL
glPushMatrix();
glRotatef(inc,0,0,1);
glPushMatrix();
cuadro(100,1.0,1.0,0.0);
glRotatef(45,0,0,1);
cuadro(100,1,1.0,0.0);
circulo(110,1,0.9,0,2*pi+0.1);
glPopMatrix();
glPopMatrix();
//NUBE
glPushMatrix();
glTranslatef(inc,0,1);
glTranslatef(100,-60,0);
circulo(45,1,1,1,pi);
glTranslatef(-30,30,0);
circulo(45,1,1,1,pi+0.7+0.1);
glTranslatef(-30,20,0);
circulo(45,1,1,1,pi+0.5);
glTranslatef(-20,-50,0);
circulo(45,1,1,1,pi);
glPopMatrix();
glPopMatrix();
glFlush();
}
void Init()
{ glClearColor(0.0,0.0,1.0,0);
gluOrtho2D(-ancho/2,ancho/2,-alto/2,alto/2);
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(100,100);
glutInitWindowSize(ancho,alto);
glutCreateWindow("SOLECITO");
Init();
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutMainLoop();
return 0;
}
No hay comentarios:
Publicar un comentario