2017年6月6日 星期二

Week 16 彣禎的上課筆記

一.下週期末作品Demo





二.內差公式vs.動作




 
 

三.存檔.讀檔

(1)存檔


 
(2)用鍵盤按s鍵喬好動作後,按s鍵檔案裡就會出現file.txt檔案

 
(3)讀檔
 
 
(3)一直按r鍵就會出現剛剛在file.txt存的動作(並且記得要另外儲存file的內容因為會被覆蓋掉)



 
 
(4)一直按著r鍵就會有連續動作
 
 
 
float alpha=0.0;///現在要改成交叉相乘的內插方式算角度: alpha
float oldAngle[20]={};///現在要改成交叉相乘的內插方式算角度: oldAngle
float newAngle[20]={};///現在要改成交叉相乘的內插方式算角度: newAngle
float angle[20]={};///現在要改成交叉相乘的內插方式算角度: 我們要用來畫的 angle 的陣列
 
FILE * fout=NULL;///存檔的步驟2, 宣告一個檔案的指標, (一開始是空的NULL)
FILE * fin=NULL;///讀檔的步驟1, 宣告一個檔案的指標, (一開始是空的NULL)
void Keyboard(unsigned char key,int x,int y)
{
    printf("%c\n", key);///你按了什麼鍵,印出來,方便了解老師按了什麼鍵
    if(key=='s'){///存檔的步驟3, 在按下 's' 鍵 save存檔
        if(fout == NULL){/// (一開始是空的NULL)
            fout = fopen("file.txt", "w+");///開啟檔案,檔名準備好, 並且是用 write加 模式
            printf("Now open file.txt for write+ Mode\n");
        }
        printf("Now write angle[] %f %f %f %f %f %f %f %f %f\n", angle[0], angle[1], angle[2], angle[3], angle[4], angle[5], angle[6], angle[7], angle[8]);
        fprintf( fout, "%f %f %f %f %f %f %f %f %f\n", angle[0], angle[1], angle[2], angle[3], angle[4], angle[5], angle[6], angle[7], angle[8]);
    }
    if(key=='r'){///讀檔的步驟2, 按下 'r' 去read, ///現在要改成交叉相乘的內插方式算角度
        if(fin == NULL){
            fin = fopen("file.txt", "r");///讀檔的步驟3,檔名準備好, 並且是用 read 模式
            printf("Now open file.txt for read Mode\n");
            fscanf(fin, "%f %f %f %f %f %f %f %f %f", &newAngle[0], &newAngle[1], &newAngle[2], &newAngle[3], &newAngle[4], &newAngle[5], &newAngle[6], &newAngle[7], &newAngle[8]);
        }
        if(alpha >= 1.0){///如果讀太多,alpha超過了, 就要再讀新的angle, 而且要把原來新的,先變舊的
            /// oldAngle = newAngle
            for(int i=0;i<9;i++) oldAngle[i] = newAngle[i];
            /// read newAngle
            fscanf(fin, "%f %f %f %f %f %f %f %f %f", &newAngle[0], &newAngle[1], &newAngle[2], &newAngle[3], &newAngle[4], &newAngle[5], &newAngle[6], &newAngle[7], &newAngle[8]);
            printf("Now read angle[] Pa Pa Pa\n");   ///讀檔的步驟 fscanf()讀進來
            alpha=0.0;
        }
        ///angle = alpha * newAngle + (1-alpha)* oldAngle;
        for(int i=0;i<9;i++){///小心, 角度不見得只有9個,可能更多哦! 要調好,有更多,就要內插更多 ex. 20個
            angle[i]=alpha*newAngle[i] + (1-alpha)*oldAngle[i];///現在要改成交叉相乘的內插方式算角度
        }
        alpha += 0.1;///現在要改成交叉相乘的內插方式算角度, 每次加一點點alpha
        glutPostRedisplay();
    }

 
 

 



四.利用Timer自動內插


五.學期複習


沒有留言:

張貼留言