void init() { glDisable(GL_LIGHTING); glShadeModel(GL_FLAT); // Use a simple non-distorting (letterbox) perspective camera with // 90 degree fovy on a 4:3 shaped window, so the frustum is based on // the horizontal, which makes things just a little more complex. // Since we can't move the camera around without using TW, we'll // place the camera above and to the right of the barn, so you can // see the front, right side, and the roof. GLfloat BBheight = barnHeight+barnWidth/2.0; GLfloat BBdepth = barnLength; GLfloat BBwidth = barnWidth; GLfloat BBradius = 0.5*sqrt(BBheight*BBheight+BBdepth*BBdepth+BBwidth*BBwidth); GLfloat EyeRadius = BBradius*sqrt(2); // Compute Center of BB GLfloat CenterX = BBwidth/2; GLfloat CenterY = BBheight/2; GLfloat CenterZ = -BBdepth/2; // Place Eye equally far from Center along each axis GLfloat EyeOrthoDist = EyeRadius/sqrt(3); GLfloat EyeX = CenterX+EyeOrthoDist; GLfloat EyeY = CenterY+EyeOrthoDist; GLfloat EyeZ = CenterZ+EyeOrthoDist; EyeX = CenterX; EyeY = CenterY; EyeZ = CenterZ+EyeRadius; GLfloat AtX = CenterX; GLfloat AtY = CenterY; GLfloat AtZ = CenterZ; GLfloat fovy = 90; GLfloat aspectRatio = 4.0/3.0; GLfloat near = EyeRadius - BBradius; GLfloat far = EyeRadius + BBradius; // Some debugging print statements: printf("BBradius = %f, EyeRadius =%f\n",BBradius,EyeRadius); printf("Center = (%f,%f,%f)\n",CenterX,CenterY,CenterZ); printf("aspect ratio = %f\nEyeRadius = %f, near=%f far=%f\nVRP=(%f,%f,%f)\nAt=(%f,%f,%f)\n", aspectRatio,EyeRadius,near,far,EyeX,EyeY,EyeZ,AtX,AtY,AtZ); printf("EyeOrthoDist = %f\n",EyeOrthoDist); near = 0.1; far = 1000; EyeY = -5; EyeZ = 30; // Some debugging print statements: printf("BBradius = %f, EyeRadius =%f\n",BBradius,EyeRadius); printf("Center = (%f,%f,%f)\n",CenterX,CenterY,CenterZ); printf("aspect ratio = %f\nEyeRadius = %f, near=%f far=%f\nVRP=(%f,%f,%f)\nAt=(%f,%f,%f)\n", aspectRatio,EyeRadius,near,far,EyeX,EyeY,EyeZ,AtX,AtY,AtZ); printf("EyeOrthoDist = %f\n",EyeOrthoDist); // Okay, finally ready for the OpenGL calls glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(fovy,aspectRatio,near,far); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(EyeX,EyeY,EyeZ,AtX,AtY,AtZ,0,1,0); }