Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Practica 1 Informática Gráfica
- */
- #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>
- using namespace std;
- #include <GL/glut.h>
- #include <iostream>
- #include <cstdlib>
- float xi, yi, zi;
- float angleZ, angleX;
- int screenWidth = 640;
- int screenHeight = 480;
- //DEFINICION DE FUNCIONES DE CALLBACK
- //Coloca la imagen raster en la posicion del puntero del raton al pulsar boton izdo. Limpia la ventana co el boton derecho
- void myMouse(int button, int state, int mx, int my) {
- if (button == GLUT_LEFT_BUTTON)
- {
- }
- if (button == GLUT_RIGHT_BUTTON) {
- }
- glutPostRedisplay();
- }
- void dibujarEje() {
- //DIBUJA UN CONJUNTO DE PUNTOS
- glBegin(GL_LINES);
- glColor3f(1, 0, 0);
- glVertex3f(0.0, 0.0, 0.0);
- glVertex3f(1.0, 0.0, 0.0);
- glColor3f(0, 1, 0);
- glVertex3f(0.0, 0.0, 0.0);
- glVertex3f(0.0, 1.0, 0.0);
- glColor3f(0, 0, 1);
- glVertex3f(-1.0, -1.0, -1.0);
- glVertex3f(0.0, 0.0, 1.0);
- glEnd();
- }
- //Cambia las dimensiones de la pantalla
- void myReshape(int w, int h) {
- screenWidth = w;
- screenHeight = h;
- }
- //Dibuja el raster
- void myDisplay(void) {
- glClearColor(0.0, 0.0, 0.0, 0.0);
- glClear(GL_COLOR_BUFFER_BIT);
- glLoadIdentity();
- dibujarEje();
- GLfloat matrizT[16] = { 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0,xi, yi, zi, 1.0 };
- GLfloat matrizR[16] = { cos(angleZ), sin(angleZ), 0.0, 0.0, -sin(angleZ), cos(angleZ), 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 };
- GLfloat matrizX[16] = { 1.0, 0.0, 0.0, 0.0, 0.0, cos(angleX), sin(angleX), 0.0, 0.0, -sin(angleX), cos(angleX), 0.0,0.0, 0.0, 0.0, 1.0 };
- glMultMatrixf(matrizT);
- glMultMatrixf(matrizR);
- glMultMatrixf(matrizX);
- glColor3f(1.0f, 1.0f, 1.0f);
- glutWireTeapot(1.0f);
- glFlush();
- }
- //Control por teclado
- void myKeys(unsigned char key, int x, int y) {
- switch (key)
- {
- case 'a':
- case 'A':
- xi += -0.5;
- break;
- case 'w':
- case 'W':
- yi += 0.5;
- break;
- case 's':
- case 'S':
- yi += -0.5;
- break;
- case 'D':
- case 'd':
- xi += 0.5;
- break;
- case 'f':
- case 'F':
- angleZ += 5.0;
- break;
- case 'g':
- case 'G':
- angleZ += -5.0;
- break;
- case 'y':
- case 'Y':
- angleX += 5.0;
- break;
- case 'h':
- case 'H':
- angleX += -5.0;
- break;
- case 'q': exit(0);
- }
- glutPostRedisplay();
- }
- void myIdle()
- {
- // Número de milisegundos que han pasado desde que se inicio el programa
- long int currentTime = glutGet(GLUT_ELAPSED_TIME);
- // animacion en funcion del tiempo
- glutPostRedisplay();
- }
- int main(int argc, char** argv) {
- //CREACION DEL ENTORNO GRAFICO
- glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
- glutInitWindowSize(screenWidth, screenHeight);
- glutInitWindowPosition(30, 30);
- glutInit(&argc, argv);
- glutCreateWindow("Lab. Informatica Grafica");
- //--------------------
- //Damos de alta a las funciones de Callback
- glutKeyboardFunc(myKeys);
- glutMouseFunc(myMouse);
- glutDisplayFunc(myDisplay);
- glutReshapeFunc(myReshape);
- //glutIdleFunc(myIdle); //comentada por eficiencia
- //--------------------
- //Funciones de limpieza de la pantalla
- glClearColor(0.0, 0.0, 0.0, 0.0);
- glClear(GL_COLOR_BUFFER_BIT);
- //---------------------
- glFlush();
- glMatrixMode(GL_PROJECTION);
- //izda,dcha,abajo,arriba
- glLoadIdentity();
- glOrtho(-5.0, 5.0, -5.0, 5.0, -2.5, 2.5); //Vista en 3D
- glMatrixMode(GL_MODELVIEW);
- //x,y,anchura,altura
- glViewport(0, 0, 640, 480);
- //Llamada al bucle principal de recoleccion de eventos
- glutMainLoop();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement