課堂內容 : fprintf()、fscanf() 寫檔和讀檔;fprintf()、fscanf() + project
#include <stdio.h>
int main()
{
FILE * fout = fopen("file.txt", "w+");
printf("Hello World\n");
fprintf(fout,"Hello World\n");
fclose(fout);
}
2022電腦圖學 Computer Graphics 授課教師: 葉正聖 銘傳大學資訊傳播工程系 每週主題: 程式環境、點線面顏色、移動/旋轉/縮放與矩陣(Matrix)、階層性關節轉動(T-R-T)、做出機器人、打光、貼圖、glu/glut函式、鍵盤、滑鼠、計時器(timer)、讀入3D模型、粒子系統、聲音、特效、投影矩陣、攝影機與運鏡、機器人2.0、期末作品
課堂內容 : fprintf()、fscanf() 寫檔和讀檔;fprintf()、fscanf() + project
Step01
1.介紹寫檔功能
-Codeblocks 開啟新檔:week14-1.cpp (先在桌面建立一個資料夾,存進去)
2.介紹讀檔功能
-Codeblocks 開啟新檔:week14-2.cpp (先在桌面建立一個資料夾,存進去)
3. -開啟 GLUT 新專案:week14_angle_fprintf
-把上一周 week13_rect_many_TRT 的程式碼拿來用
Step02
1.動畫
-開啟 GLUT 新專案:week14_angles_fprintf_fscanf
-copy 上一個程式碼來用
-按 r 會轉動手臂
2.了解為甚麼 file.txt 檔會放在 freeglut\bin 目錄裡
-用 notepad++ 開啟 week14_angles_fprintf_fscanf.cbp
-把下面兩個地方的路徑改成 "."
-再把 freeglut\bin 目錄裡的 freeglut.dll 複製到專案裡頭就完成了
Step03
1.計時器(1)
-新增 GLUT 專案,檔名:week14_timer
-設五個鬧鐘,每一秒叫一次
2.計時器(2)
-新增 GLUT 專案,檔名:week14_timer_one_by_one
-增加鬧鐘音效,執行五秒鐘後,每一秒響一次
week14
1.今日課程:寫檔fprintf()、讀檔fscanf()、寫檔fprintf()+project、讀檔fscanf()+project
1.1 程式碼:#include<stdio.h>
int main()
{
///檔案指標fout 開啟檔案(檔名,write模式)
FILE * fout = fopen("write.txt","w+");
printf("Hello world\n");
fprintf(fout,"Hello world\n");
fclose(fout);
}
1.2 程式碼:#include<stdio.h>
int main()
{
///檔案指標fout 開啟檔案(檔名,write模式)
FILE * fout = fopen("file.txt","w+");
fprintf(fout,"3.1415926\n");
fclose(fout);///關檔
float angle =0;
FILE * fin=fopen("file.txt","r");
fscanf(fin,"%f",&angle);///沒加&會當
printf("讀到了角度:%f",angle);
fclose(fin);
}
1.3 加上my read 按下鍵盤r可以撥放音樂
#include <opencv/highgui.h>
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
一. 一樣先安裝且設定好freeglut,OpecCV, 開啟CodeBlocks建立新專案 week11_gundam, 把 MyGundam.zip下載解壓縮後的data資料夾放到freeglut/bin裡面 把week09_openc...