Transformaciones
#include<GL/glut.h>
#include <glut.h>
void trans(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (0.1, 0.0, 0.1);
glBegin(GL_POLYGON);
glVertex3f (2.0, 2.0, 0.0);
glVertex3f (7.0, 2.0, 0.0);
glVertex3f (7.0, 7.0, 0.0);
glVertex3f (2.0, 7.0, 0.0);
glEnd();
glColor3f (1.0, 1.0, 1.0);
glPushMatrix();
glTranslatef(2.0f,2.0f,0.0f);
glBegin(GL_POLYGON);
glVertex3f (2.0, 2.0, 0.0);
glVertex3f (7.0, 2.0, 0.0);
glVertex3f (7.0, 7.0, 0.0);
glVertex3f (2.0, 7.0, 0.0);
glEnd();
glPopMatrix();
}
void escal(){
glColor3f(0.0, 0.0, 0.1);
glScalef(0.5,0.5,0.0);
glBegin(GL_POLYGON);
glVertex3f (2.0, 2.0, 0.0);
glVertex3f (7.0, 2.0, 0.0);
glVertex3f (7.0, 7.0, 0.0);
glVertex3f (2.0, 7.0, 0.0);
glEnd();
glFlush ();
}
void rot(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (0.5, 0.8, 0.2);
glPushMatrix();
glRotatef(45,0,0,1);
glBegin(GL_POLYGON);
glVertex3f (2.0, 2.0, 0.0);
glVertex3f (7.0, 2.0, 0.0);
glVertex3f (7.0, 7.0, 0.0);
glVertex3f (2.0, 7.0, 0.0);
glEnd();
glPopMatrix();
glFlush ();
}
void init (void)
{
glClearColor (1.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-15.0, 15.0, -15.0, 15.0, -2.0, 4.0);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -5.0f);
glRotatef(15, 1.0f, 0.0f, 0.0f);
glRotatef(15, 0.0f, 1.0f, 0.0f);
}
void keyboard(unsigned char key, int x, int y)
{
switch(key)
{
case 'p':
case 'P':
trans();
break;
case 'o':
case 'O':
rot();
break;
case 'i':
case 'I':
escal();
break;
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (600, 600);
glutInitWindowPosition (100, 100);
glutCreateWindow ("proyectox");
init ();
glutDisplayFunc(rot);
glutDisplayFunc(trans);
glutMainLoop();
return 0;
}
No hay comentarios:
Publicar un comentario