2024年5月16日 星期四

week13

 week13

## week13-1_glm_gundan_keyboard_angleID_mouse_notion_angle

把環境設好: download opencv
小心:add PATH
小心:目錄不要改
小心:重開codeblocks

codeblocks: setting-compiler
Search directories的Compiler: C:\OpenCV2.1\include
Search directories的Linker: C:\OpenCV2.1\lib
Linker setting: cv210 cxcore210 highgui210

再把 Github 的程式下載(兩種下載法 Git指令 or Download ZIP)

再把week12-3改成week13-1

用右鍵Notepad++開 .cbp 檔,改Titlle


```cpp

float angle[20] = {};

int angleID = 0;

int oldX = 0,oldY = 0;

void motion(int x,int y) {

    angle[angleID] += y-oldY;

    oldX = x;

    oldY = y;

    glutPostRedisplay();

}

void mouse(int button,int state,int x,int y) {

    oldX = x;

    oldY = y;

}

void keyboard(unsigned char key,int x,int y){

    if(key=='0') angleID = 0;

    if(key=='1') angleID = 1;

    if(key=='2') angleID = 2;

    if(key=='3') angleID = 3;

}

```

glRotatef(angle[1],1,0,0);

```

glutMouseFunc(mouse);

glutMotionFunc(motion);

glutKeyboardFunc(keyboard);

```


滑鼠右鍵拖曳可以轉動、鍵盤0、1可以切換X軸和Z軸,X軸結合了上禮拜內容可以曲臂!!!

## week13-2_FILE_fopen_fprintf_fscanf

1.把week13-1複製過來用
2.要加FILE指標

```cpp
FILE * fin = NULL;
FILE * fout = NULL;
#include <stdio.h>
void motion(int x,int y) {
    angle[angleID] += y-oldY;
    oldX = x;
    oldY = y;
    glutPostRedisplay();
    if(fout==NULL) fout = fopen("angle.txt","w+");
    for(int i=0;i<20;i++) {
        printf("%.1f ",angle[1]);
        fprintf(fout,".1f",angle[1]);
    }
    printf("\n");
    fprintf(fout,"\n");
}

```
執行程式時,用mouse motion 一邊改變角度,
一邊大量產生角度值
小黑關掉後,可以在目錄裡看到angle.txt

##week-2 最後三個物件可以轉

最後一個用github gist






沒有留言:

張貼留言