#week16
1. 主題: camera
先用上課的課本教材
https://jsyeh.org/3dcg10
1.data.zip
2. windows.zip => 下載\windows\Project.exe
了解gluLookAt( eyeX, eyeY, eteZ, centerX, centerY, centerZ, upX, upY, upZ);
##week16-0_sample
先設好今天的上課環境
0. 安裝 freeglut
1. 安裝OpenCv2.1
2. 把CodeBlocks Setting-Compiler加入3個設定:
-Search directories的compiler要設C:\OpenCV2.1\include。
-Search directories的Linker要設C:\OpenCV2.1\lib。
-Linker setting要設cv210 cxcore210 highgui210
##week16-1_sample_gluLookAt
1. 把剛剛week16-0整個目錄, 複製成week16-1
2. 複製後, 改目錄名和改.cbp專案檔名, 用Notepad++改內容
樣修改的程式碼, 是想要 Look At 看著某個物體
我們的眼睛: 0, 0, 0
要看的主角: -2.4,1.2,-6
我們的up 向量: 0, 1, 0
我們注入的函釋, 是
glutReshapeFunc(resixa);
ˋˋˋcpp
void resize(int width, int height)
{
...
gluLookAt(0, 0, 0, -2.4, 1.2, -6, 0, 1, 0):
}
ˋˋˋ
##week16-2_teapot_gluLookAt_glutReshapeFunc_reshape
#include <GL/glut.h>
void display() {
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glutSolidTeapot( 0.3 );
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week16-2");
glutDisplayFunc(display);
glutMainLoop();
}
課本教學:
gluOrtho(左,右,下,上,近,遠);
gluPerspective(張角, 長寬比, 近, 遠);
gluFrustum(左,右,下,上,近,遠);
寫程式, 在int main()裡
glutReshapeFunc(reshape);
在前面, 準備void reshape(int w, int h);{
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();
}
##week16-3_myTexture_id1_id2_glBindTexture
讓程式, 可以有2張貼圖, 可以參考week05-2 和 week05-3
week16-3_myTexture_id1_id2_glBindTexture
1. 新增專案File-New-Project, GLUT專案
2. 貼上11行的GLUT程式, 再貼上week05-2的myTexture 12行程式
沒有留言:
張貼留言