Aquí está un diagrama que muestra cómo un conjunto diferente de las imágenes de mapa de cubo forman las caras de un cubo.
/** Garnica Ayala Héctor Daniel CubeMap: Se puede "capturar" una vista de 360 grados de los alrededores de pie en un solo lugar y tomando seis fotografías cada una a una vista ortogonal de 90 grados de los demás */ #include#include #include #include /*******Variables Globales*****/ float a; /// int anchoImagen=512,altoImagen=512;///dimensiones de las imagenes unsigned char * imagenDown; unsigned char * imagenLeft; unsigned char * imagenBack; unsigned char * imagenFront; unsigned char * imagenRight; unsigned char * imagenTop; int leerimagenDown(){///piso FILE *imagen; imagen=fopen("C:/Users/host/Documents/PROG_Graficacion/sdoparcial/CubeMap/down.RAW","r"); imagenDown=(unsigned char*)malloc(anchoImagen*altoImagen*3); if(imagen==NULL){ printf("Error: No imagen"); return 0; } fread(imagenDown,anchoImagen*altoImagen*3,1,imagen); fclose(imagen); return 1; } int leerimagenLeft(){///lado izquierdo FILE *imagen; imagen=fopen("C:/Users/host/Documents/PROG_Graficacion/sdoparcial/CubeMap/left.RAW","r"); imagenLeft=(unsigned char*)malloc(anchoImagen*altoImagen*3); if(imagen==NULL){ printf("Error: No imagen"); return 0; } fread(imagenLeft,anchoImagen*altoImagen*3,1,imagen); fclose(imagen); return 1; } int leerimagenFront(){///parte frontal FILE *imagen; imagen=fopen("C:/Users/host/Documents/PROG_Graficacion/sdoparcial/CubeMap/front.RAW","r"); imagenFront=(unsigned char*)malloc(anchoImagen*altoImagen*3); if(imagen==NULL){ printf("Error: No imagen"); return 0; } fread(imagenFront,anchoImagen*altoImagen*3,1,imagen); fclose(imagen); return 1; } int leerimagenRight(){///lado derecho FILE *imagen; imagen=fopen("C:/Users/host/Documents/PROG_Graficacion/sdoparcial/CubeMap/right.RAW","r"); imagenRight=(unsigned char*)malloc(anchoImagen*altoImagen*3); if(imagen==NULL){ printf("Error: No imagen"); return 0; } fread(imagenRight,anchoImagen*altoImagen*3,1,imagen); fclose(imagen); return 1; } int leerimagenBack(){///parte trasera del cubo FILE *imagen; imagen=fopen("C:/Users/host/Documents/PROG_Graficacion/sdoparcial/CubeMap/back.RAW","r"); imagenBack=(unsigned char*)malloc(anchoImagen*altoImagen*3); if(imagen==NULL){ printf("Error: No imagen"); return 0; } fread(imagenBack,anchoImagen*altoImagen*3,1,imagen); fclose(imagen); return 1; } int leerimagenTop(){///techo o parte superior FILE *imagen; imagen=fopen("C:/Users/host/Documents/PROG_Graficacion/sdoparcial/CubeMap/top.RAW","r"); imagenTop=(unsigned char*)malloc(anchoImagen*altoImagen*3); if(imagen==NULL){ printf("Error: No imagen"); return 0; } fread(imagenTop,anchoImagen*altoImagen*3,1,imagen); fclose(imagen); return 1; } void texturaDown(void) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, anchoImagen, altoImagen, 0, GL_RGB, GL_UNSIGNED_BYTE, imagenDown); } void texturaLeft(void) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, anchoImagen, altoImagen, 0, GL_RGB, GL_UNSIGNED_BYTE, imagenLeft); } void texturaFront(void) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, anchoImagen, altoImagen, 0, GL_RGB, GL_UNSIGNED_BYTE, imagenFront); } void texturaRight(void) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, anchoImagen, altoImagen, 0, GL_RGB, GL_UNSIGNED_BYTE, imagenRight); } void texturaBack(void) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, anchoImagen, altoImagen, 0, GL_RGB, GL_UNSIGNED_BYTE, imagenBack); } void texturaTop(void) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, anchoImagen, altoImagen, 0, GL_RGB, GL_UNSIGNED_BYTE, imagenTop); } void dibujaDown(void) { glDisable(GL_LIGHTING); glColor3f(1,1,1); glBegin(GL_QUADS); glTexCoord3f(0.0, 1.0,0.0); glVertex3f(-100,-100,100); glTexCoord3f(0.0, 0.0,0.0); glVertex3f(-100,-100,-100); glTexCoord3f(1.0, 0.0,0.0); glVertex3f(100,-100,-100); glTexCoord3f(1.0, 1.0,0.0); glVertex3f(100,-100,100); glEnd(); glEnable(GL_LIGHTING); } void dibujaLeft(void) { glDisable(GL_LIGHTING); glColor3f(1,1,1); glBegin(GL_QUADS); glTexCoord3f(0.0, 1.0,0.0); glVertex3f(-100,-100,100); glTexCoord3f(0.0, 0.0,0.0); glVertex3f(-100,100,100); glTexCoord3f(1.0, 0.0,0.0); glVertex3f(-100,100,-100); glTexCoord3f(1.0, 1.0,0.0); glVertex3f(-100,-100,-100); glEnd(); glEnable(GL_LIGHTING); } void dibujaFront(void) { glDisable(GL_LIGHTING); glColor3f(1,1,1); glBegin(GL_QUADS); glTexCoord3f(0.0, 1.0,0.0); glVertex3f(-100,-100,-100); glTexCoord3f(0.0, 0.0,0.0); glVertex3f(-100,100,-100); glTexCoord3f(1.0, 0.0,0.0); glVertex3f(100,100,-100); glTexCoord3f(1.0, 1.0,0.0); glVertex3f(100,-100,-100); glEnd(); glEnable(GL_LIGHTING); } void dibujaRight(void) { glDisable(GL_LIGHTING); glColor3f(1,1,1); glBegin(GL_QUADS); glTexCoord3f(0.0, 1.0,0.0); glVertex3f(100,-100,-100); glTexCoord3f(0.0, 0.0,0.0); glVertex3f(100,100,-100); glTexCoord3f(1.0, 0.0,0.0); glVertex3f(100,100,100); glTexCoord3f(1.0, 1.0,0.0); glVertex3f(100,-100,100); glEnd(); glEnable(GL_LIGHTING); } void dibujaBack(void) { glDisable(GL_LIGHTING); glColor3f(1,1,1); glBegin(GL_QUADS); glTexCoord3f(0.0, 1.0,0.0); glVertex3f(100,-100,100); glTexCoord3f(0.0, 0.0,0.0); glVertex3f(100,100,100); glTexCoord3f(1.0, 0.0,0.0); glVertex3f(-100,100,100); glTexCoord3f(1.0, 1.0,0.0); glVertex3f(-100,-100,100); glEnd(); glEnable(GL_LIGHTING); } void dibujaTop(void) { glDisable(GL_LIGHTING); glColor3f(1,1,1); glBegin(GL_QUADS); glTexCoord3f(0.0, 1.0,0.0); glVertex3f(-100,100,-100); glTexCoord3f(0.0, 0.0,0.0); glVertex3f(-100,100,100); glTexCoord3f(1.0, 0.0,0.0); glVertex3f(100,100,100); glTexCoord3f(1.0, 1.0,0.0); glVertex3f(100,100,-100); glEnd(); glEnable(GL_LIGHTING); } void display(void) { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); GLfloat mat_specular[]={1.0,1.0,1.0,1.0}; GLfloat mat_shininess[]={80.0}; GLfloat mat_diff[]={1.0,0.5,0.0,0.5}; glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_diff); glPushMatrix(); glColor3f(1,1,1); glRotatef(a, 0, 1, 0); glPushMatrix(); texturaDown(); dibujaDown(); texturaLeft(); dibujaLeft(); texturaBack(); dibujaBack(); texturaFront(); dibujaFront(); texturaRight(); dibujaRight(); texturaTop(); dibujaTop(); glPopMatrix(); glPushMatrix();//TEAPOT glColor3f(1.0, 1.0, 1.0); glTranslated(0.0,10,0); glutSolidTeapot(3); glPopMatrix(); glPopMatrix(); a += 0.1;//velocidad de rotacion glutSwapBuffers(); } void myReshape(int w, int h) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective( 90.0, (GLdouble)w/(GLdouble)h, 0.1,200.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0.0, 15.0, 20.0, 0.0, 7.0, 0.0, 0.0, 1.0, 0.0); glEnable(GL_NORMALIZE); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); //glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_COLOR_MATERIAL); } void myIdleFunc(void) { glutPostRedisplay(); } void Init() { glEnable(GL_TEXTURE_2D); glMatrixMode(GL_PROJECTION); leerimagenDown(); leerimagenLeft(); leerimagenBack(); leerimagenFront(); leerimagenRight(); leerimagenTop(); } int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(600, 600); glutCreateWindow("CubeMap"); Init(); glutReshapeFunc(myReshape); glutDisplayFunc(display); glutIdleFunc(myIdleFunc); glClearColor(1.0, 1.0, 1.0, 1.0); glutMainLoop(); return 0; }
Descargar Archivo.txt
CuboMap.txt
No hay comentarios:
Publicar un comentario