2019年5月17日 星期五

aaaaaa week13

一.檔案

1.開啟貝殼專案

2.輸入程式碼


FILE * fout=NULL;
宣告檔案變數

int main()
{
    fout = fopen("filename.txt", "w+"); //開啟檔案
    for(int i=0;i<20;i++){
        fprintf( fout, "Hello world\n");  //把資料寫入檔案
    }
}

在專案資料夾能找到 filename.txt


#include<stdio.h>
FILE * fout=NULL;
float angle[20];
int main()
{
    fout = fopen("motion.txt", "w+");
    for(int i=0;i<20;i++){
        fprintf( fout, " %.1f", angle[i]);  改成輸出變數
    }
}



二. trt+很多東西複習

做茶壺

把茶壺當手臂 做出來



#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

            glPushMatrix();///NOW2 長出下手臂
                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 lower arm

            glPopMatrix();
        glPopMatrix();

        glPushMatrix();///left 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 );///left upper arm

            glPushMatrix();///NOW2 長出下手臂
                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 );///left lower arm

            glPopMatrix();
        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();
}

做出 兩隻手 會動


加入很多東西


主要是加入可以跟鍵盤互動的程式

還有轉動角度的輸出
 

沒有留言:

張貼留言