到jsyeh.org/3dcg10下載
1.data.zip
2.window.zip ⮕ 下載\window\Projection.exe
了解 gluLookAt(eyeX, eyeY, centerZ, centerX, centerY, centerZ, upX, upY, upZ);
0. week16-0_sample
0-1. 安裝freeglut
0-2. 安裝OpenCV2.1
0-3. 重新CodeBlocks, 設定opencv的3個設定
0-4. File ⮕ New ⮕ Project,GLUT專案 week16-0_sample
1. week16-1_sample_gluLookAt
1-1. 把 week16-0 整個目錄複製成 week16-1
1-2. 複製後,改目錄名稱,改 .cbp 專案檔名,用 Notepad++ 改內容
要修改的程式碼,要 Look At 看著某物體
眼睛:0, 0 ,0
要看的主角:-2.4, -1.2, -6
UP的向量:0, 1, 0
將視角固定在某個區域
```cpp
void resize(int width, int height)
{
gluLookAt(0, 0, 0, -2.4, 1.2, -6, 0 , 1, 0);
}
```
按0、1、2、3改變視角
void key(unsigned char key, int x, int y)
{
if(key == '0'){ ///原來的視角,模仿 resize() 函式
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
else if(key == '1'){ ///看左上
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0, 0, 0, -2.4, 1.2, -6, 0 , 1, 0);
}
else if(key == '2'){ ///看正上
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0, 0, 0, 0, 1.2, -6, 0 , 1, 0);
}
else if(key == '3'){ ///看右上
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0, 0, 0, 2.4, 1.2, -6, 0 , 1, 0);
}
}
2. week16-2_teapot_gluLookAt_glutReshapeFunc_reshape
2-1. File ⮕ New ⮕ Project,GLUT專案 week16-2_teapot_gluLookAt_glutReshapeFunc_reshape
2-2. 了解以下程式
glutOrtho(左, 右, 下, 上, 近, 遠);
glutPerspective(張角, 長寬比, 近, 遠);
glutFrustum(左, 右, 下, 上, 近, 遠);
2-3. 寫程式
在 int main() 裡
glutReshapeFunc(reshape);
在前面,準備 void reshapte(int w, int h)```cpp
void reshape(int w, int h){
float ar = w / (float) h ; ///aspect ratio 長寬比
glViewport(0, 0, w, h); ///設定可以看到的範圍,全看到
glMatrixMode(GL_PROJECTION); ///現在要設定成 Projection 矩陣
glLoadIdentity(); ///最原始的單位矩陣I
gluPerspective(60, ar, 0.1, 100); ///透視投影的參數
glMatrixMode(GL_MODELVIEW); ///現在要切換回 model view 矩陣(畫圖的T, R, S
glLoadIdentity();
}
```
3. week16-3_myTextur_id1_id2_glBindTexture
讓程式可以同時貼2張圖(可參考 week05-2 和 week05-3)
3-1. 新增方案,File ⮕ New ⮕ Project,GLUT專案 week16-3_myTextur_id1_id2_glBindTexture
3-2. 貼上11行GLUT程式,再貼上 week05-2 的 myTexture 12行程式
3-3. 寫程式
```cpp
glBindTexture(GL_TEXTURE_2D, id1);
glBegin(GL_POLYGON);
glTexCoord2f(0,0); glVertex2f(-1, +1);
glTexCoord2f(0,1); glVertex2f(-1, -1);
glTexCoord2f(1,1); glVertex2f(+1, -1);
glTexCoord2f(1,0); glVertex2f(+1, +1);
glEnd();
glBindTexture(GL_TEXTURE_2D, id2);
glutSolidTeapot( 0.3 );
```
.png)
.png)
.png)
.png)
.png)
.png)
.png)
沒有留言:
張貼留言