🧠 ROBOT 2.0 🧠
1.存檔、讀檔
注意下面的存檔位置,去那邊找建造的檔案
程式碼如下:
#include <stdio.h>
int main(int argc,char** argv)
{
FILE * fout =NULL; ///檔案指標
fout=fopen("檔名.txt","w+"); ///file output變數,模式:write
printf("Hello World\n");
fprintf(fout,"Hello World\n");
}
2.改.cbp檔的working_dir
把那個欄位改成.
3.輸出字串
程式碼如下:
#include <stdio.h>
int main(int argc,char** argv)
{
FILE * fin =NULL; ///改成讀檔
fin=fopen("000.txt","r"); /// read
char line[100];
fscanf(fin,"%s",line);
printf(" %s \n",line);
fscanf(fin,"%s",line);
printf(" %s \n",line);
}
4.做出個茶壺
程式碼如下:
#include <stdio.h>
#include <GL/glut.h>
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidTeapot(0.3);
glutSwapBuffers();
}
int main(int argc, char** argv)
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow("08160554");
glutDisplayFunc(display);
glutMainLoop();
}
5.加timer
程式碼如下:
#include <stdio.h>
#include <GL/glut.h>
float angle=0;
int diff=2;
void timer(int t)
{
glutTimerFunc(30,timer,t+1);
angle+=diff;
if(angle>90)diff=-2;
if(angle<0)diff=+2;
glutPostRedisplay();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidTeapot(0.3);
glutSolidTeapot(0.3);
glutSolidTeapot(0.3);
glutSolidTeapot(0.3);
glutSolidTeapot(0.3);
glutSwapBuffers();
}
int main(int argc, char** argv)
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow("08160554");
glutDisplayFunc(display);
glutTimerFunc(0,timer,0);
glutMainLoop();
}
6.做很多個茶壺
程式碼如下:
#include <stdio.h>
#include <GL/glut.h>
float angle=0;
int diff=2;
void timer(int t)
{
glutTimerFunc(30,timer,t+1);
angle+=diff;
if(angle>90)diff=-2;
if(angle<0)diff=+2;
glutPostRedisplay();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(-0.3,0,0);
glRotatef(angle,0,0,1);
glTranslatef(-0.3,0,0);
glutSolidTeapot(0.3);
glPushMatrix();
glTranslatef(-0.3,0,0);
glRotatef(angle,0,0,1);
glTranslatef(-0.3,0,0);
glutSolidTeapot(0.3);
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.2,+0.2,0);
glRotatef(angle,0,0,1);
glTranslatef(-0.15,0,0);
glutSolidTeapot(0.3);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char** argv)
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow("08160554");
glutDisplayFunc(display);
glutTimerFunc(0,timer,0);
glutMainLoop();
}
7.茶壺手臂
程式碼如下:
#include <stdio.h>
#include <GL/glut.h>
float angle=0;
int diff=2;
void timer(int t)
{
glutTimerFunc(30,timer,t+1);
angle+=diff;
if(angle>90)diff=-2;
if(angle<0)diff=+2;
glutPostRedisplay();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidTeapot(0.3);
glPushMatrix();
glTranslatef(-0.3,0,0);
glRotatef(angle,0,0,1);
glTranslatef(-0.3,0,0);
glutSolidTeapot(0.3);
glPushMatrix();
glTranslatef(-0.3,0,0);
glRotatef(angle,0,0,1);
glTranslatef(-0.3,0,0);
glutSolidTeapot(0.3);
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(+0.3,0,0);
glRotatef(-angle,0,0,1);
glTranslatef(+0.3,0,0);
glutSolidTeapot(0.3);
glPushMatrix();
glTranslatef(+0.3,0,0);
glRotatef(-angle,0,0,1);
glTranslatef(+0.3,0,0);
glutSolidTeapot(0.3);
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char** argv)
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow("08160554");
glutDisplayFunc(display);
glutTimerFunc(0,timer,0);
glutMainLoop();
}





沒有留言:
張貼留言