Ejemplo n.º 1
0
static void setMatrices(vcg::Point3f L, int screensize, int screensizeHard, bool sx){
  // orthonormal basis
  L.Normalize();
  Point3f ax,ay,az=L;
  ax=az^Point3f(1,0,0);
  if (ax.SquaredNorm()<0.1) ax=az^Point3f(0,1,0);
  ax=ax.Normalize();
  ay=(az^ax).Normalize();

  glMatrixMode(GL_PROJECTION);
  glPushMatrix();
  glLoadIdentity();
/*  if (!sx) {
    glScalef(1,1,-1);
  }*/

  
	GLfloat nearPlane = 1.0;
	GLfloat farPlane = 201;
  glOrtho(-1,+1,-1,+1, nearPlane, farPlane);

  glMatrixMode(GL_MODELVIEW);
  
  // PREPARE MATRIX for shadow test...
  
  glPushMatrix();
  glLoadIdentity();
  glOrtho(-1,+1,-1,+1, nearPlane, farPlane);
  
  gluLookAt(0,0,-4,   0,0,0,   0,1,0);    
  gluLookAt( az[0],az[1],az[2],  0,0,0, ay[0], ay[1], ay[2] );

  float r=shadowmap.m.r;
  float px=shadowmap.m.px;
  float py=shadowmap.m.py;
  float pz=shadowmap.m.pz;
  glScalef(1/r,1/r,1/r);
  glTranslatef(-px,-py,-pz);
  
  glGetFloatv(GL_MODELVIEW_MATRIX, &(matSM[0][0]));
  
  // ...done!
  
  glLoadIdentity();
  gluLookAt(0,0,-4,   0,0,0,   0,1,0);    
  gluLookAt( az[0],az[1],az[2],  0,0,0, ay[0], ay[1], ay[2] );

  //shadowScaleFactor=extractCurrentScaleFactor()/r;
  
  glGetIntegerv(GL_VIEWPORT, lastviewport);
  
  if (sx) {
    glViewport(0,0,screensize,screensize);
    glEnable(GL_SCISSOR_TEST);
    glScissor(0,0,screensize,screensize);
  }
  else {
    glViewport(screensize,0,screensize,screensize);
    glEnable(GL_SCISSOR_TEST);
    glScissor(screensize,0,screensize,screensize);
  }

  HSratio = float(screensize) / float(screensizeHard) ;
  //for (int i=0; i<4; i++)
  //for (int j=0; j<2; j++) matSM[i][j] /=ratio;
  
}