2024年6月6日 星期四

week16(11行程式碼)

 week16-0_sample

上課環境

0.安裝feeglut


openCV

Setting-Compiler 要加入 OpenCV 相關的3個設定
-compiler 的 incldue 要加入 C:\OpenCV2.1\include
-linker 的lib 要加入 C:\OpenCV2.1\lib
-linker 設定 要加入 cv210 cxcore210  highgui210

file-new-project glut專案  week16-0_sample

看課本的程式
jsyeh.org/3dcg10 下載
jsyeh.zip => 下載\

week16-1_sample_gluLookAt
file-new-project
要改 resize()函式 在裡面




現在要做另一個修改 想要在按按鍵時 看不同地方
先把剛剛加的39行註解調

if(key=='1'){///看左上方
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        gluLookAt( 0, 0, 0, -2.4, 1.2, -6, 0, 1, 0);

    }else if(key=='2'){///看上方
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        gluLookAt( 0, 0, 0, 0, 1.2, -6, 0, 1, 0);

    }else if(key=='3'){///看右上方
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        gluLookAt( 0, 0, 0, +2.4, 1.2, -6, 0, 1, 0);
    }


請先看課本範例 Projection.exe 的範例

gluPerspective 透視投影
glOrtho 垂直投影
glFrustum 比較奇怪 我們通常不用它的投影法
左`右`下`上 近 遠 共6組參數

gluPerspective(視角,長寬比,z近,z遠)
fovy filed of view in y視角
aspect ratio 常寬比

我們要寫個程式 11行+8行 做出透視投影
1.file-new-project
2.week16-2_glutReshapeFunc_gluPerspective_gluLookAt
十行基本程式碼(重要)!!!
#include <GL/glut.h>
void display()

{

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glutSolidTeapot(0.3);
    glutSwapBuffers();

}
int main(int argc, char*argv[])
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week08 gundom");
    glutDisplayFunc(display);
    glutMainLoop();
}



這樣子改變視窗大小就不會影響裡面的比例

week16-3_myTexture_id1_id2_glBindTextue
若想要有"兩張貼圖" (一張背景,一張給模型)
1.File-new-project 
用 week05_rotating_earth/main.cpp 裡的程式碼
會出錯因為沒有圖檔




沒有留言:

張貼留言