#week13
先設定好環境
1.freeglut
2.安裝openCV2.1 add PATH, C:\OpenCV2.1目錄
3.重開CB,Setting-Compiler,3個設定
-Search directiories的 Compiler 對應
C:\OpenCV2.1\include
-Search directiories的 Linker 對應
C:\OpenCV2.1\lib
-Linker setting 要加1. cv210 2.cxcore 3.highgui210
#week13-1_glum_gundam_keyboard_angleID_mouse_motion_angle
沿用上週12-3
0.改目錄名,改.cbp名,改.cbp的內容title1.把float angle =0 改成
```cppfloat angle[20] = {};int angleID = 0; //0,1,2,3... angle[angleID]
#week13-2_FILE_fopen_fprintf_fsanf
0.改目錄名,改.cbp名,改.cbp的內容title
1.加FILE指標
```cpp
FILE * fin =NULL;
FILE * fout = NULL;
```
3.在motion()裡,要加一段程式```cppvoid 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[i]); fprintf(fout, "%.1f. angle[i] );}printf("\n");fprintf(fout,"\n");
```執行程式時,用mouse motion 一邊改變角度,一邊大量產生角度值小黑關掉後,可在目錄看,看到 angle.txt內 就是剛印的數值
現在要讀```cppvoid keyboard(unsigned char key, int x ,int y){ if(key=='r'){
if(fin==NULL) fopen("angle.txt.", "r");
for(int i=0; i<20; i++){ fscanf(fin, "%f" , & angle[i] );}glutPostRedisplay();
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[i]);
fprintf(fout, "%.1f. angle[i] );
}
printf("\n");
fprintf(fout,"\n");
沒有留言:
張貼留言