Week13
一、關節擺動
(2)打出程式碼
(3)看到有新增檔案在 C:\Users\user\Desktop\week13_file\file
程式碼:
#include <stdio.h>
FILE * fout=NULL;
int main()
{
fout = fopen("filename.txt", "w+");
for(int i=0;i<20;i++){
fprintf(fout,"Hello World\n");
}
}
二、開始製作機器人
(2)打出程式碼
程式碼:
#include <GL/glut.h>
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);
///glutInitWindowSize(600,600);///我們可以開很大的視窗
glutCreateWindow("week 13 motion TRT angle file");
glutDisplayFunc(display);
glutMainLoop();
}
#include <GL/glut.h>
float angle[20];///NOW
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();///body
glColor3f(1,1,1);///white
glutSolidTeapot( 0.3 );///body
glPushMatrix();///right Arm
glTranslatef(0.18, 0, 0);///(3)掛到肩上
glRotatef(angle[1], 0,0,1);///(2)轉動 ///NOW
glTranslatef(0.18, 0, 0);///(1)改變旋轉中心,放到中心
glColor3f(1,0,0);///red
glutSolidTeapot( 0.2 );///right upper arm
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
int oldX;///NOW
void mouse(int button, int state, int x, int y)///NOW
{
oldX = x;///NOW
}
void motion(int x, int y)///NOW
{
angle[1] += (x-oldX);///NOW
oldX = x;///NOW
display();///NOW
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
///glutInitWindowSize(600,600);///我們可以開很大的視窗
glutCreateWindow("week 13 motion TRT angle file");
glutMouseFunc(mouse);///NOW
glutMotionFunc(motion);///NOW
glutDisplayFunc(display);
glutMainLoop();
沒有留言:
張貼留言