2023年5月24日 星期三

辰 電腦圖學 week15

 今日主題
攝影機 Camera

投影,運鏡

glPerspective()

gluLookAt()


期末作品


進入https://jsyeh.org/3dcg10/ ,下載data、win32。


window.zip解壓縮後,把data資料夾複製進去window資料夾。



開啟Projection檔。



up的x軸運鏡




fovy : field of view (y視野)  視野角度。
aspect : aspect ratio 長寬比。


Week15-2
#include <GL/glut.h>
#include <stdlib.h>
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glutSolidTeapot(0.3);
    glutSwapBuffers();
}
void reshape(int w,int h){
    glViewport(0,0,w,h);

    float ar=w/(float)h;

    glMatrixMode(GL_PROJECTION);///臨時切換Model view 矩陣
    glLoadIdentity();
    gluPerspective(60,ar,0.01,1000);

    glMatrixMode(GL_MODELVIEW);///切回Model矩陣

    glLoadIdentity();
    gluLookAt(0,0,1,  0,0,0,  0,1,0);

    glutPostRedisplay();
}
float eyeX=0,eyeY=0;
void motion(int x,int y){

    eyeX=(x-150.0)/150.0;
    eyeY=(150.0-y)/150.0;
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    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");

    glutDisplayFunc(display);
    glutReshapeFunc(reshape);

    glutMainLoop();
}

沒有留言:

張貼留言