Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <stdlib.h>
- #include <stdio.h>
- //#include <sys/time.h>
- #include <ctime>
- #ifdef __APPLE__
- #include <GLUT/glut.h>
- #else
- #include <GL/gl.h>
- #include <GL/glut.h>
- #endif
- #include <math.h>
- #include <iostream>
- #include <fstream>
- //#include <vector>
- using namespace std;
- string FICHERO = "movimiento.txt";
- struct punto
- {
- float x;
- float y;
- float z;
- };
- //Estaticos//
- const long int MAX_TAM = 10000;
- typedef punto vector[MAX_TAM];
- vector PUNTOS;
- typedef punto vectors[26];
- //Dinamicos//
- //vector<punto> PUNTOS;
- int screenWidth = 640;
- int screenHeight = 480;
- void LeerFicheroPuntos();
- void silueta(vectors);
- void frame(vectors);
- //DEFINICION DE FUNCIONES DE CALLBACK
- void LeerFicheroPuntos()
- {
- ifstream f;
- int i = 0;
- float prueba = 0;
- //float x, y, z;
- int cont = 0;
- f.open("posiciones.txt");
- if (f.is_open())
- {
- while (f >> prueba)
- {
- if (cont < 26)
- {
- PUNTOS[i].x = prueba;
- f >> PUNTOS[i].y;
- f >> PUNTOS[i].z;
- //cout << PUNTOS[i].x << " " << PUNTOS[i].y << " " << PUNTOS[i].z << endl;
- i++;
- cont++;
- }
- else
- cont = 0;
- }
- glEnd();
- }
- else
- cout << "Error" << endl;
- f.close();
- }
- void frame(vectors linea)
- {
- for (int i = 0; i < 26; i++)
- {
- linea[i].x = PUNTOS[i].x;
- linea[i].y = PUNTOS[i].y;
- linea[i].z = PUNTOS[i].z;
- }
- }
- void silueta(vectors linea)
- {
- glColor3f(1.0, 1.0, 1.0);
- glBegin(GL_LINES);
- //Pierna izquierda
- glVertex3f(linea[2].x, linea[2].y, linea[2].z);
- glVertex3f(linea[16].x, linea[16].y, linea[16].z);
- glVertex3f(linea[2].x, linea[2].y, linea[2].z);
- glVertex3f(linea[3].x, linea[3].y, linea[3].z);
- glVertex3f(linea[3].x, linea[3].y, linea[3].z);
- glVertex3f(linea[4].x, linea[4].y, linea[4].z);
- glVertex3f(linea[4].x, linea[4].y, linea[4].z);
- glVertex3f(linea[5].x, linea[5].y, linea[5].z);
- glVertex3f(linea[5].x, linea[5].y, linea[5].z);
- glVertex3f(linea[6].x, linea[6].y, linea[6].z);
- glVertex3f(linea[6].x, linea[6].y, linea[6].z);
- glVertex3f(linea[7].x, linea[7].y, linea[7].z);
- //Pierna derecha
- glVertex3f(linea[20].x, linea[20].y, linea[20].z);
- glVertex3f(linea[16].x, linea[16].y, linea[16].z);
- glVertex3f(linea[20].x, linea[20].y, linea[20].z);
- glVertex3f(linea[21].x, linea[21].y, linea[21].z);
- glVertex3f(linea[21].x, linea[21].y, linea[21].z);
- glVertex3f(linea[22].x, linea[22].y, linea[22].z);
- glVertex3f(linea[22].x, linea[22].y, linea[22].z);
- glVertex3f(linea[23].x, linea[23].y, linea[23].z);
- glVertex3f(linea[23].x, linea[23].y, linea[23].z);
- glVertex3f(linea[24].x, linea[24].y, linea[24].z);
- glVertex3f(linea[24].x, linea[24].y, linea[24].z);
- glVertex3f(linea[25].x, linea[25].y, linea[25].z);
- //Brazo izquierdo
- glVertex3f(linea[0].x, linea[0].y, linea[0].z);
- glVertex3f(linea[1].x, linea[1].y, linea[1].z);
- glVertex3f(linea[0].x, linea[0].y, linea[0].z);
- glVertex3f(linea[12].x, linea[12].y, linea[12].z);
- //Brazo derecho
- glVertex3f(linea[12].x, linea[12].y, linea[12].z);
- glVertex3f(linea[18].x, linea[18].y, linea[18].z);
- glVertex3f(linea[18].x, linea[18].y, linea[18].z);
- glVertex3f(linea[19].x, linea[19].y, linea[19].z);
- //Cabeza
- glVertex3f(linea[8].x, linea[8].y, linea[8].z);
- glVertex3f(linea[9].x, linea[9].y, linea[9].z);
- glVertex3f(linea[9].x, linea[9].y, linea[9].z);
- glVertex3f(linea[10].x, linea[10].y, linea[10].z);
- //Columna
- glVertex3f(linea[9].x, linea[9].y, linea[9].z);
- glVertex3f(linea[11].x, linea[11].y, linea[11].z);
- glVertex3f(linea[11].x, linea[11].y, linea[11].z);
- glVertex3f(linea[12].x, linea[12].y, linea[12].z);
- glVertex3f(linea[12].x, linea[12].y, linea[12].z);
- glVertex3f(linea[13].x, linea[13].y, linea[13].z);
- glVertex3f(linea[13].x, linea[13].y, linea[13].z);
- glVertex3f(linea[14].x, linea[14].y, linea[14].z);
- glVertex3f(linea[14].x, linea[14].y, linea[14].z);
- glVertex3f(linea[15].x, linea[15].y, linea[15].z);
- glVertex3f(linea[15].x, linea[15].y, linea[15].z);
- glVertex3f(linea[16].x, linea[16].y, linea[16].z);
- glVertex3f(linea[16].x, linea[16].y, linea[16].z);
- glVertex3f(linea[17].x, linea[17].y, linea[17].z);
- glEnd();
- }
- //Función del callback del ratón
- void myMouse(int button, int state, int mx, int my)
- {
- if (state == GLUT_DOWN)
- {
- if (button == GLUT_LEFT_BUTTON)
- {
- }
- else if (button == GLUT_RIGHT_BUTTON)
- {
- }
- glutPostRedisplay();
- }
- }
- //Función de callback de cambio del tamaño de la ventana
- void myReshape(int w, int h)
- {
- screenWidth = w;
- screenHeight = h;
- }
- //Función de callback del teclado
- void myKeys(unsigned char key, int x, int y)
- {
- switch (key)
- {
- case 'p':
- case 'P':
- break;
- case 'o':
- case 'O':
- break;
- }
- glutPostRedisplay();
- }
- void parallel() {
- float angle = 135 * 3.14 / 180;
- //Tercera proyección (3.3.3)
- float N[16] = { 1, 0, 0, 0,
- 0, 1, 0, 0,
- 0, -sin(angle) / cos(angle), 0, 0,
- 0, -1 * (sin(angle) / cos(angle)), -1, 1 };
- glMultMatrixf(N);
- }
- void myDisplay(void)
- {
- glClearColor(0.0, 0.0, 0.0, 0.0);
- glClear(GL_COLOR_BUFFER_BIT);
- glBegin(GL_LINES);
- vectors linea;
- frame(linea);
- /*En OpenGl existen dos instrucciones para configurar las ventanas de la transformación:
- void gluOrtho2D(Gldouble left, Gldouble right, Gldouble bottom, Gldouble top);
- Configura la Ventana del Mundo
- void glViewport(Glint x, Glint y, Glint width, Glint height);
- Configura el Puerto de Vista
- Estas instrucciones deben ser llamadas en la función de callback que se activa cada vez que se
- modifica el tamaño de la ventana de visualización (conocida generalmente con el nombre de
- MyReshape())
- void myReshape(int w, int h){
- glViewport(0,0,w,h);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- if(w <=h) //ventana grafica más ancha que alta
- gluOrtho2D(-2.0,2.0,-2.0* (float)h/w, 2.0* (float)h/w,2.0* (float)h/w, 2.0* (float)h/w );
- else
- gluOrtho2D(-2.0* (float)w/h, 2.0* (float)w/h,-2.0,2.0);
- glMatrixMode(GL_MODELVIEW);
- }*/
- silueta(linea);
- glEnd();
- glFlush();
- }
- //Funcion de actualizacion automatica
- //Es la función que se ejecuta siempre que no ocurran otros eventos
- void myIdle()
- {
- // Número de milisegundos que han pasado desde que se inicio el programa
- long int currentTime = glutGet(GLUT_ELAPSED_TIME);
- glutPostRedisplay();
- Sleep(1); // Esto si no tienes habilitado el vSync
- }
- int main(int argc, char ** argv)
- {
- //Inicialización de GLUT
- glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
- glutInitWindowSize(screenWidth, screenHeight);
- glutInitWindowPosition(30, 30);
- glutInit(&argc, argv);
- glutCreateWindow("Uso Basico OpenGl. Lab. Informatica Grafica");
- LeerFicheroPuntos();
- //--------------------
- //Damos de alta a las funciones de Callback
- glutKeyboardFunc(myKeys);
- glutMouseFunc(myMouse);
- glutDisplayFunc(myDisplay);
- glutReshapeFunc(myReshape);
- glutIdleFunc(myIdle);
- //--------------------
- //Configurar el color de borrado de la pantalla y borrar la pantalla
- glClearColor(0.0, 0.0, 0.0, 0.0);
- glClear(GL_COLOR_BUFFER_BIT);
- //---------------------
- glFlush();
- //Configuración de la vista
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(-1000.0, 1000.0, 1000.0, -1000.0, 1000, -1000);
- glMatrixMode(GL_MODELVIEW);
- //x,y,anchura,altura
- glViewport(0, 0, screenWidth, screenHeight);
- //Llamada al bucle principal de recoleccion de eventos
- glutMainLoop();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement