2015年3月18日 星期三

02160145_方得榮 Week04

原本樣子
#include <GL/glut.h>
void display()
{
    glutWireTorus(0.3,0.7,30,30);///(內徑R,外徑R,橫切,縱切)
    glutSolidTeapot(0.2);
    glFlush();

}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("02160200");
    glutDisplayFunc(display);

    glutMainLoop();
}
移動中間的茶壺
#include <GL/glut.h>
void display()
{
    glutWireTorus(0.3,0.7,30,30);///(內徑R,外徑R,橫切,縱切)
    glPushMatrix();
        glTranslatef(0.5,0,0);///移動(x,y,z)
    glutSolidTeapot(0.2);
   glPopMatrix();
    glFlush();

}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("02160200");
    glutDisplayFunc(display);

    glutMainLoop();
}

旋轉
#include <GL/glut.h>
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT);///清畫面
    glPushMatrix();///備份matrix
        glRotatef(angle,1,1,0);///旋轉對(1,1,0)軸 轉動angle
    glutWireTorus(0.3,0.7,30,30);///(內徑R,外徑R,橫切,縱切)
        ///glTranslatef(0.5,0,0);移動(x,y,z)
    glutSolidTeapot(0.2);
   glPopMatrix();///還原matrix
    glFlush();
    angle+=0.1;///每次加一點

}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("02160200");
    glutDisplayFunc(display);
    glutIdleFunc(display);

    glutMainLoop();
}

沒有留言:

張貼留言