2023年5月25日 星期四

15binggreen

 https://jsyeh.org/3dcg10/ 下載 data win32 把data放在windows裡面


gluLookAt <eye 控制鏡頭視角 x控制左右 y控制上下 x控制遠近
center 是鏡頭中心點座標

up 橫拍或直拍
week15-1_gluLookAt 加鏡頭




float eyeX =0,eyeY=0; void motion(int x,int y){ ///加motion eyeX = 3*(x-320)/320.0;///算eyeX的座標 eyeY=3*(240-y)/240.0;///算eyeY的座標 glLoadIdentity(); gluLookAt(eyeX,eyeY,-3,0,0,-6, 0,1,0); /// EYE位置 中間主角 UP向量 glutPostRedisplay(); }

fov field of veiw(y方向) 視野張開的角度
aspect aspect ratio 長寬比

week15-2_glutPersprctive

glOrtho(-ar*3,ar*3,-1.0*3,1.0*3,2.0,100.0);
gluPerspective(60,ar,0.01,1000);

week15-3_perspective_glulookat




#include <GL/glut.h>
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();
}
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);
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week15");

    glutReshapeFunc(reshape);
    glutMotionFunc(motion);
    glutDisplayFunc(display);

    glutMainLoop();
}


沒有留言:

張貼留言