ch02 bouncing box

 

maybe this is the finest and clearness version of the

bouncing box, i ever made -- althogh partial copy the super bible

 

should be pay attention the following code

the view port didn't corresponding the windows real pixel

they connected by the aspect ratio = window's pixels width/ window's pixels height

void ChangeSize(GLsizei w, GLsizei h)
{
    //windowWidth = w;
    //windowHeight = h;

    GLfloat aspectRatio;
    // Prevent a divide by zero
    if(h == 0)
        h = 1;
    // Set Viewport to window dimensions
    glViewport(0, 0, w, h);
    // Reset coordinate system
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    // Establish clipping volume (left, right, bottom, top, near, far)
    aspectRatio = (GLfloat)w / (GLfloat)h;
    if (w <= h)
    {
        windowWidth = 100.;
        windowHeight = 100 / aspectRatio;
        glOrtho (-100.0, 100.0, -100 / aspectRatio, 100.0 / aspectRatio,
        1.0, -1.0);
    }
    else
    {
        windowWidth = 100 * aspectRatio;
        windowHeight = 100;
        glOrtho (-100.0 * aspectRatio, 100.0 * aspectRatio,
        -100.0, 100.0, 1.0, -1.0);
    }
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}

 

 

转载于:https://www.cnblogs.com/geometry-/archive/2012/06/29/2570481.html

相关文章:

  • 2022-02-24
  • 2022-01-19
  • 2021-12-03
  • 2021-09-11
  • 2022-12-23
  • 2022-12-23
  • 2021-04-12
  • 2021-12-31
猜你喜欢
  • 2021-11-17
  • 2021-04-06
  • 2021-05-19
  • 2021-11-17
  • 2021-11-15
  • 2022-01-04
  • 2022-01-19
相关资源
相似解决方案