2016年6月6日 星期一

Liu Workingshop Week XVI

課堂作業:運鏡效果
步驟1:先用Code::Blocks開啟一個新的貝殼專案檔 步驟2:用glu程式碼做出運鏡效果(gluLookAt()) 程式碼如下: #include <GL/glut.h>//從桌面上的freeglut\GL\glut的程式 #include <stdio.h> void display() {
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glutSolidTeapot(1);
    glPopMatrix();
    glutSwapBuffers();
} void motion(int x,int y) {
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(x/80.0,y/200.0,5,
              0,0,0,
              0,1,0);
    glutPostRedisplay();
} void resize(int w,int h) {
    glViewport(0,0,(GLsizei)w,(GLsizei)h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(65.0,(GLdouble)w/h,1.0,100.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0.0,0.0,5.0,
              0.0,0.0,0.0,
              0.0,1.0,0.0);
} int main(int argc, char**argv) {
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);//設定視窗模式
    glutCreateWindow("camera");//叫出顯示圖案的視窗""裡為視窗名
    glutDisplayFunc(display);//呼叫void裡的函釋
    glutMotionFunc(motion);
    glutReshapeFunc(resize);

    glutMainLoop();

}
 

沒有留言:

張貼留言