際際滷

際際滷Share a Scribd company logo
3. More Drawing Tool

1.The Mapping from the Window to the Viewport
 一 觀壱 襷ろ

             world coordinates(瑚譬)
              る瑚 れ襦 讌 螻糾




             world window(瑚)
               覃伎 蠏碁れ 




                viewport(觀壱)
            企Μ ろ襴一
3. More Drawing Tool

1.The Mapping from the Window to the Viewport
3. More Drawing Tool

1.The Mapping from the Window to the Viewport
*viewport: 吴碁 豌伎
        scaling螻 shifting 牛 襷ろ




                                           (0,0)
1.The Mapping from the Window to the Viewport

 Distortion(螻) 狩る
 1)壱蠍一^
 2)磯企 觀壱語 譬°譟一


        300
                                   glViewport(0,0,150,150)
                    world window


                  300



                                   glViewport(0,0,300,150)

     glInitWindowSize(300,300)
3. More Drawing Tool

1.The Mapping from the Window to the Viewport




                                                                 screen window

                                                                 viewport




 world window left,top,right,bottom (W.l,W.t,W.r,W.b)蟆所襦 蠍一.

 viewport V. l,V.t,V.r,V.b 曙襦 豸′ ろ襴 一 譬螻襦 蠍一.
3. More Drawing Tool

1.The Mapping from the Window to the Viewport
 覲 牛 襷ろ




                   sx =Ax+C, sy =By+D

                   A , B scale 螳
                   C , D shift(or translate)螳
sx =Ax+c, sy =By+d
A and B scale the x,y coordinates,
C and D shift(or translate)

A= V.r-V.l C= V.l-AW.l      B= V.t-V.b D= V.b-BW.b
  W.r-W.l                    W.t-W.b
sx =Ax+c, sy =By+d
(W. l,W.t,W.r,W.b)=(0, 2.0, 0, 1.0)
(V. l,V.t,V.r,V.b)=(40,400,60,300)

sx=180x+40                       glMatrixMode(GL_PROJECTION);
sy=240y+60                       glLoadIdentity();
                                  gluOrtho2D(0, 2.0, 0, 1.0);//一れ
                                  glViewport(40,400,60,300);//viewportれ
Tiling the screen window with the dinosaur motif




     a)setWindow(0, 640.0, 0, 440.0);             // set a fixed window
      for(int i=0; i < 5; i++)              // for each column
        for (int j=0; j < 5; j++)           // for each row
        {
        glViewport(i * 64, j * 44, 64,44)      // set the next viewport
        drawPolylineFile(dino.dat") ;           // draw it again
        }
Tiling the screen window with the dinosaur motif




     b)for(int i = 0; i<5;i++)
         for (int j = 0;=0; j<5;j++)
         {
             if((i+j) % 2 == O                   //if (i+j) is even
                setWindow (0.0 , 640.0, 0.0, 440.0) // right - side-up window
             else
                setWindow(0.0, 640.0, 440.0, 0.0); // upside-down window
             glViewport(i * 64, j * 44, 64, 44);  // set the next viewport
             drawPolylineFile("dino.dat");          //draw it again
        }
3. More Drawing Tool

1.The Mapping from the Window to the Viewport
-Zooming and Roaming

                       float cx = 0.3, cy = 0.2;              //center of the window
                       float H, W = 1.2, aspect = 0.7;          // window properties
                       set the viewport
                       for(int frame = 0; frame < NumFrames; frame++) // for each frame
                       {
                       clearthescreen                   // erase the previous figure
                       W*-0.7;                      // reduce the window width
                       H = W * aspect;                // maintain the same aspect ratio
                       setWindow(cx - W, cx + W,. cy._- H, cy + H) ; //set the next window
                       hexSwirl();                   // draw the object



    zooming螻朱ゼ 襷り鍵  襷 襷 一 蠍磯ゼ 譴
    覃伎 .

    center aspect ratio(R) 螻 豈 螳 蠍一 觀壱  蠏碁れ.
3. More Drawing Tool

1.The Mapping from the Window to the Viewport
-Zooming and Roaming
 覿 覃伎 襷り鍵


  Double buffering
  襦 磯ゼ るジ 企螳 覩碁Μ 蠏碁る  覯渚蟆
  蠏碁れ 蠏碁殊 ろ伎 讀 覦蠖豺蠍 .

  glutSwapBuffer
  覃覈襴  蠏碁殊 螳 覲  襦 ろ襴 磯 企慨

  豐蠍壱
  觚覯朱 伎 豐蠍壱覈 れ 豢螳

  glutlintDisplayMode(GLUT_DOUBLE l GLUT_RGB)
  -hexSwirl()れ glutSwapBuffers()襯 豢螳
3. More Drawing Tool

2.Setting the Window and Viewport Automatically
-setting of the window
 る語 覯( 覦企覦)蟲蠍



                               All the endpoints of the object's lines
                               are stored in an array

                               pt[i]
                               i=0, 2.....,n-1
                               extreme value of x, y

                               給襯 至鍵  覯 pass

                               pass 1: 蠏碁Μ蠍 襭伎 ろ讌襷
                                     れ 蠏碁Μ讌 螻 覯襷 螻.
                               pass 2: 詞伎 覯襯 螳讌螻 れ 蠏碁.
3. More Drawing Tool

2.Setting the Window and Viewport Automatically
-automatic setting of the viewport to preserve the aspect ratio




   豌願係襴殊 覃伎 j  

   a) world window  譬°螳 screen window 譬°覲企  蟆曙 R>W/H
   b) world window  譬°螳 screen window 譬°覲企  蟆曙 R<W/H
3. More Drawing Tool

2.Setting the Window and Viewport Automatically
-automatic setting of the viewport to preserve the aspect ratio




       a)setViewport(0,W,0,W/R)              b)setViewport(0,H*R,0,H)
3. More Drawing Tool

2.Setting the Window and Viewport Automatically
-automatic setting of the viewport to preserve the aspect ratio



     ex)R=1.6, H=200, W=360

     W/H=1.8
     case b) 企
     setViewport()?
     setViewport(0,320,0,200)




       a)setViewport(0,W,0,W/R)              b)setViewport(0,H*R,0,H)
3. More Drawing Tool

2.Setting the Window and Viewport Automatically
-Resizing the Screen Window: the Resize Event
  蠍郁 覲蟆暑 語 貊覦燕

                                   glReshapeFunc(myReshape);
                                   //specifies the funtion called
                                   //on a resize event


                                   void myshape(GLsize W, GLsize H);
                                   {
                                     if (R>W/H) //use window aspect ratio
                                           setViewport(0, W, 0,W/R)
                            drag     else
                                     setViewport(0, H*R, 0, H)
                                   }


     drag: resize event覦

More Related Content

Open gl

  • 1. 3. More Drawing Tool 1.The Mapping from the Window to the Viewport 一 觀壱 襷ろ world coordinates(瑚譬) る瑚 れ襦 讌 螻糾 world window(瑚) 覃伎 蠏碁れ viewport(觀壱) 企Μ ろ襴一
  • 2. 3. More Drawing Tool 1.The Mapping from the Window to the Viewport
  • 3. 3. More Drawing Tool 1.The Mapping from the Window to the Viewport *viewport: 吴碁 豌伎 scaling螻 shifting 牛 襷ろ (0,0)
  • 4. 1.The Mapping from the Window to the Viewport Distortion(螻) 狩る 1)壱蠍一^ 2)磯企 觀壱語 譬°譟一 300 glViewport(0,0,150,150) world window 300 glViewport(0,0,300,150) glInitWindowSize(300,300)
  • 5. 3. More Drawing Tool 1.The Mapping from the Window to the Viewport screen window viewport world window left,top,right,bottom (W.l,W.t,W.r,W.b)蟆所襦 蠍一. viewport V. l,V.t,V.r,V.b 曙襦 豸′ ろ襴 一 譬螻襦 蠍一.
  • 6. 3. More Drawing Tool 1.The Mapping from the Window to the Viewport 覲 牛 襷ろ sx =Ax+C, sy =By+D A , B scale 螳 C , D shift(or translate)螳
  • 7. sx =Ax+c, sy =By+d A and B scale the x,y coordinates, C and D shift(or translate) A= V.r-V.l C= V.l-AW.l B= V.t-V.b D= V.b-BW.b W.r-W.l W.t-W.b
  • 8. sx =Ax+c, sy =By+d (W. l,W.t,W.r,W.b)=(0, 2.0, 0, 1.0) (V. l,V.t,V.r,V.b)=(40,400,60,300) sx=180x+40 glMatrixMode(GL_PROJECTION); sy=240y+60 glLoadIdentity(); gluOrtho2D(0, 2.0, 0, 1.0);//一れ glViewport(40,400,60,300);//viewportれ
  • 9. Tiling the screen window with the dinosaur motif a)setWindow(0, 640.0, 0, 440.0); // set a fixed window for(int i=0; i < 5; i++) // for each column for (int j=0; j < 5; j++) // for each row { glViewport(i * 64, j * 44, 64,44) // set the next viewport drawPolylineFile(dino.dat") ; // draw it again }
  • 10. Tiling the screen window with the dinosaur motif b)for(int i = 0; i<5;i++) for (int j = 0;=0; j<5;j++) { if((i+j) % 2 == O //if (i+j) is even setWindow (0.0 , 640.0, 0.0, 440.0) // right - side-up window else setWindow(0.0, 640.0, 440.0, 0.0); // upside-down window glViewport(i * 64, j * 44, 64, 44); // set the next viewport drawPolylineFile("dino.dat"); //draw it again }
  • 11. 3. More Drawing Tool 1.The Mapping from the Window to the Viewport -Zooming and Roaming float cx = 0.3, cy = 0.2; //center of the window float H, W = 1.2, aspect = 0.7; // window properties set the viewport for(int frame = 0; frame < NumFrames; frame++) // for each frame { clearthescreen // erase the previous figure W*-0.7; // reduce the window width H = W * aspect; // maintain the same aspect ratio setWindow(cx - W, cx + W,. cy._- H, cy + H) ; //set the next window hexSwirl(); // draw the object zooming螻朱ゼ 襷り鍵 襷 襷 一 蠍磯ゼ 譴 覃伎 . center aspect ratio(R) 螻 豈 螳 蠍一 觀壱 蠏碁れ.
  • 12. 3. More Drawing Tool 1.The Mapping from the Window to the Viewport -Zooming and Roaming 覿 覃伎 襷り鍵 Double buffering 襦 磯ゼ るジ 企螳 覩碁Μ 蠏碁る 覯渚蟆 蠏碁れ 蠏碁殊 ろ伎 讀 覦蠖豺蠍 . glutSwapBuffer 覃覈襴 蠏碁殊 螳 覲 襦 ろ襴 磯 企慨 豐蠍壱 觚覯朱 伎 豐蠍壱覈 れ 豢螳 glutlintDisplayMode(GLUT_DOUBLE l GLUT_RGB) -hexSwirl()れ glutSwapBuffers()襯 豢螳
  • 13. 3. More Drawing Tool 2.Setting the Window and Viewport Automatically -setting of the window る語 覯( 覦企覦)蟲蠍 All the endpoints of the object's lines are stored in an array pt[i] i=0, 2.....,n-1 extreme value of x, y 給襯 至鍵 覯 pass pass 1: 蠏碁Μ蠍 襭伎 ろ讌襷 れ 蠏碁Μ讌 螻 覯襷 螻. pass 2: 詞伎 覯襯 螳讌螻 れ 蠏碁.
  • 14. 3. More Drawing Tool 2.Setting the Window and Viewport Automatically -automatic setting of the viewport to preserve the aspect ratio 豌願係襴殊 覃伎 j a) world window 譬°螳 screen window 譬°覲企 蟆曙 R>W/H b) world window 譬°螳 screen window 譬°覲企 蟆曙 R<W/H
  • 15. 3. More Drawing Tool 2.Setting the Window and Viewport Automatically -automatic setting of the viewport to preserve the aspect ratio a)setViewport(0,W,0,W/R) b)setViewport(0,H*R,0,H)
  • 16. 3. More Drawing Tool 2.Setting the Window and Viewport Automatically -automatic setting of the viewport to preserve the aspect ratio ex)R=1.6, H=200, W=360 W/H=1.8 case b) 企 setViewport()? setViewport(0,320,0,200) a)setViewport(0,W,0,W/R) b)setViewport(0,H*R,0,H)
  • 17. 3. More Drawing Tool 2.Setting the Window and Viewport Automatically -Resizing the Screen Window: the Resize Event 蠍郁 覲蟆暑 語 貊覦燕 glReshapeFunc(myReshape); //specifies the funtion called //on a resize event void myshape(GLsize W, GLsize H); { if (R>W/H) //use window aspect ratio setViewport(0, W, 0,W/R) drag else setViewport(0, H*R, 0, H) } drag: resize event覦