2019年4月25日 星期四

Week10 鍾嘉穎 2019-04-25

1. 期中考:OpenGL必背10函數
2. 複習: 移動, 旋轉, 縮放
      1. 點進去小葉的網頁: http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
      2. 下載 Example裏的 win32, glut32.dll, data, source
      3. 解壓縮到下載 (但先不要把souces .zip解壓縮)
      4. 把已解壓的 data 資料夾拉到windows裏
      5. 把已解壓的 glut32.dll 資料夾拉到windows裏
      6. 打開 Transformation.exe

      
            
      圖一: 車子自轉(右)


      
      圖二: 車子公轉 (右)


3. T-R-T 旋轉 (改變旋轉軸)
     1. 先載入freeglut (跟第一週一樣)
           1. Google search "freeglut windows"
           2. 從Transmission Zero 下載 "freeglut 3.0.0 MinGW Package"
           3. 解壓縮後放到桌面
           4. 在lib複製一個"libfreeglut.a"命名為"libglut32.a"
           5. CodeBlocks 開
           6. File  ->  New -> Project -> GLUT Project
           7. 把location改成"C:\Users\user\Desktop\freeglut"


     2. 先把茶壺的程式碼打到main
               #include <GL/glut.h>
                void display(){
                    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
                    glutSolidTeapot( 0.3 );
                    glutSwapBuffers();
                }
                int main(int argc, char**argv){
                    glutInit(&argc,argv);
                    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
                    glutCreateWindow("06160912");
                    glutDisplayFunc(display);
                    glutMainLoop();
                }

     3. 改一下程式碼
                #include <GL/glut.h>
                float angle=0;
                void display(){
                    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
                    glPushMatrix();
                        glTranslatef(0,0.5,0); ///這是往上移動的茶壺
                        glutSolidTeapot( 0.3 ); ///This is a Teapot
                    glPopMatrix();

                    glPushMatrix();
                        //glutSolidSphere( 0.3,30,30 );
                    glPopMatrix();

                    glPushMatrix();
                        glTranslatef(0.5,0.625,0); ///(3)把它掛在你要放的地方
                        glRotatef(angle,0,0,1); ///(1)先有個轉動, 但怪怪的
                        glTranslatef(0.6,0,0); ///(2)要更早去移動旋轉中心
                        glRotatef(-90,0,1,0); ///(0)轉動90度的Cone
                        glutSolidCone(0.2,0.6,30,30); ///直直的Cone
                    glPopMatrix();

                    glutSwapBuffers();
                }

                void motion(int x, int y)
                {
                    angle=x;
                    display();
                }

                int main(int argc, char**argv){
                    glutInit(&argc,argv);
                    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
                    glutCreateWindow("06160912");
                    glutDisplayFunc(display);
                    glutMotionFunc(motion);
                    glutMainLoop();
                }
            




沒有留言:

張貼留言