2024年5月23日 星期四

電腦圖學 Week14 🥴

 week14-1_alpha_interpolation_angle_timer

1. moodle下載 freeglut 拖到桌面

2. 把桌面\freglut\lib\libfreeglut.a 複製成 libglut32.a

3. 安裝 OpenCV 2.1

- 安裝第三步驟, Add OpenCV to system PATH(勾第2或3個, 不要勾第1個)

- 目錄不要改,要用預設的

- 要重開CodeBlocks

4. CodeBlocks 的 settings>compiler 加入 opencv 的3個設定

- Search directories > Compiler 要加上 C:\OpenCV2.1\include

- Search directories > Linker 要加上 C:\OpenCV2.1\lib

- Linker settings 要加上 cv210 / cxcore210 / highgui210

5. 安裝git, 把github上之前寫過的程式複製到桌面

- cd desktop

- git clone https://github.com/xiyu-emma/2024graphicsa

6. 把week13-2 複製成week14-1_alpha_interpolation_angle_timer, cbp檔用Notepad++把13-2都改成14-1

7. 開啟week14-1.cbp

8. 開啟excel, alpha公式:新的*alpha + 舊的*(1-alpha)
B2=A2/20, E2=D2*B2+C2*(1-B2)

6. motion()的一段程式碼剪下貼上到keyboard(), 完成後就只會在按s的時候存檔

else if(key==s){

    if(fout==NULL) fout = fopen("angle.txt", "w+");

    for(int i=0; i<20; i++){

    printf("%.1f ", angle[i]);

    fprintf(fout, "%.1f ", angle[i]);

 }

7. 在main()函式上面新增一個timer函式

void timer(int t){

    glutTimerFunc(1000, timer, t+1);

    printf("現在起床:%d\n", t);

}

8. main()函式裡再新增一行

glutTimerFunc(0, timer, 0);

9. 把步驟7和8 測試用的程式碼註解掉

10. 在keyboard上新增一個timer()函式
float oldAngle[20] = {}, newAngle[20] = {};
void timer(int t){
    glutTimerFunc(50, timer, t+1);
    if(t%20 ==0){
        if(fin==NULL) fin=fopen("angle.txt", "r");
        for(int i=0; i<20; i++){
        oldAngle[i] = newAngle[i];
        fscanf(fin, "%f", & newAngle[i]);
        }
    }
    float alpha = (t%20) / 20.0;
    for(int i=0; i<20; i++){
        angle[i] = newAngle[i]*alpha + oldAngle[i]*(1-alpha);
    }
    glutPostRedisplay();
}

11. keyboard()函式加上一段程式
if(key=='p'){
    glutTimerFunc(0, timer, 0);
}

week14-2_angleX_angleY_10

1. 把week14-1複製成week14-2, cbp檔用Notepad++把14-1都改成14-2

2. 開啟week14-2.cbp

3. 把 if(key=='0') angleID = 0; 增加到0~9

4. 把 float angle[20]= {}; 改成 float angleX[10]= {}, angleY[10]= {};

5. 把 for(int i=0; i<20; i++) 改成 





沒有留言:

張貼留言