2019年3月14日 星期四

郁婷 a 筆記 (移動/旋轉/縮放與矩陣(Matrix)

1.進入 www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10
           下載:(1)windows.zip → 下載 / windows / Transformation.exe
                       (2)data.zip → 下載 / windows / data / 模型
                       (3)glut32.dll → 下載 / windows / glut32.dll

2.打開Code::Blocks → File → New → Project → GLUT project

   輸入成以下畫面


3.接著要下載我們需要的東西:
  (1)上網搜尋" freeglut windows "
        (2)選擇"  freeglut Windows Development Libraries - Transmission Zero "
        (3)選擇" freeglut 3.0.0 MinGW Package "並下載檔案丟至桌面解壓縮
        (4)點開" lib "資料夾,複製" libfreeglut.a "檔案並改名為" libglut32.a "

4.回到Code::Blocks繼續操作
   選擇剛剛的資料夾位置



一直接續到 Finish

5.將程式碼刪除並Key In我們自己的程式碼

#include <GL/glut.h>
void display()
{
    glPushMatrix(); ///備份矩陣
        glTranslatef( 0.3, 0.3, 0 ); ///移動 (會改矩陣)
        glutSolidTeapot( 0.3 );
    glPopMatrix(); ///還原矩陣,才不會再下次有舊的殘值
    glutSwapBuffers();
}
int main (int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week04");
    glutDisplayFunc(display);

    glutMainLoop();
}

(如圖下所示)


6.將圖檔可以跟著滑鼠移動,所以將程式碼改成

#include <GL/glut.h>
float x=0, y=0; ///滑鼠motion
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glPushMatrix(); ///備份矩陣
        glTranslatef( (x-150)/150.0, -(y-150)/150.0, 0 );///滑鼠motion
        glutSolidTeapot( 0.3 );
    glPopMatrix();///還原矩陣,才不會再下次有舊的殘值
    glutSwapBuffers();
}
void motion(int nowX, int nowY)///滑鼠motion
{
    x=nowX; y=nowY;
    display(); //////滑鼠motion 馬上更新
}///滑鼠motion
int main (int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week04");
    glutDisplayFunc(display);
    glutMotionFunc(motion);///滑鼠motion

    glutMainLoop();
}

(如圖下所示)


以上就是今天的上課內容~~~~~ (๑´ㅂ`๑) /

沒有留言:

張貼留言