2024年6月3日 星期一

期末報告還沒做涼涼上圖學-不小心用到兩個標籤繼續搬家

Week16-camera

01開啟小葉的教材,了解GLLook at 中 eye , center , up 三個函數中XYZ三個軸的意思

 
*Codeblock前置設定(openCV ,compiler.....)

16-1建立新project:(16-1_sample)和(16-1_glLookAt)*原圖

使用glLookAt函式把中心點變為左上的紅色圓球

39 - gluLookAt(0,0,0(Eye),  -2.4,1.2,-6,(Center)  0,1,0(Up));

*呈現如圖

增加Keyboard if函數可以按一個鍵盤切換想要的視角

EX.

if(key=='1'){

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

gluLookAt(0,0,0, -2.4,1.2,-6, 0,1,0);

結果:

Press ' 0 '

Press ' 1 '

Press ' 2 '


16-2 (Teapot_LookAt)

*會使用到下列個函數

1.gluOrtho(左,下,上,近,遠)

2.gluperspect(張角,長寬比,近,遠)

3.gluFrustum(左,右,下,上,近,遠)

建立專案 貼上11行GLUT函式

新增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.1,100);

    glMatrixMode(GL_MODELVIEW);

    glLoadIdentity();

    gluLookAt(0,0,-3,0,0,0,0,1,0);

}

在main函式加上

glutReshapeFunc(reshape);

*呈現出的Teapot無論如何縮放頁面比例都不會改變


16-3多個貼圖

#include <opencv/highgui.h> ///雿輻 OpenCV 2.1 瘥?蝪∪, ?芾???High GUI ?喳

#include <opencv/cv.h>

#include <GL/glut.h>


int id1,id2;

void display()

{

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glBindTexture(GL_TEXTURE_2D,id1);

    glBegin(GL_POLYGON);

        glTexCoord2f(0,0);glVertex2f(-1,+1);

        glTexCoord2f(0,1);glVertex2f(-1,-1);

        glTexCoord2f(0,1);glVertex2f(+1,-1);

        glTexCoord2f(1,0);glVertex2f(+1,+1);

        glEnd();

    glBindTexture(GL_TEXTURE_2D,id2);

    glutSolidTeapot(0.3);

    glutSwapBuffers();

}

int main(int argc, char**argv)

{

    glutInit( &argc, argv );

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("week16-3_My_Texture");


    glutDisplayFunc(display);

    id1 = myTexture("c:/d5049597.jpg");

    id2 = myTexture("c:/earth.jpg");

    glutMainLoop();

}








沒有留言:

張貼留言