2022年3月8日 星期二

鹿的電腦圖學筆記week03

 Step01:

1.下載datazip,windows.zip,解壓縮

2.點windows>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);
會輸入座標軸







沒有留言:

張貼留言

VERY BEAUTIFUL, VERY POWERFUL

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