電腦圖學 2023-05-24 Week15
1. 主題: 攝影機 Camera2. 主題: 投影、運鏡
gluPerspective(), gluLookAt()
3. 期末作品
I. Open the file "projection" in data from teacher's web
eye: 從哪裡看
center: 看哪裡
center: 看哪裡
up: 拍攝角度/方向
fovy: field of view (y方向) 視野的角度,
若fov的角度越小, 則看到的東西佔的比例就會變大
aspect: aspect ratio 長寬比, 通常要依照視窗的長寬長決定
zNear zFar: 在z方向的近的切一刀, 遠的切一刀,
再決定哪個範圍裡的內容會被投影到方塊裡, 再壓扁畫出來
III.
{
glViewport(0, 0, w, h); /// 視窗裡會看到的2D範圍
float ar = w/ (float) h;/// aspect ratio 長寬比
glMatrixMode(GL_PROJECTION); /// 先切換到 Project 矩陣
glLoadIdentity(); /// 矩陣清空, 成為單位矩陣 (最一開始的矩陣)
gluPerspective(60, ar, 0.01, 1000); ///現在一片空白, 因為在茶壺裡
glMatrixMode(GL_MODELVIEW); /// 做好後馬上切回 model view 矩陣
glLoadIdentity(); /// 矩陣清空, 成為單位矩陣 (最一開始的矩陣)
gluLookAt(0,0,1, 0,0,0, 0,1,0);
/// 在0,0,1 看著茶壺的0,0,0, up是0,1,0
glutPostRedisplay();
}
IV. 3D teapot (add x, y)
V. Back to the final project
if (key=='s') { ///按下s會記錄目前轉動的角度到motion.txt
if (fout==NULL) fout = fopen("motion.txt", "w"); /// 寫檔案 5.24
for (int i=0; i<20; i++){
fprintf(fout, "%.2f ", angle[i]); /// 寫檔案, 有空格
}
fprintf(fout, "\n"); /// 寫檔案, 後面有跳行
}else if (key=='r'){ ///按下r會撥放motion內紀錄的角度
if (fin==NULL) fin = fopen("motion.txt", "r");
for (int i=0; i<20; i++){
fscanf(fin, "%f", &angle[i]);
}
glutPostRedisplay();
}
沒有留言:
張貼留言