#include <stdio.h>
int main()
{
FILE * fout = fopen("Output.txt","w+");
fprintf(fout, "Hello world/n");
}
即可產生一個記事本的檔案
主題2.控制關節 以下為程式碼
#include <GL/glut.h>
#include <stdio.h>///要檔案
FILE * fout=NULL;///(0)宣告檔案的指標,一開始是空的
float angle=60, angle2=90, angle3=60;///準備3個角度的值
void keyboard(unsigned char key, int x, int y)
{
if(key=='s' || key=='S' || key=='w' || key=='W'){
if(fout==NULL) fout=fopen("output.txt", "w+");
///上面這行,只有第一次按s鍵,才會還沒有值,才fopen
///因為第二次按s鍵,fout名花有主,不會再重覆開檔案
printf("%.3f %.3f %.3f\n", angle,angle2,angle3);
fprintf(fout, "%.3f %.3f %.3f\n", angle,angle2,angle3);
}///3個角度的值,印到檔案去
}
主題3.加入接下來的程式碼
程式碼如下:
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
///Now: 要畫東西
glPushMatrix();///Now:像大括號一樣,把裡面的移動/旋轉,控制在裡面,不要影響到外面
glutSolidTeapot(0.3);///Now:身體
glPushMatrix();///Now:像大括號一樣,把裡面的移動/旋轉,控制在裡面,不要影響到外面
glTranslatef(0.4, 0, 0);///Now:(3) 掛在右邊
glRotatef(angle, 0,0,1);///Now:(2) angle的轉動角度,對Z軸
glTranslatef(0.4, 0, 0);///Now:(1) 往右移,讓手把在中間
glutSolidTeapot(0.3); ///Now:右手臂
glPopMatrix();///Now:像大括號一樣,把裡面的移動/旋轉,控制在裡面,不要影響到外面
glPopMatrix();///Now:像大括號一樣,把裡面的移動/旋轉,控制在裡面,不要影響到外面
glutSwapBuffers();
}
void motion(int x, int y)///Now:
{///Now:
angle = x;///Now: 角度會隨mouse motion而改值
glutPostRedisplay();///Now:
}///Now:
glutMotionFunc(motion);///Now: 加上motion事件
即可讓茶壺旋轉!!

沒有留言:
張貼留言