2023年5月25日 星期四

week15


 Week15


1.前往網站 jsyeh.org/3dcg10/ 下載 win32.zip data.zip 並解壓所致同個資料夾




2.打開 Projection.exe 來操作gluLookAt數值,進行攝影機轉向



3. gluLookAt有三種可調整攝影機視角的數值

第一行eye是調整看向物件的環視視角

第二行center則是調整攝影機的中心點方向

第三行up是調整攝影機頭上下仰角視野




Week15-1

1.下載git bash並clone github的程式專案 2023graphicsb



2.創建GLUT專案,並測試執行



3.在新創立的專案中,在預設的程式main.cpp中在 int main前一列追加可調整視角的程式碼
float eyeX=0,eyeY=0;
void motion(int x, int y)
{
    eyeX=3*(x-320)/320.0;
    eyeY=3*(240-y)/250.0;
    glLoadIdentity();
    gluLookAt(eyeX,eyeY,3,0,0,-6,0,1,0);
    glutPostRedisplay();
}


4.執行程式,使用滑鼠拖曳視角轉向




Week15-2

1.在Projection.exe第一行程式 gluPerspective中有四個可調整數值
fovy是【field of view】可看見視野廣角角度
aspect是【aspect ratio】視野長寬比




2.創建一個新GLUT專案week15-2



3.使用原預設的程式碼main.cpp開頭 void resize 使用不同視角程式
glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);

glOrtho(-ar*3,ar*3,-1.0*3,1.0*3,2.0,100.0);


gluPerspective(60,ar,0.01,1000);

以上為不同視角程式的圖



Week15-3

1.創建新GLUT專案,並寫一個新的程式碼,利用LookAt程式碼特性
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glutSolidTeapot(0.3);
    glutSwapBuffers();
}
void motion(int x, int y)
{
    glLoadIdentity();
    float eyeX=(x-150)/150.0,eyeY=(150-y)/150.0;
    gluLookAt(eyeX,eyeY,1,0,0,0,0,1,0);
    glutPostRedisplay();
}
int main(int argc,char** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week15");

    glutMotionFunc(motion);
    glutDisplayFunc(display);
    glutMainLoop();
}



2.執行程式並利用滑鼠按住拖曳畫面來讓攝影機轉動,用不同角度看茶壺


3.追加程式碼 reshape,能夠自由拖曳視角觀賞茶壺操作
void reshape(int w,int h)
{
    float ar=w/(float)h;
    glViewport(0,0,w,h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60,ar,0.01,1000);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0,0,1,0,0,0,0,1,0);
}

4.執行程式,用滑鼠拖曳畫面來轉動視角觀看茶壺











沒有留言:

張貼留言