martes, 13 de marzo de 2012

Investigacion.

1.Proyección en OpenGL.
Ortogonal:
# Include <GL / gl.h>
#include < GL / glut.h > # Include <GL / glut.h>
#include < windows.h > # Include <windows.h>
#include < stdio.h > # Include <stdio.h>



int w1; int w1;
int h1; int h1;


void orthogonalStart ( void ) { orthogonalStart vacío (void) {
glMatrixMode ( GL_PROJECTION ) ; glMatrixMode (GL_PROJECTION);
glPushMatrix ( ) ; glPushMatrix ();
glLoadIdentity ( ) ; glLoadIdentity ();
gluOrtho2D ( 0, w1, 0, h1 ) ; gluOrtho2D (0, w1, 0, H1);
glScalef ( 1, - 1, 1 ) ; glScalef (1, - 1, 1);
glTranslatef ( 0, - h1, 0 ) ; glTranslatef (0, - h1, 0);
glMatrixMode ( GL_MODELVIEW ) ; glMatrixMode (GL_MODELVIEW);
} }


void orthogonalEnd ( void ) { orthogonalEnd vacío (void) {
glMatrixMode ( GL_PROJECTION ) ; glMatrixMode (GL_PROJECTION);
glPopMatrix ( ) ; glPopMatrix ();
glMatrixMode ( GL_MODELVIEW ) ; glMatrixMode (GL_MODELVIEW);
} }


void display ( void ) { void display (void) {
glClearColor ( 1.0,0.0,0.0,1.0 ) ; glClearColor (1.0,0.0,0.0,1.0);
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ; glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity ( ) ; glLoadIdentity ();


orthogonalStart ( ) ; orthogonalStart ();

glBegin ( GL_QUADS ) ; glBegin (GL_QUADS);
glVertex2f ( 125, 125 ) ; glVertex2f (125, 125);
glVertex2f ( 125, 375 ) ; glVertex2f (125, 375);
glVertex2f ( 375, 375 ) ; glVertex2f (375, 375);
glVertex2f ( 375, 125 ) ; glVertex2f (375, 125);
glEnd ( ) ; glEnd ();


orthogonalEnd ( ) ; orthogonalEnd ();

glutSwapBuffers ( ) ; glutSwapBuffers ();
} }


void reshape ( int w, int h ) { anular remodelar (int w, int h) {
glViewport ( 0, 0, ( GLsizei ) w, ( GLsizei ) h ) ; glViewport (0, 0, (GLsizei) w, (GLsizei) yh);
glMatrixMode ( GL_PROJECTION ) ; glMatrixMode (GL_PROJECTION);
glLoadIdentity ( ) ; glLoadIdentity ();
gluPerspective ( 60, ( GLfloat ) w / ( GLfloat ) h, 0.1, 1000.0 ) ; gluPerspective (60, (GLfloat) W / (GLfloat) h, 0,1, 1000,0);
w1 = w; w1 = w;
h1 = h; h1 = h;
glMatrixMode ( GL_MODELVIEW ) ; glMatrixMode (GL_MODELVIEW);
} }


int main ( int argc, char * * argv ) { int main (int argc, char ** argv) {
glutInit ( & argc, argv ) ; glutInit (& argc, argv);
glutInitDisplayMode ( GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGBA glutInitDisplayMode (GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGBA
) ; );
glutInitWindowSize ( 500, 500 ) ; glutInitWindowSize (500, 500);
glutInitWindowPosition ( 100, 100 ) ; glutInitWindowPosition (100, 100);
glutCreateWindow ( “A Basic Window) ; glutCreateWindow ("Una ventana de base");
glutDisplayFunc ( display ) ; glutDisplayFunc (pantalla);
glutIdleFunc ( display ) ; glutIdleFunc (pantalla);
glutReshapeFunc ( reshape ) ; glutReshapeFunc (reformar);
glutMainLoop ( ) ; glutMainLoop ();
return 0; return 0;
} }


Perspectiva:
#include <GL/gl.h>
#include <GL/glut.h>


long v[8][3] = {
 {-1, -1, -1},
 {-1, -1,  1},
 {-1,  1,  1},
 {-1,  1, -1},
 { 1, -1, -1},
 { 1, -1,  1},
 { 1,  1,  1},
 { 1,  1, -1}
};
int path[16] = {
 0, 1, 2, 3,
 0, 4, 5, 6,
 7, 4, 5, 1,
 2, 6, 7, 3
};

void drawcube() {
 int i;

 glClear(GL_COLOR_BUFFER_BIT);
 glColor3f(0.0, 0.0, 0.0); 

 glBegin(GL_LINE_STRIP);
 for (i=0; i < 16; i++)
  glVertex3i(v[path[i]][0], v[path[i]][1], v[path[i]][2]);
 glEnd();
 glFlush();
}

main(int argc, char **argv) {
 glutInit(&argc, argv);
 glutInitWindowSize(600, 400);
 glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
 glutCreateWindow("glLookat example");

 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 gluPerspective(30.0, 1.5, 0.1, 10.0);
 gluLookAt(5.0, 4.0, 6.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0);
       
 glMatrixMode(GL_MODELVIEW);

 glClearColor(1.0, 1.0, 1.0, 0.0);  /* white */

 glutDisplayFunc(drawcube);
 glutMainLoop();
 return 0;
}

2.Transformaciones geometricas:

Ejemplo de rotación, traslación y escalar.
/*
 Programa que demuestra la ejecución de transformaciones del tipo
 mover, rotar, escalar en 3D de modo interactivo mediante el mouse.
 Se utiliza un sistema de menú para la selección de las distintas operaciones.
*/ 

#include <GL/glut.h>
#include <GL/glaux.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

struct Point3f
 {
 float x, y, z;
 };

struct Face
 {
 int vertexIndices[3];
 int smoothingGroup;
 Point3f normal[3];
 Point3f faceNormal;
 };

struct Object3D
 {
 int nVertices;
 Point3f *pVertices;   
 int nFaces;
 Face *pFaces;      
 };

enum {ROT_EJE_X, ROT_EJE_Y, ROT_EJE_Z,
   MOV_EJE_X,MOV_EJE_Y,MOV_EJE_Z,MOV_EJE_XY,   
   SCAL_EJE_X,SCAL_EJE_Y,SCAL_EJE_Z,SCAL_EJE_XYZ};
Object3D obj;
int moving, begin_x,begin_y;
int newModel = 1;
GLfloat trasl_x, trasl_y;
GLfloat escala_x, escala_y;
GLfloat angle =0.f;
GLboolean ROTAR=FALSE;
GLboolean MOVER=FALSE;
GLboolean ESCALAR=FALSE;
GLfloat EJE_X=0.0;
GLfloat EJE_Y=0.0;
GLfloat EJE_Z=0.0;
float LightPos[] = { 0.0f, 0.0f, 1.0f, 0.0f};         
float LightAmb[] = { 0.2f, 0.2f, 0.2f, 1.0f};         
float LightDif[] = { 1.0f, 1.0f, 1.0f, 1.0f};           
float LightSpc[] = { 0.5f, 0.5f, 0.5f, 1.0f};   

void CargarModelo(char *filename, Object3D &object)
{
 FILE  *file;
 char  *tempString = new char [80];
 char  trash[15];
 float tempX, tempY, tempZ;
 int   tempA, tempB, tempC;
 int   indexSmoothing;
 int   i;
 
 if((file = fopen(filename, "rt"))==NULL)
 {
 printf("File Not Found : %s\n",filename);
 exit(1);
 }
 while(strncmp(tempString, "Vertices",8))
 {
 fscanf(file, "%s", tempString);
 if (feof(file))
  {
  printf("String \"Vertices\" no existe\n");
  exit(1);
  }
 }
 fgetc(file);    
 fscanf(file, "%d", &object.nVertices);
 object.pVertices = new Point3f[object.nVertices];
 for (i=0; i<object.nVertices; i++)
 {
  fscanf(file, "%f %f %f\n", &tempX, &tempY, &tempZ);
 object.pVertices[i].x=tempX;
 object.pVertices[i].y=tempY;
 object.pVertices[i].z=tempZ;
 }
 while(strncmp(tempString, "Faces",5))
 {
 fscanf(file, "%s", tempString);
 if (feof(file))
  {
  printf("String \"Faces\" no existe\n");
  exit(1);
  }
 }
 fgetc(file);    
 fscanf(file, "%d", &object.nFaces);
 object.pFaces = new Face[object.nFaces];
 for (i=0; i<object.nFaces; i++)
 {
  fscanf(file, "%d %d %d\n", &tempA, &tempB, &tempC);
 fscanf(file, "%s %d\n", &trash, &indexSmoothing);
 object.pFaces[i].vertexIndices[0]=tempA;
 object.pFaces[i].vertexIndices[1]=tempB;
 object.pFaces[i].vertexIndices[2]=tempC;
 object.pFaces[i].smoothingGroup=indexSmoothing;
 }
}


void applySmoothingGroups(Object3D &object)
{
int i,j,k,l,smoothingGroup;
float length;

for (i=0; i<object.nFaces; i++)
 {
 smoothingGroup = object.pFaces[i].smoothingGroup;
 for (j=i+1; j<object.nFaces; j++)
  {
  if (smoothingGroup == object.pFaces[j].smoothingGroup)
   {
   for (k=0; k<3; k++)
    {
    for (l=0; l<3; l++)
     {
     if (object.pFaces[i].vertexIndices[k] == object.pFaces[j].vertexIndices[l])
      {
      object.pFaces[i].normal[k].x += object.pFaces[j].faceNormal.x;
      object.pFaces[i].normal[k].y += object.pFaces[j].faceNormal.y;
      object.pFaces[i].normal[k].z += object.pFaces[j].faceNormal.z;
      object.pFaces[j].normal[l].x += object.pFaces[i].faceNormal.x;
      object.pFaces[j].normal[l].y += object.pFaces[i].faceNormal.y;
      object.pFaces[j].normal[l].z += object.pFaces[i].faceNormal.z;
      }
     }
    }
   }
  }
 for (k=0; k<3; k++)
  {
  length = sqrt(pow(object.pFaces[i].normal[k].x,2.0) +
          pow(object.pFaces[i].normal[k].y,2.0) +
          pow(object.pFaces[i].normal[k].z,2.0));

  if (length == 0)
   {
   object.pFaces[i].normal[k].x = 1;
   object.pFaces[i].normal[k].y = 1;
   object.pFaces[i].normal[k].z = 1;
   }
  else
   {
   object.pFaces[i].normal[k].x /= length;
   object.pFaces[i].normal[k].y /= length;
   object.pFaces[i].normal[k].z /= length;
   }
  }
 }
}


void CalcularNormales(Object3D &object)
{
 float x1, y1, z1;
 float x2, y2, z2;
 float x3, y3, z3;
 float length;
 int   a, b, c;
 int   i;

 for (i=0; i<object.nFaces; i++)
 {
 Face& face = object.pFaces[i];
 a = face.vertexIndices[0];
 b = face.vertexIndices[1];
 c = face.vertexIndices[2];
 x1 = object.pVertices[b].x - object.pVertices[a].x;
 y1 = object.pVertices[b].y - object.pVertices[a].y;
 z1 = object.pVertices[b].z - object.pVertices[a].z;
 x2 = object.pVertices[c].x - object.pVertices[a].x;
 y2 = object.pVertices[c].y - object.pVertices[a].y;
 z2 = object.pVertices[c].z - object.pVertices[a].z;
 z3 = x1*y2 - y1*x2;
 x3 = y1*z2 - z1*y2;
 y3 = z1*x2 - x1*z2;
 length = sqrt(x3*x3 + y3*y3 + z3*z3);
 if (length == 0)
  {
  face.faceNormal.x=1;
  face.faceNormal.y=1;
  face.faceNormal.z=1;
  }
 else
  {
  face.faceNormal.x=x3/length;
  face.faceNormal.y=y3/length;
  face.faceNormal.z=z3/length;
  }
 face.normal[0].x=face.normal[1].x=face.normal[2].x=face.faceNormal.x;
 face.normal[0].y=face.normal[1].y=face.normal[2].y=face.faceNormal.y;
 face.normal[0].z=face.normal[1].z=face.normal[2].z=face.faceNormal.z;
 }
}


void killObject(Object3D &object)
{
 delete[] object.pFaces;
 object.pFaces = NULL;
 object.nFaces = 0;
 delete[] object.pVertices;
 object.pVertices = NULL;
 object.nVertices = 0;
}


void mouse(int button, int state, int x, int y)
{
 if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
 moving = 1;
 begin_x = x;
 begin_y = y;
 }
 if (button == GLUT_LEFT_BUTTON && state == GLUT_UP) {
 moving = 0;
 }
}


void movimiento(int x, int y)
{ //Captura el movimiento del mouse.
 if (moving) {  
 trasl_x=(GLfloat)(x - begin_x)/100.0;
 trasl_y=(GLfloat)(y - begin_y)/100.0;
 angle = (GLfloat)(x - begin_x)/5.0;
 escala_x=(GLfloat)(x - begin_x)/20.0;
 if(escala_x < -0.9f) 
  escala_x=-0.9;
 begin_x = x;
 begin_y = y;
 newModel = 1;
 glutPostRedisplay();
 }
}


void controlTransf(int value)
{//Casos del menu de opciones.
 switch (value)
 {
 //printf (" Se ha seleccionado la opcion de rotar en el eje X\n");
 case ROT_EJE_X:
  ROTAR=TRUE;
  MOVER=FALSE;
  ESCALAR=FALSE;
  EJE_X=1.0;
  EJE_Y=0.0;
  EJE_Z=0.0;
  break;
 //printf (" Se ha seleccionado la opcion de rotar en el eje Y\n");
 case ROT_EJE_Y:
  ROTAR=TRUE;
  MOVER=FALSE;
  ESCALAR=FALSE;
  EJE_X=0.0;
  EJE_Y=1.0;
  EJE_Z=0.0;
  break;
 //printf (" Se ha seleccionado la opcion de rotar en el eje Z\n");
 case ROT_EJE_Z:
  ROTAR=TRUE;
  MOVER=FALSE;
  ESCALAR=FALSE;
  EJE_X=0.0;
  EJE_Y=0.0;
  EJE_Z=1.0;
  break;
 //printf (" Se ha seleccionado la opcion de mover en el eje X\n");
 case MOV_EJE_X:
  ROTAR=FALSE;
  MOVER=TRUE;
  ESCALAR=FALSE;
  EJE_X=1.0;
  EJE_Y=0.0;
  EJE_Z=0.0;
  break;
 //printf (" Se ha seleccionado la opcion de mover en el eje Y\n");
 case MOV_EJE_Y:
  ROTAR=FALSE;
  MOVER=TRUE;
  ESCALAR=FALSE;
  EJE_X=0.0;
  EJE_Y=1.0;
  EJE_Z=0.0;
  break;
 //printf (" Se ha seleccionado la opcion de mover en el eje Z\n");
 case MOV_EJE_Z:
  ROTAR=FALSE;
  MOVER=TRUE;
  ESCALAR=FALSE;
  EJE_X=0.0;
  EJE_Y=0.0;
  EJE_Z=1.0;
  break;
 //printf (" Se ha seleccionado la opcion de mover en los ejes XY\n");
 case MOV_EJE_XY:
  ROTAR=FALSE;
  MOVER=TRUE;
  ESCALAR=FALSE;
  EJE_X=1.0;
  EJE_Y=1.0;
  EJE_Z=0.0;
  break;
 //printf (" Se ha seleccionado la opcion de escalar en el eje X\n");
 case SCAL_EJE_X:
  ROTAR=FALSE;
  MOVER=FALSE;
  ESCALAR=TRUE;
  EJE_X=1.0;
  EJE_Y=0.0;
  EJE_Z=0.0;
  break;
 //printf (" Se ha seleccionado la opcion de escalar en el eje Y\n");
 case SCAL_EJE_Y:
  ROTAR=FALSE;
  MOVER=FALSE;
  ESCALAR=TRUE;
  EJE_X=0.0;
  EJE_Y=1.0;
  EJE_Z=0.0;
  break;
 //printf (" Se ha seleccionado la opcion de escalar en el eje Z\n");
 case SCAL_EJE_Z:
  ROTAR=FALSE;
  MOVER=FALSE;
  ESCALAR=TRUE;
  EJE_X=0.0;
  EJE_Y=0.0;
  EJE_Z=1.0;
  break;
 //printf (" Se ha seleccionado la opcion de escalar en los ejes XYZ\n");
 case SCAL_EJE_XYZ:
  ROTAR=FALSE;
  MOVER=FALSE;
  ESCALAR=TRUE;
  EJE_X=1.0;
  EJE_Y=1.0;
  EJE_Z=1.0;
  break;
 }
 glutPostRedisplay();
}


void recalcModelView(void)
{
 glPopMatrix();
 if(ROTAR) //Transformación de rotacion
 glRotatef(angle, EJE_X, EJE_Y, EJE_Z); 
 if(MOVER)//Transformación de traslación
 glTranslatef(trasl_x*EJE_X, -trasl_y*EJE_Y,trasl_x*EJE_Z );
 if(ESCALAR)//Transformación de escalado
 glScaled(1.0 + escala_x*EJE_X, 1.0 +escala_x*EJE_Y, 1.0 + escala_x*EJE_Z); 
 glPushMatrix();
 newModel = 0;
}


void redibuja(void)
{
 GLfloat mat_ambient[] = { 0.02f, 0.16f, 0.16f, 1.0f };
 GLfloat mat_diffuse[] = { 0.1f, 0.9f, 1.0f, 1.0f };
 GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
 GLfloat mat_shininess[] = { 100.0f };
 int a, b, c;
 int i;

 if (newModel)
 recalcModelView();
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 glPushMatrix();
 
 glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
 glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
 glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
 glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

 glBegin(GL_TRIANGLES);
 for (i=0; i<obj.nFaces; i++)
 {
 const Face& face = obj.pFaces[i];
 a=face.vertexIndices[0];
 b=face.vertexIndices[1];
 c=face.vertexIndices[2];
 glNormal3f(face.normal[0].x, face.normal[0].y, face.normal[0].z); 
 glVertex3f(obj.pVertices[a].x, obj.pVertices[a].y, obj.pVertices[a].z);
 glNormal3f(face.normal[1].x, face.normal[1].y, face.normal[1].z); 
    glVertex3f(obj.pVertices[b].x, obj.pVertices[b].y, obj.pVertices[b].z);
 glNormal3f(face.normal[2].x, face.normal[2].y, face.normal[2].z); 
    glVertex3f(obj.pVertices[c].x, obj.pVertices[c].y, obj.pVertices[c].z);
 }
 glEnd();

 glPopMatrix();
 glFlush();
 glutSwapBuffers();
}


void init(void)
{
 glClearColor(0.0, 0.0, 0.0, 0.0);
 glShadeModel(GL_SMOOTH);
 glCullFace(GL_BACK);
 glEnable(GL_DEPTH_TEST);
 glEnable(GL_CULL_FACE);
 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
 glEnable(GL_DEPTH_TEST);
 glLightfv(GL_LIGHT0, GL_POSITION, LightPos);       
 glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmb);        
 glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDif);       
 glLightfv(GL_LIGHT0, GL_SPECULAR, LightSpc);     
 glEnable(GL_LIGHT0);                               
 glEnable(GL_LIGHTING);
 CargarModelo("ship.dat", obj);
 CalcularNormales(obj);
 applySmoothingGroups(obj);
}


int main(int argc, char **argv)
{
 int menu_rotar, menu_mover, menu_escalar;
 
 glutInit(&argc, argv);
 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
 glutInitWindowSize(400, 400);
 glutCreateWindow("Transformaciones con el mouse");
 glutDisplayFunc(redibuja);
 glutMouseFunc(mouse);
 glutMotionFunc(movimiento);
 menu_rotar=glutCreateMenu(controlTransf);
 glutAddMenuEntry("eje x", ROT_EJE_X);
 glutAddMenuEntry("eje y", ROT_EJE_Y);
 glutAddMenuEntry("eje z", ROT_EJE_Z);
 menu_mover=glutCreateMenu(controlTransf);
 glutAddMenuEntry("eje x", MOV_EJE_X);
 glutAddMenuEntry("eje y", MOV_EJE_Y);
 glutAddMenuEntry("eje z", MOV_EJE_Z);
 glutAddMenuEntry("ejes xy", MOV_EJE_XY);
 menu_escalar=glutCreateMenu(controlTransf);
 glutAddMenuEntry("eje x", SCAL_EJE_X);
 glutAddMenuEntry("eje y", SCAL_EJE_Y);
 glutAddMenuEntry("eje z", SCAL_EJE_Z);
 glutAddMenuEntry("ejes xyz", SCAL_EJE_XYZ);
 glutCreateMenu(controlTransf);
 glutAddSubMenu("Rotar", menu_rotar);
 glutAddSubMenu("Mover", menu_mover);
 glutAddSubMenu("Escalar", menu_escalar);
 glutAttachMenu(GLUT_RIGHT_BUTTON);
 init();
 /* Se establece la vista del cubo.*/
 glMatrixMode(GL_PROJECTION);
 gluPerspective(45.0, 1.0, 1.0, 10.0);
 glMatrixMode(GL_MODELVIEW);
 gluLookAt(0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.);      
 glPushMatrix();       
 glutMainLoop();
 killObject(obj);
 return 0; 
}

Translaciones

El caso de las translaciones en el espacio es idéntico al de las translaciones en el plano.

En esta ocasión también es posible realizar el desplazamiento sin necesidad de multiplicar por la matriz de transformación, basta simplemente con sumar a cada coordenada del punto el desplazamiento en el eje correspondiente que se desea realizar.

Escalado

Al igual que en el caso anterior, el escalado 3D no es más que una extensión del de dos dimensiones. Existen tres factores de escalado, uno para cada eje: Ex, Ey y Ez.

Al igual que en el escalado bidimensional: Si los tres factores son iguales la imagen resultante guardará proporcionalidad con la original. En el caso especial de que los tres factores tengan valor 1, la imagen no sufrirá cambios.

Rotaciones

La rotaciones 3D puede que no resulten tan simples de ver como las 2D.
Antes de nada, es necesario aclarar como se realizan este tipo de rotaciones. En este caso, al disponer de 3 ejes de coordenadas podemos realizar tres tipos de rotaciones: una rotación en el eje X, en el eje Y o en el eje Z.
Por ejemplo, una rotación en el eje X quiere decir que se realiza la rotación moviendo el eje Y hacia el eje Z, de forma que el X permanece inmóvil.
Las matrices de transformación para las rotaciones 3D de un ángulo 'o' son las siguientes: Para rotaciones en el eje X:


En el eje Y:


Y, en el eje Z:


3.Manejo de Matrices.
La transformación de las coordenadas se realiza internamente en OpenGL a partir de las
matrices de transformación y de las coordenadas de modelado del objeto. Sin embargo, para
representar el rastro que dibuja la tortuga al desplazarse, se realizará explícitamente la
transformación de la coordenada en la que se encuentra la tortuga. De esta forma se actúa
directamente en la matriz de transformación.

4.Pila de Matrices.
En la función display() se encuentran las llamadas a dos funciones. Se trata de glPushMatrix() y glPopMatrix(). Para comprender su funcionamiento, primero se experimenta que es lo que ocurre cuando están llamadas.
 void display(void) {
...
// glPushMatrix();
...
glTranslatef(0.0, 0.0, .5);
...
// glPopMatrix();
glutSwapBuffers();
}
Una pila es un almacén con funcionamiento LIFO, el último en entrar es el primero en
salir, por lo que suele comparar a una pila de platos en la que sólo se puede dejar uno encima
de la pila o coger el superior que es el último depositado. La pila de matrices tiene el mismo
funcionamiento sustituyendo los platos por matrices. La matriz superior de la pila es sobre la
que se aplican las distintas transformaciones, multiplicándola por la matriz que generan las
disntintas funciones.

La función glPushMatrix() realiza una copia de la matriz superior y la pone encima de
la pila, de tal forma que las dos matrices superiores son iguales.
La función glPopMatrix() elimina la matriz superior, quedando en la parte superior de
la pila la matriz que estaba en el momento de llamar a la función glPushMatrix().

Fuentes de información:
http://www.oocities.org/valcoey/mouse.html
http://www.alobbs.com/revistas/opengl3

No hay comentarios:

Publicar un comentario