2016年3月21日 星期一

Week05

1.download 網站:http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
   下載data.zip        =>     桌面/window/data/3D模型
           window.zip  =>     桌面/window/Transformation.exe
           glut32.dll     =>     桌面/window/glut32.dll
   打開Transformation.exe右鍵swap交換translate/rotate
    (B)【Rotate】旋轉
         【Transformation】移動
          旋轉在移動之前,會因為汽車寬度越大,而影響旋轉的半徑會越大;
          寬度越小,而影響的半徑會越小。
          
          小葉老師在大鍋子裡的右側做旋轉,然後調整transformation,就會看到整個大鍋子都在            轉
    (A)【Transformation】
         【Rotate】
           移動在旋轉前,汽車是在原地旋轉
           
2.用glutMotionFunc(motion);
       void motion(int x,int y)
       {
             rotX=x;       ///用來旋轉
             display();
        }

    (1)x軸或y軸可以旋轉
    
#include <GL/glut.h>
float rotX=0;
void display()
{
    glClearColor(1,1,1,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();   ///備份Matrix (Matrix裡有translate,  rotate, scale的量值) 
        glRotatef(rotX, 0,1,0);  ///用來旋轉
        glColor3f(1,0,0);
        glutSolidTeapot(0.3);
    glPopMatrix();    ///還原Matrix (回到剛剛push時的樣子)
    glutSwapBuffers();
}
void motion(int x,int y)
{
    rotX=x;
    display();             ///glutPostRedisplay();
}
int main (int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);   ///double buffer兩倍記憶體
    glutCreateWindow("hello3D");
    glutDisplayFunc(display);
    glutMotionFunc(motion);

    glutMainLoop();
}

(2)

#include <GL/glut.h>
float rotX=0, rotY=0;
void display()
{
    glClearColor(1,1,1,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();        ///備份Matrix (Matrix裡有translate,  rotate, scale的量值)
        glRotatef(rotY, 1,0,0);      ///Y的移動量,讓它對X軸轉
        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;   rotY=y;
    display();            ///glutPostRedisplay();
}
int main (int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);        ///double buffer兩倍記憶體
    glutInitWindowSize(700,700); glutInitWindowPosition(600,0);
    glutCreateWindow("hello3D");
    glutDisplayFunc(display);
    glutMotionFunc(motion);

    glutMainLoop();
}



沒有留言:

張貼留言