2021年3月22日 星期一

Week_05 2021.03.22

 

1. 旋轉

    1. 滑鼠右鍵,Swap translate / rotate

    2. 公轉,自轉

        自轉:
            glTranslatef ( 0.00 , 0.00 , 0.00 ) ; 移動( x , y , z )
            glRotatef (0.0 , 0.00 , 1.00 , 0.00 ) ; 旋轉( 角度 , x , y , z )
            glScalef (1.00 , 1.00 , 1.00 ) ; 縮放( x , y , z )
            glBegin( .... );
            .......

        公轉:
            glRotatef (0.0 , 0.00 , 1.00 , 0.00 ) ; 旋轉( 角度 , x , y , z )
            glTranslatef ( 0.00 , 0.00 , 0.00 ) ; 移動( x , y , z )
            glScalef (1.00 , 1.00 , 1.00 ) ; 縮放( x , y , z )
            glBegin( .... );
            .......
        

        !!!!! 繞著世界轉最重要

     3. 從下往上看程式碼才對

          自轉:
            glTranslatef ( 0.45 , 0.00 , 0.00 ) ;  有一個胖胖的旋轉25度移動到右邊的車子
            glRotatef ( 51.0 , 0.00 , 1.00 , 0.00 ) ;  有一個胖胖的旋轉51度的車子
            glScalef (1.79 , 1.00 , 1.00 ) ;  有一個變胖的車子
            glBegin( .... );  有一個車子
            .......

            

        公轉:
            glRotatef ( 68.0 , 0.00 , 1.00 , 0.00 ) ;  有一個變胖移動到右邊旋轉1度的車子
            glTranslatef ( 0.41 , 0.00 , 0.00 ) ;  有一個變胖移動到右邊的車子
            glScalef (1.20 , 1.00 , 1.00 ) ;  有一個變胖的車子
            glBegin( .... );  有一個車子
            .......

                


2. 自製

    1. 下載github
    2. 開GLUT檔
    3. 新增程式碼


            #include <GL/glut.h>
            #include <stdio.h>
            float vx[2000],vy[2000];   ///準備很多頂點
            int N=0;   ///有N個頂點
            void display()
            {
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
                glColor3f(1,1,0);   ///加顏色

                glBegin(GL_LINE_LOOP);   ///也可以是GL_TRIANGLE_FAN 就可以有其他形狀
                for(int i=0;i<N;i++)
                {
                    glVertex2f(vx[i],vy[i]);
                }
                glEnd();
                glutSwapBuffers();
            }
            void mouse(int buttin,int state,int x,int y)
            {
            }
            void motion(int x,int y)
            {
                printf("%d %d\n",x,y);   ///把頂點記下來
                vx[N] = (x-150)/150.0;
                vy[N] = -(y-150)/150.0;
                N++;
                display();
            }
            int main(int argc,char**argv)
            {
                glutInit(&argc, argv);
                glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
                glutCreateWindow("Week05 drawing");
                glutDisplayFunc(display);
                glutMouseFunc(mouse);
                glutMotionFunc(motion);
                glutMainLoop();
            }

3. 期中考網頁120.125.80.50/GL

4. github

    1. 搜尋網址gist.github.com
    2. 輸入程式碼,複製網頁
    3. 部落格HTML模式,貼上網頁
    4. 成功!



Github
----------------------------------------------




















沒有留言:

張貼留言

Week18期末作業(橘貓的跳舞熊熊)

 期末作業(橘貓的跳舞熊熊) 影片: https://youtu.be/R89tptMaQZw 程式碼: #include <opencv/highgui.h> #include <opencv/cv.h> #include <GL/glut.h...