#include <GL/gl.h>
#include <GL/glut.h>
#include <iostream>
#include <math.h>
#include <stdlib.h>//Importacion de librerarias
using namespace std; //Pues para mandar mensajes a pantala
#define NP 4000
#define AGE 200
float winWid,winHeight;
int rx,ry;//Declaracion de variables
float valores[30];
int count=0;
int countfig=0;
int figure[15];
//permitirá dibujar y recuperar la matriz
void redraw(void){
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
for(int i=0,j=0;i<count;i++,j++){
glPushMatrix();
double x=valores[i];
i++;
double y=valores[i];
x=(x-250)/250;
y=(y-250)/250;
glTranslatef(x,y,0); //Mueve el punto de origen
glColor3f(0.0,1.0,1.0);//Color
if(figure[j]==1){
glRotatef(55,9,22,0);
glutWireCube(0.2);
}
if(figure[j]==2){
glRotatef(45,0,1,1);
glutWireSphere(.2,16,16);
}
if(figure[j]==3){
glRotatef(60,1,0,0);
glutWireTorus(0.05,0.15,12.0,32.0);
}
if(figure[j]==4)
glutWireTeapot(0.2);
if(figure[j]==5){
glRotatef(60,1,0,0);
glutWireCone(0.2,0.5,22.0,5.0);
}
if(figure[j]==6){
glScalef(0.3,0.3,0.3);
glRotatef(55,9,22,0);
glutWireDodecahedron();
}
if(figure[j]==7){
glScalef(0.2,0.2,0.1);
glRotatef(45,0,1,1);
glutWireIcosahedron();
}
glPopMatrix();
}
glFlush();
}
//metodo que nos permite obeter las coordenadas al dar clic izquierdo
void mousebutton(int button, int state, int x, int y){
cerr << "mousebutton. x:" << x << ", y:" << y << " \n";
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){
rx = float(x);//debuelve el valor de donde se dio clic en el eje x
ry = winHeight - float(y);//debuelve el valor donde se dio clic en el eje y
}
}
//programar menu
void menu(int opc){
switch(opc){
case 1:
valores[count]=rx;
count++;
valores[count]=ry;
count++;
figure[countfig]=1;
countfig++;
redraw();
break;
case 2:
valores[count]=rx;
count++;
valores[count]=ry;
count++;
figure[countfig]=2;
countfig++;
redraw();
break;
case 3:
valores[count]=rx;
count++;
valores[count]=ry;
count++;
figure[countfig]=3;
countfig++;
redraw();
break;
case 4:
valores[count]=rx;
count++;
valores[count]=ry;
count++;
figure[countfig]=4;
countfig++;
redraw();
break;
case 5:
valores[count]=rx;
count++;
valores[count]=ry;
count++;
figure[countfig]=5;
countfig++;
redraw();
break;
case 6:
valores[count]=rx;
count++;
valores[count]=ry;
count++;
figure[countfig]=6;
countfig++;
redraw();
break;
case 7:
valores[count]=rx;
count++;
valores[count]=ry;
count++;
figure[countfig]=7;
countfig++;
redraw();
break;
}
}
main(int argc, char *argv[]){
winWid = 590.0;
winHeight = 550.0;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutCreateWindow(" ");
glutPositionWindow(200,100);
glutReshapeWindow(int(winWid),int(winHeight));
//glClearColor(0.0,0.0,0.0,1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0,winWid,0.0,winHeight, -100.0, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glutCreateMenu(menu);//crear menu
glutAddMenuEntry("Cubo",1);//opcion del menú
glutAddMenuEntry("Esfera",2);
glutAddMenuEntry("Dona",3);
glutAddMenuEntry("Tetera",4);
glutAddMenuEntry("Cono",5);
glutAddMenuEntry("Dodecaedro",6);
glutAddMenuEntry("Icosaedro",7);
glutAttachMenu(GLUT_RIGHT_BUTTON);//al presionar clic secundario
glutDisplayFunc(redraw);
glutMouseFunc(mousebutton);
glutMainLoop();
}
No hay comentarios:
Publicar un comentario