2023年5月25日 星期四

jason week15


 1-1


打開window的projection,試著去操作glutLookAt(前3個調整眼睛方向,中間3個為中心點座標,後3個為調整鏡頭的上方)

開啟gitbash,下載2023graphicsb

1-2

新增專案week15-1_gluLookAt
位置改為2023graphicsb的freeglut
新增motion函式,讓畫面藉由滑鼠移動可以從不同視角觀看

2-1

在projection的檔案哩,嘗試其他的投影方式glPerspective,glFrustum,glOrtho

2-2



新增專案week15-2_gluPerspective
從glfrustum改成glOrtho,改成透視的角度,並且調整視角的大小

///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視角

gluPerspective(60, ar, 0.01,1000);

3-1

開啟新專案week15-3_gluPerspective

輸入程式碼,讓茶壺跟著滑鼠移動而改變大小
#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;
    eyeX=(x-150)/150.0, eyeY=(150-y)/150.0;
    gluLookAt(eyeX,eyeY, 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");

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

3-2

新增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);
}

3-3

更改angle的參數,變為矩陣




沒有留言:

張貼留言