2016年3月21日 星期一

03160171 week05


想像車子中間插著一根棍子再轉

按右鍵 Swap translate/rotate
想像在鍋子裡沿著邊緣轉



#include <GL/glut.h>
float rotX=0;
void display()
{
    glClearColor(1,1,1,1);
    glClear(GL_COLOR_BUFFER_BIT);//背景顏色
    glPushMatrix();//備份Rotate/Translate/Scale
    glRotatef(rotX,0,1,0);
    glColor3f(1,0,0);
    glutSolidTeapot(0.3);
    glPopMatrix();//還原push前的資料形式
    glutSwapBuffers();//把上面準備好的程式一次展現出來
}
void motion(int x,int y)//旋轉函式
{
    rotX=x;
    display();
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);//兩倍記憶體和深度用於3D
    glutCreateWindow("hello3D");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}

沒有留言:

張貼留言