#include <stdio.h>
int main()
{
FILE * fout = fopen("output.txt", "w+");
///printf("Hello World\n");
fprintf(fout,"Hello World\n");
}
按鍵輸入寫檔程式碼:
開freeglut專案,並刪除打光程式碼以上的程式碼。
再來控制關節
4.開啟GLUT的專案,並先刪除打光前的程式碼
#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個角度的值,印到檔案去
}
5.刪除以下程式碼,並執行
6.加入現在要做的程式碼
程式碼:
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事件
7.執行檔案
沒有留言:
張貼留言