作業一
程式碼
#include <stdio.h>
FILE *fout=NULL,*fin=NULL;
int main(int argc,char**argv)
{
if(fout==NULL)
fout=fopen("output.txt","w+");
fprintf(fout,"Hello World\n");
return 0;
}
FILE *fout=NULL,*fin=NULL;
int main(int argc,char**argv)
{
if(fout==NULL)
fout=fopen("output.txt","w+");
fprintf(fout,"Hello World\n");
return 0;
}
作業二
茶壺讀取
(1).加入檔案
作業三
按R可以移動水壺
#include<GL/glut.h>
#include<stdio.h>
FILE *fout=NULL,*fin=NULL;
int nowX=0, nowY=0;//, oldX=0, oldY=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef((nowX-150)/150.0, -(nowY-150)/150.0, 0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int x, int y)
{
if(fout==NULL) fout=fopen("motion.txt","w+");
fprintf( fout, "%d %d\n", x, y);
printf("%d %d\n", x, y);
}
void keyboard(unsigned char key, int x, int y)
{
if(key=='r'){
if(fin==NULL) fin=fopen("motion.txt","r");
fscanf( fin,"%d %d", &nowX, &nowY);
printf("%d %d\n", nowX, nowY);
}
glutPostRedisplay();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
glutCreateWindow("3D");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutKeyboardFunc(keyboard);
glutMainLoop();
}






沒有留言:
張貼留言