先用codeblocks開啟貝殼圖示
接下來便開始寫程式碼
#include <stdio.h> FILE*fout=NULL;///(1)宣告一個檔案指標 int main() { ///檔案寫檔 fout=fopen("filename.txt","w++");///(2)我們要開檔案 for(int i=0;i<20;i++) { ///printf("Hello World\n"); fprintf(fout,"Hello World\n");///(3)印出來到檔案 } }
3.打上程式碼
(f是指file的意思)
(w+是寫檔)
4.可以看到資料夾裡有檔案
5.完成
(2)主題:關節、擺動作
#include <stdio.h>
FILE * fout2=NULL;///寫另一個檔案
FILE * fin2=NULL;///讀另一個檔案
float angle[20];///有20個關節的角度
int main()
{
fout2=fopen("motion.txt","w+");///另一個有關節膽案
for(int i=0;i<20;i++)
{
fprintf(fout2," %.2f ", angle[20]);///另一個有關節的角度
}
}
(3)
(3)
#include <GL/glut.h>
float angle[20];///NOW2
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glColor3f(1, 1, 1);///white
glutSolidTeapot( 0.3 );///body
glPushMatrix();
glTranslatef(0.2, 0, 0);///NOW2 (3)掛上去
glRotatef(angle[1], 0,0,1);///NOW2 ///(2)旋轉
glTranslatef(0.15, 0, 0);///NOW2 (1)旋轉中心
glColor3f(1, 0, 0);///red
glutSolidTeapot( 0.2 );///right arm
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
int oldX=0;///NOW2
void mouse(int button, int state, int x, int y)///NOW2
{///NOW2
oldX = x;///NOW2
}
void motion(int x, int y)///NOW2
{///NOW2
angle[1] += x-oldX;///NOW2
oldX = x;///NOW2
display();///NOW2
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
///glutInitWindowSize(600,600);///可以開大一點的window
glutCreateWindow("Week 13 angle motion file");
glutMouseFunc(mouse);///NOW2
glutMotionFunc(motion);///NOW2
glutDisplayFunc(display);
glutMainLoop();
}
就可以用滑鼠控制另一個茶壺
(3)主題:複習(4)作業:機器人擺動作
沒有留言:
張貼留言