2016年3月21日 星期一

Week05

Hw01
(A)

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

(B)

案右鍵Swap Translate/Rotate
先移動再轉 , 變成想像在一個鍋子裡繞著鍋邊轉

Hw02



#include <GL/glut.h>
float rotX=0;
void display()
{
      glClearColor(1,1,1,1);
      glClear(GL_COLOR_BUFFER_BIT);  //背景顏色
      glPushMatrix();          //備份Matrix  (Rotate/Translate/Scale等資料)
          glRotatef(rotX,0,1,0); //x的移動量 , 讓他對y軸轉
          glColor3f(1,0,0);
          glutSolidTeapot(0.3);
    glPopMatrix();             //還原Matrix   (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();
}

Hw03  茶壺旋轉


#include <GL/glut.h>
float rotX=0,rotY=0;
void display()
{
      glClearColor(1,1,1,1);
      glClear(GL_COLOR_BUFFER_BIT);
      glPushMatrix();
          glRotatef(rotY,  1,0,0);   //Y的移動量 , 讓他對X軸轉
          glRotatef(rotX,  0,1,0);   //X的移動量 , 讓他對Y軸轉
          glColor3f(1,0,0);
          glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}
void motion(int x,int y)
{
     rotX=x; rotY=y;
     display();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(300,300); glutInitWindowPosition(600,0); //放大和位置
    glutCreateWindow("hello3D");

    glutDisplayFunc(display);
    glutMotionFunc(motion);

    glutMainLoop();
}

沒有留言:

張貼留言