MIT计算机图形学资料


MIT最新的计算机图形学课程资源。包含课件和代码的下载
资源截图
代码片段和文件信息

/* The documentation for camera is in the header file camera.h. */

#include 
#include 
#include 
#include 

// NOTE: the “static“ modifier means that the variable or function is private to this file.

   static double eyex = 0 eyey = 0 eyez = 30;
   static double refx = 0 refy = 0 refz = 0;
   static double upx = 0 upy = 1 upz = 0;
   
   static double xminRequested = -5 xmaxRequested = 5;
   static double yminRequested = -5 ymaxRequested = 5;
   static double zmin = -10 zmax = 10;
   static int orthographic = 0;
   static int preserveAspect = 1;
   
   static double xminActual xmaxActual yminActual ymaxActual;
   
   void cameraSetOrthographic(int ortho) {
      orthographic = ortho;
   }

   void cameraSetPreserveAspect(int preserve) {
      preserveAspect = preserve;
   }

   void cameraSetLimits(double xmin double xmax double ymin double ymax double zmin1 double zmax1) {
      xminRequested = xminActual = xmin;
      xmaxRequested = xmaxActual = xmax;
      yminRequested = yminActual = ymin;
      ymaxRequested = ymaxActual = ymax;
      zmin = zmin1;
      zmax = zmax1;
   }
   
   void cameraSetScale(double limit) {
      cameraSetLimits(-limitlimit-limitlimit-2*limit2*limit);
   }
   
   void cameraLookAt(double eyeX double eyeY double eyeZ
                        double viewCenterX double viewCenterY double viewCenterZ
                        double viewUpX double viewUpY double viewUpZ) {
      eyex = eyeX;
      eyey = eyeY;
      eyez = eyeZ;
      refx = viewCenterX;
      refy = viewCenterY;
      refz = viewCenterZ;
      upx = viewUpX;
      upy = viewUpY;
      upz = viewUpZ;
   }

    static double norm(double v0 double v1 double v2) {
        double norm2 = v0*v0 + v1*v1 + v2*v2;
        return sqrt(norm2);
    }

    static void normalize(double v[]) {
        double n = norm(v[0]v[1]v[2]);
        v[0] /= n;
        v[1] /= n;
        v[2] /= n;
    }

   void cameraApply() {
        int viewport[4];
        glGetIntegerv(GL_VIEWPORT viewport);
        xminActual = xminRequested;
        xmaxActual = xmaxRequested;
        yminActual = yminRequested;
        ymaxActual = ymaxRequested;
        if (preserveAspect) {
           double viewWidth = viewport[2];
           double viewHeight = viewport[3];
           double windowWidth = xmaxActual - xminActual;
           double windowHeight = ymaxActual - yminActual;
           double aspect = viewHeight / viewWidth;
           double desired = windowHeight / windowWidth;
           if (desired > aspect) { //expand width
               double extra = (desired / aspect - 1.0) * (xmaxActual - xminActual) / 2.0;
               xminActual -= extra;
               xmaxActual += extra;
           } else if (aspect > desired) {
               double extra = (aspect / desired - 1.0) * (ymaxActual - yminActual) / 2.0;
               yminActual -= extra; 
               ymaxActual += extra;
           }
        

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-01-04 20:36  graphicsbook-1.2-web-site
     目录           0  2018-01-04 20:36  graphicsbook-1.2-web-sitec6
     文件        1775  2018-01-04 20:36  graphicsbook-1.2-web-sitec6affine-transform-matrix-2d.png
     文件        4719  2018-01-04 20:36  graphicsbook-1.2-web-sitec6
gb-triangle-webgl.png
     文件       17365  2018-01-04 20:36  graphicsbook-1.2-web-sitec6s5.html
     文件       12524  2018-01-04 20:36  graphicsbook-1.2-web-sitec6
ested-squares.png
     文件      270691  2018-01-04 20:36  graphicsbook-1.2-web-sitec6cubemap-fisheye.png
     文件       42521  2018-01-04 20:36  graphicsbook-1.2-web-sitec6s3.html
     文件       50693  2018-01-04 20:36  graphicsbook-1.2-web-sitec6s4.html
     文件      386385  2018-01-04 20:36  graphicsbook-1.2-web-sitec6multi-texture.png
     文件        5815  2018-01-04 20:36  graphicsbook-1.2-web-sitec6index.html
     文件       11286  2018-01-04 20:36  graphicsbook-1.2-web-sitec6 extures-from-pixels.png
     文件       19978  2018-01-04 20:36  graphicsbook-1.2-web-sitec6webgl-dataflow.png
     文件       66294  2018-01-04 20:36  graphicsbook-1.2-web-sitec6 exture-units-and-objects.png
     文件       45740  2018-01-04 20:36  graphicsbook-1.2-web-sitec6s2.html
     文件       52662  2018-01-04 20:36  graphicsbook-1.2-web-sitec6s1.html
     目录           0  2018-01-04 20:36  graphicsbook-1.2-web-sitec2
     文件       51645  2018-01-04 20:36  graphicsbook-1.2-web-sitec2s6.html
     文件       56822  2018-01-04 20:36  graphicsbook-1.2-web-sitec2scene-graph.png
     文件       14222  2018-01-04 20:36  graphicsbook-1.2-web-sitec2convexity.png
     文件       24529  2018-01-04 20:36  graphicsbook-1.2-web-sitec2pixel-coordinates.png
     文件       45342  2018-01-04 20:36  graphicsbook-1.2-web-sitec2filled-shapes.png
     文件        8016  2018-01-04 20:36  graphicsbook-1.2-web-sitec2antialiased-line.png
     文件       44485  2018-01-04 20:36  graphicsbook-1.2-web-sitec2s7.html
     文件        9777  2018-01-04 20:36  graphicsbook-1.2-web-sitec2old-to-new-coords.png
     文件        4733  2018-01-04 20:36  graphicsbook-1.2-web-sitec2line-attributes.png
     文件       47131  2018-01-04 20:36  graphicsbook-1.2-web-sitec2RotatedStringAndImage.jpg
     文件        9438  2018-01-04 20:36  graphicsbook-1.2-web-sitec2ovals.png
     文件       51793  2018-01-04 20:36  graphicsbook-1.2-web-sitec2s5.html
     文件        5220  2018-01-04 20:36  graphicsbook-1.2-web-sitec2cart.png
     文件        1617  2018-01-04 20:36  graphicsbook-1.2-web-sitec2hierarchical-animation.svg
............此处省略560个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)