2018年5月25日 星期五

Week13劉峻宇

                               使用數字鍵控制茶壺轉動


1.
先畫兩個茶壺 一個中間一個右邊
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glutSolidTeapot(0.3);
        glPushMatrix();
            glTranslatef(0.4, 0,0);
            glRotatef(angle, 0,0,1);
            glTranslatef(0.4, 0,0);
            glutSolidTeapot(0.3);
        glPopMatrix();
    glPopMatrix();
    glutSwapBuffers();
}



2.
加上新的程式, 按數字2可以讓茶壺轉動

#include <stdio.h>
FILE * fout=NULL;
float angle=0;
int oldX=0;
void mouse(int button, int state, int x, int y)
{
    oldX=x;
}
void motion(int x, int y)///用mouse來改關節
{
    angle += x-oldX;
    oldX=x;
    if(fout==NULL){
        fout = fopen("output.txt", "w+");
    }
    fprintf(fout, "%.3f\n", angle);
    printf("%.3f\n", angle);
    glutPostRedisplay();
}



沒有留言:

張貼留言