顯示具有 week03 標籤的文章。 顯示所有文章
顯示具有 week03 標籤的文章。 顯示所有文章

2022年3月15日 星期二

獻祭肝臟的電腦圖學課堂筆記_week04

 

1.主題 Rotate旋轉

jsyeh.org/3dcg 下載

data.zip

windows.zip

2.測試Rotate功能

決定旋轉方向 

利用國中學習的右手定則 來判定它旋轉的方向







    3.點擊轉茶壺

        打開 Codeblocks 建立新的 GLUT 專案
      
        -Build&Run 會出現一個按一次旋轉90度的白色茶壺
        
       #include <GL/glut.h>
        void display()
        {
            glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            glPushMatrix();
                glRotatef(90,0,0,1); ///以z軸為主做90度的旋轉
                glutSolidTeapot(0.3);
            glPushMatrix();
            glutSwapBuffers();
        }
        int main(int argc, char** argv)
        {
            glutInit( &argc, argv );
            glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
            glutCreateWindow("第04週的程式哦!");
            glutDisplayFunc(display);
            glutMainLoop();
        }



4.滑鼠互動

#include <GL/glut.h>

void display()
{
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///清畫面
    glPushMatrix();///備分矩陣
        glRotatef(90,0,0,1);///旋轉
        glColor3f(1,0,0);///顏色(RGB)
        glutSolidTeapot(0.3);///就一個神燈
    glPopMatrix();///還原矩陣

    glutSwapBuffers();///畫好提交
}

int main(int argc, char** argv)///主函式 進階版 看不懂
{
    glutInit( &argc, argv);///把參數給glutInit 初始化
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );///雙緩衝區+3D深度功能
    glutCreateWindow("第4周的程式");///開GLUT視窗

    glutDisplayFunc(display);///用來顯示的函式

    glutMainLoop();
}

5.改進


原因:因為上面的只會跟者妳X軸的座標去移動 等於說一開始點的座標也會算進去
所以要固定起始點與上次的一樣

#include <GL/glut.h>
float angle=0,oldX=0;
void display()
{
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///清畫面
    glPushMatrix();///備分矩陣
        glRotatef(angle,0,0,1);///旋轉
        glColor3f(1,0,0);///顏色(RGB)
        glutSolidTeapot(0.3);///就一個神燈
    glPopMatrix();///還原矩陣

    glutSwapBuffers();///畫好提交
}
void motion (int x, int y)
{
        angle+=(x-oldX);
        oldX=x;
        display();///重劃畫面

}
void mouse(int button, int state, int x, int y)
{
    oldX=x;///定錨
}


int main(int argc, char** argv)///主函式 進階版 看不懂
{
    glutInit( &argc, argv);///把參數給glutInit 初始化old
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );///雙緩衝區+3D深度功能
    glutCreateWindow("滑鼠可以跟者動");///開GLUT視窗
    glutMotionFunc(motion);///讓她動
    glutMouseFunc(mouse);///上周的
    glutDisplayFunc(display);///用來顯示的函式

    glutMainLoop();
}



(設定你的網路品牌) 超熱血的圖學筆記 Week04

 1. 主題: Rotate旋轉

jsyeh.org/3dcg10 下載

data.zip   =>下載\windows\data\一堆3D模型

windows.zip=>下載\windows\Transformation.exe

2. 測試 角度

   glRotatef(角度, x, y, z);

3. 最難的, 是不同的旋轉軸。


step01-1_介紹今天的主題「旋轉Rotate」先帶大家看課本的範例,解壓縮windows.zip並把 data.zip 正確放好,便能執行Transformation.exe 並試著改裡面的glRotatef(角度,....)


step01-2_接下來要介紹各種不同的旋轉軸,像是如果旋轉軸是0,1,0向上的Y軸,那它怎麼轉呢。如果旋轉軸是1,0,0向右的X軸,它的轉法,是頭往前倒。如果旋轉軸是1,1,0向右上斜,那轉動時,右肩往前倒。最難理解的是0,0,1向著前面的Z軸,如果你有右手比讚,便容易想像它怎麼轉動。




step02-1_我們再利用課本範例Transformation.exe測了最難理解的0,0,1的Z軸,如果改成0,0,-1的反方向,大家也要能知道它往哪裡轉。接下來我們承接上週的程式碼,改成用glRotatef(角度,x,y,z)來看茶壼轉動的狀況


///全刪,再從blog抄你的精簡10行程式
#include <GL/glut.h>
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();///備份矩陣
        glRotatef(90, 0,0,1);
        glutSolidTeapot(0.3);
    glPopMatrix();///還原矩陣
    glutSwapBuffers();
}
int main(int argc, char**argv)
{
    glutInit( &argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week04 Rotate");

    glutDisplayFunc(display);
    glutMainLoop();
}


step_02-1b_如何偽造時間。在Blog裡,其實可以設定你的時間。在GitHub裡,也可以設定你的時間。老師分享之前交作業時曾經修改email的時間, 去年在修英文課時,發現如果有缺交作業時,就會想放棄。如果能補交、保持完美,就會有動力繼續保持下去。大家可以試試,有問題可以問我。



step02-2_剛剛的程式裡, glRotatef(90,0,0,1) 的角度是寫死固定。想要有互動的變化時, 可以使用 mouse motion 功能,要在 main() 裡註冊 glutMotionFunc(motion), 再寫你的 void motion(int x, int y) 裡面去修改 angle值,再用 display()重畫畫面, 其中glRotatef(angle, 0,0,1)


```C++
#include <GL/glut.h>
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();///備份矩陣
        glRotatef(angle, 0,0,1);
        glutSolidTeapot(0.3);
    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("Week04 Rotate");

    glutDisplayFunc(display);
    glutMotionFunc(motion);///mouse motion動
    glutMainLoop();
}
```

備份、改GitHub時間
```
git clone https://github.com/jsyeh/2022graphics1

git status (看到有紅色)
git add .
git status (確認變綠色)

git config --global user.name jsyeh
git config --global user.email jsyeh@mail.mcu.edu.tw


git commit -m "add week04"   --date "2022-03-09 12:00:00"

git push
```


step03-1_剛剛的 angle=x 的作法,會讓轉動很奇怪、不太連續, 原因是 angle設成x座標。老師使用一個很舊的笑話「大象放到冰箱裡」接下來,便利用這樣的觀念,把滑鼠按下去定錨oldX=x,之後移動時,angle+=(x-oldX), 最後再 oldX=x 再定一次錨


```C++
#include <GL/glut.h>
float angle=0, oldX=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();///備份矩陣
        glRotatef(angle, 0,0,1);
        glutSolidTeapot(0.3);
    glPopMatrix();///還原矩陣
    glutSwapBuffers();
}
void motion(int x, int y)
{
    angle += (x-oldX);
    oldX = x;
    display();///重畫畫面
}
void mouse(int button, int state, int x, int y)
{
    oldX = x; ///定錨
}
int main(int argc, char**argv)
{
    glutInit( &argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week04 Rotate");

    glutDisplayFunc(display);
    glutMotionFunc(motion);///mouse motion動
    glutMouseFunc(mouse);///上週教: mouse按下去、放開來
    glutMainLoop();
}
```

step03-2_複習上週教的「用滑鼠寫程式」,,老師利用mouse()來印出程式碼,並把座標備份在mx[]及my[]裡面,配合N知道已經記錄了幾個座標。再於display()裡面,利用for迴圈,把這些座標利用GL_LINE_LOOP畫出來看。希望大家對於座標、座標換算、頂點、glBegin()等更有概念.zip

```C++
///上週的複習
#include <GL/glut.h>
#include <stdio.h>
int mx[1000],my[1000];///用來備份你的mouse的座標
int N=0;///有幾個點按好了?
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glBegin(GL_LINE_LOOP);
    for(int i=0; i<N; i++){
        glVertex2f( (mx[i]-150)/150.0, -(my[i]-150)/150.0 );
    }
    glEnd();
    glutSwapBuffers();
}
void mouse(int button, int state, int x, int y)
{//  printf("%d %d %d %d\n", button, state, x, y);
    if(state==GLUT_DOWN){///如果state是按下去0,才印程式碼
        printf("    glVertex2f( (%d-150)/150.0, -(%d-150)/150.0 );\n", x, y);
        N++;
        mx[N-1]=x; my[N-1]=y;
    }
    display();///重畫
}
int main(int argc, char**argv)
{
    glutInit( &argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week04 Rotate");

    glutDisplayFunc(display);
    glutMouseFunc(mouse);///上週教: mouse按下去、放開來
    glutMainLoop();
}
```



豪哥圖學筆記week04

 1.https://jsyeh.org/3dcg10/ 

下載win32,data

解壓縮windows.zip,data.zip

2.測試rotate方向,用安培右手定則可知道旋轉方向。





#include <GL/glut.h>

void display()

{

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glPushMatrix();

        glRotatef(90,0,0,1);

        glutSolidTeapot(0.3);

    glPopMatrix();

    glutSwapBuffers();

}

int main(int argc,char**argv)

{

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("Week04 Rotate");


    glutDisplayFunc(display);

    glutMainLoop();

}



讓茶壺移動




#include <GL/glut.h>

float angle=0;

void display()

{

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glPushMatrix();

        glRotatef(angle,0,0,1);

        glutSolidTeapot(0.3);

    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("Week04 Rotate");


    glutDisplayFunc(display);

    glutMotionFunc(motion);

    glutMainLoop();

}


第三個程式碼

#include <GL/glut.h>

float angle=0 , oldX=0;

void display()

{

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glPushMatrix();

        glRotatef(angle,0,0,1);

        glutSolidTeapot(0.3);

    glPopMatrix();

    glutSwapBuffers();

}

void motion(int x,int y)

{

    angle += (x-oldX);

    oldX=x;

    display();

}

void mouse (int button,int state,int x,int y)

{

    oldX=x;

}

int main(int argc,char**argv)

{

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("Week04 Rotate");


    glutDisplayFunc(display);

    glutMotionFunc(motion);

    glutMouseFunc(mouse);

    glutMainLoop();

}



電腦圖學課堂筆記week04

week04

1.連結http://jsyeh.org/3dcg10/
2.下載data.zip和win32.zip
3.windows.zip ->Transformation.exe
4.data.zip->模型.obj
5.執行Transformation.exe









2022年3月14日 星期一

OuO圖學筆記Week03

 移動,茶壺,滑鼠事件

移動

進入老師的網站https://jsyeh.org/3dcg10-->下載Win32、data-->解壓縮

data到windows


茶壺

執行week02_GLUT的程式-->建立實心茶壺程式-->加入移動程式-->還原矩陣





滑鼠事件

用上面程式更改-->查詢座標系統




2022年3月9日 星期三

week03

 1.範例 https://jsyeh.org/3dcg10/


1.1 下載 data, win32

windows.zip => 下載\windows\Transformation.exe

data.zip => 下載\windows\data\模型.obj

1.2.執行 Transformation.exe

(右上角) 右鍵:換模型

(下方)拖曳綠色的數值:


Step02:
1.寫入上禮拜茶壺程式
2.學習移動(translate)
寫入
        glPushMatrix(); ///備分舊位置
        ///移動會累積,會改變矩陣
            glTranslatef(0.5,0.5,0);    ///右上角
            glColor3f(1,1,0);
            glutSolidTeapot(0.3);
        glPopMatrix();///還原原位置
3.執行茶壺在右上角出現


Step03:
1.新增MyTeapot()函式
2.把剛剛的translate移到MyTeapot()
3.MyTeapot()設參數MyTeapot(float x,float y)
4.改glTranslatef(0.5,0.5,0); --->glTranslatef(x,y,0);讓它讀取參數值
程式如下:
void MyTeapot(float x,float y){
    glPushMatrix(); ///備分舊位置
        ///移動會累積,會改變矩陣
            glTranslatef(x,y,0);
            glColor3f(1,1,0);
            glutSolidTeapot(0.3);
        glPopMatrix();///還原原位置
}
5.修改display(),導入MyTeapot()
void Display(){
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
        MyTeapot(0.5,0.5);    ///右上角
        MyTeapot(-0.5,0.5);    ///左上角
        MyTeapot(-0.5,-0.5);    ///左下角
        MyTeapot(0.5,-0.5);    ///右下角


        glutSwapBuffers();
}

Step04:
1.開新檔,沿用上一步程式
2.設值float mouseX=0,mouseY=0;
3.建立mouse()函式
void mouse(int button,int state,int x,int y)
4.寫入mouseX=x;mouseY=y;
void mouse(int button,int state,int x,int y){
    mouseX=x;mouseY=y;
}
5.在Display()加入
MyTeapot((mouseX-150)/150.0,-(mouseY-150)/150.0);
6.在Main()加入
glutMouseFunc(mouse);

Step05:
1.輔助上一步,沿用上一步程式
2.加入外掛#include <stdio.h>
在mouse()加入
printf("%d,%d,%d,%d\n",button,state,x,y);
會輸入座標軸




2022年3月8日 星期二

連week03 - 小畫家 , 滑鼠移動控制 與 利用滑鼠找座標


03-1 畫圖 小小兵












---------------------------------------------------------------------------------------------------------------------------
重點
#include <math.h>  // sin() ,cos()

void myCircle(float x,float y, float r)
{
    glBegin(GL_POLYGON);
    for(float a=0;a<3.1415926*2;a+=0.01){
        glVertex2f(x+r*cos(a),r*sin(a));
    } // 要畫三角函數
    glEnd();
 }

glColor3ub(255,218,102); // ( r , g , b )
      myCircle(0,0,2); // ( x軸 , y軸 , 大小 )
----------------------------------------------------------------------------------------------------------------
完整程式參考

----------------------------------------------------------------------------------------------------

滑鼠移動控制









完整程式碼



利用滑鼠找座標

----------------------------------------------------------------------------------------------------------------

重點

#include <stdio.h>  // 小黑 print 座標用

----------------------------------------------------------------------------------------------------------------








完整程式碼


尖🦉-圖學筆記 Week03

★小技巧:

   1.利用#include <math.h>可以用sin()、cos()

    2. 以下程式碼可以形成圓形:(x,y可以更改圖形的位置)

        void mycirle( float x , float y , float r){

               glBegin(GL_POLYGON);

               for( float a=0 ; a<3.1415926*2 ; a+=0.01){  ///乘2拿掉會有半圓 a讓圓的點變多

                   glVertex2f( x+r*cos(a), y+r*sin(a) );

               }

                glEnd();

        

練習範例:

    1.去jsyeh.org/3dcg10/下載 data 跟win32

    2.windows 解壓縮到windows\

        data解壓縮後放進剛剛解壓縮的windows

    3.執行今天要用的windows/Tranformation.exe:

        右上角Screen-space view視窗 按右鍵:可以選擇其他形狀。

        中下 Command manipulation window視窗按右鍵:可以調整旋轉、位置等的數值。


建立GLUT專案-Translate(移動):
    1.今天的程式碼:(螢光色的是新教的)

        #include <GL/glut.h>
            void display()
           {
                glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);

                 glPushMatrix();///備份舊的位置的矩陣
                      glTranslatef( 0.5 , 0.5 , 0);///改變位置,不過這個移動會累積,所以要用push跟pop 來固定位置。Translatef(f前面沒有數字)
                      glColor3f(1,1,0);
                      glutSolidTeapot(0.3);
                 glPopMatrix();///還原矩陣

              glutSwapBuffers();
         }
        int main(int argc,char**argv)
        {
             glutInit(&argc,argv);
             glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
             glutCreateWindow("第三周Translate");

             glutDisplayFunc(display);

             glutMainLoop();
        }

    2.另加函式簡化:
            更改x和y的值就能一次創造多的茶壺。

能利用滑鼠控制的專案:
    1.利用glutMouseFunc(mouse)能隨著滑鼠點的位置改變:
            

    2.tea( (mousex-150)/150.0 , -(mousey-150)/150.0 ); 會這樣寫是因為要座標轉換
        圖裡的紅色座標是滑鼠用的,綠色是畫3D圖的座標,所以我們會需要轉換。

    
利用滑鼠點擊印出座標:
    小黑視窗會顯示按下與放開後的座標!
作業可利用滑鼠點出座標,順便印出。
*printf(" glVertex2f((%d-150)/150.0 ,-(%d-150)/150.0)\n",x,y); ///可以利用這行去快速拿座標

            




week03

 這周一開始我們先去https://jsyeh.org/3dcg10/的網站裡把data跟win32下載下來

之後把兩個檔案都解壓縮,然後把Transformation.exe打開

可以拉動下面的綠色數字來改變模型的位置、大小等等
並且在右上角模型上按右鍵,就可以更換其他不同的模型


接著我們用上週的程式碼
把茶壺移動到右上角


再來我們可以利用函式,把它分成四份

#include <GL/glut.h>
void myTeapot(float x,float y)
{
    glPushMatrix();///備份矩陣
    ///移動會累積,因為它會修改矩陣
       // glTranslatef(0.5,0.5,0);///右上角
        glTranslatef(x,y,0);///
        glColor3f(1,1,0);///黃色
        glutSolidTeapot(0.3);///茶壺
    glPopMatrix();///還原矩陣(還原舊的位置)
}
void display()
{
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     myTeapot(0.5,0.5);
     myTeapot(0.5,-0.5);
     myTeapot(-0.5,-0.5);
     myTeapot(-0.5,0.5);
     glutSwapBuffers();
}
int main(int argc,char** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week02_1");

    glutDisplayFunc(display);
    glutMainLoop();
}
之後再加上mouse函式,只要滑鼠點擊左鍵,茶壺就會移動到滑鼠所在的位置

#include <GL/glut.h>
float mouseX=0,mouseY=0;
void myTeapot(float x,float y)
{
    glPushMatrix();///備份矩陣
    ///移動會累積,因為它會修改矩陣
       // glTranslatef(0.5,0.5,0);///右上角
        glTranslatef(x,y,0);///
        glColor3f(1,1,0);///黃色
        glutSolidTeapot(0.3);///茶壺
    glPopMatrix();///還原矩陣(還原舊的位置)
}
void display()
{
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     myTeapot((mouseX-150)/150.0,-(mouseY-150)/150.0);
     glutSwapBuffers();
}
void mouse(int button,int state,int x,int y)
{
    mouseX=x;mouseY=y;
}
int main(int argc,char** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week02_1");

    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMainLoop();
}




然後我們加上#include <stdio.h>
和printf()
讓他能夠印出茶壺所在的3D座標








爆肝Week03

 範例 http://jsyeh.org/3dcg10

1. 下載網頁中的data, win32

2. 將windows解壓縮, data.zip/data丟進解壓縮後的windows資料夾
 3. 執行Transformation.exe
    對視窗右上角點擊右鍵:換模型
    拖曳下方綠色數值:旋轉、移動、大小


移動 Translattef()
使用上週寫出茶壺的程式碼
1.在座標上畫出圖形
```
#include <GL/glut.h>

void display()
{
    glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);

    glPushMatrix();///備份矩陣
    ///移動會累積, 因為它會修改矩陣
        glTranslatef(0.2, 0.6, 0.8);
        glColor3f(1, 1, 0);
        glutSolidTeapot(0.3);
    glPopMatrix();///還原矩陣
    /*備份與還原間要縮排*/
    glutSwapBuffers();
}

int main(int argc, char** argv)
{
    glutInit( &argc, argv);
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
    glutCreateWindow("week_02");

    glutDisplayFunc(display);
    glutMainLoop();
}

```
結果:

2.利用坐標軸在視窗上畫出4個茶壺:
```
#include <GL/glut.h>
void MyTeapot(float x, float y)
{
    glPushMatrix();///備份矩陣
    ///移動會累積, 因為它會修改矩陣
    /// glTranslatef(0.5,0.5,0.5)
        glTranslatef(x, y, 0);
        glColor3f(1, 1, 0);
        glutSolidTeapot(0.3);
    glPopMatrix();///還原矩陣
    /*備份與還原間要縮排*/
}
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    MyTeapot(0.5, 0.5);
    MyTeapot(0.5, -0.5);
    MyTeapot(-0.5, -0.5);
    MyTeapot(-0.5, 0.5);
    glutSwapBuffers();
}
int main(int argc, char** argv)
{
    glutInit( &argc, argv);
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
    glutCreateWindow("week_02");

    glutDisplayFunc(display);
    glutMainLoop();
}

```
結果:

滑鼠事件 glutMouseFunc()
1.新增滑鼠事件,茶壺會移動到指定位置
```
#include <GL/glut.h>
float mouseX=0, mouseY=0;
void MyTeapot(float x, float y)
{
    glPushMatrix();///備份矩陣
    ///移動會累積, 因為它會修改矩陣
    /// glTranslatef(0.5,0.5,0.5)
        glTranslatef(x, y, 0);
        glColor3f(1, 1, 0);
        glutSolidTeapot(0.3);
    glPopMatrix();///還原矩陣
    /*備份與還原間要縮排*/
}
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    MyTeapot( (mouseX-150.0)/150.0, -(mouseY-150)/150.0 );
    glutSwapBuffers();
}
void MouseClick(int button, int state, int x, int y)
{
    mouseX=x; mouseY=y;
}
int main(int argc, char** argv)
{
    glutInit( &argc, argv);
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
    glutCreateWindow("week_03");
    glutMouseFunc(MouseClick);///滑鼠事件

    glutDisplayFunc(display);
    glutMainLoop();
}
```
結果:
2.座標換算
新增printf函式輸出座標可以查看當前座標
3.利用printf函式印出座標與程式碼,協助完成
HW2
```
#include <GL/glut.h>
#include <stdio.h>
float mouseX=0, mouseY=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
///    MyTeapot( (mouseX-150.0)/150.0, -(mouseY-150)/150.0 );
    glutSwapBuffers();
}
void MouseClick(int button, int state, int x, int y)
{
    mouseX=x; mouseY=y;
    printf("    glVertex3f((%d-150.0)/150.0, -(%d-150)/150.0);\n", x, y);
}
int main(int argc, char** argv)
{
    glutInit( &argc, argv);
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
    glutCreateWindow("week_03_mouse");
    glutMouseFunc(MouseClick);///滑鼠事件

    glutDisplayFunc(display);
    glutMainLoop();
}

```


VERY BEAUTIFUL, VERY POWERFUL

一.     一樣先安裝且設定好freeglut,OpecCV, 開啟CodeBlocks建立新專案 week11_gundam,                 把 MyGundam.zip下載解壓縮後的data資料夾放到freeglut/bin裡面 把week09_openc...