2018年3月30日 星期五

Week 05 游伃瑄

(1) 到 http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/ 

下載 [data] [win32] [glut32.dll] 三個檔案



(2) 將下載好的壓縮檔 [windows] 解壓縮,

並將 [glut32.dll] 和 [data] 複製到window資料夾裡



(3) 開啟 Transformation.exe

並觀察 移動 和 轉動(公轉/自轉) 的相對關係

滑鼠右鍵 -> [s]Swap Translate/Rotate -> 觀察程式碼交換後的差別



(4) 老師用小畫家來講解自轉和公轉的差別處 


公轉:
glRotatef(0.00,0.00,0.00); 
glTranslatef(0.00,0.00,0.00); 

自轉:
glTranslatef(0.00,0.00,0.00); 
glRotatef(0.00,0.00,0.00); 



-------------------------------------------------------------


(1) 在 Codeblocks 開啟 GLUT 程式


到moodle下載freeglut-MinGW-3.0.0-1.mp.zip > 解壓縮 > freeglut > lib > 
複製libfreeglut.a > 貼上並重新命名為libglut32.a > 開啟Codeblocks > File > 
New > Project > GLUT

(2) 修改程式碼並觀察各種變化


















(3) 程式碼加入glColor3f(1,1,1); 讓其他物件變黑白




(4) 修改程式碼讓圓球繞著圓心公轉


glPushMatrix();
     glRotated(a,0,0,1);
     glTranslated(-2.4,1.2,-6);
     glutSolidSphere(1,slices,stacks);
glPopMatrix();



-------------------------------------------------------------

(1) 延續上周的自轉茶壺


複製貼上老師在Facebook社團的程式碼

#include <GL/glut.h>
float angle=0;///Now: 讓茶壼自動轉動的角度
void display()
{
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     glPushMatrix(); ///Now:備份矩陣
          glRotatef(angle, 0,0,1); ///Now:轉動
          glutSolidTeapot(0.3);
     glPopMatrix(); ///Now:還原矩陣
     glutSwapBuffers();
}
void motion(int x, int y)
{
     angle=x; ///Now: 改變角度
     glutPostRedisplay(); ///Now: 請 重畫畫面
}
int main(int argc, char**argv)
{
     glutInit(&argc, argv);
     glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
     glutCreateWindow("Week05 TRT");
     glutDisplayFunc(display);
     glutMotionFunc(motion); ///Now
     glutMainLoop();
}

(2) 移動茶壺的把手到中心,讓茶壺以把手為中心旋轉


#include <GL/glut.h>
float angle=0; ///Now: 讓茶壼自動轉動的角度
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix(); ///Now:備份矩陣
        glRotatef(angle, 0,0,1); ///Now:轉動
        glTranslatef(0.45,-0.10,0);
        glutSolidTeapot(0.3);
    glPopMatrix(); ///Now:還原矩陣
    glutSwapBuffers();
}
void motion(int x, int y)
{
    angle=x; ///Now: 改變角度
    glutPostRedisplay(); ///Now: 請 重畫畫面
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("Week05 TRT");

    glutDisplayFunc(display);
    glutMotionFunc(motion); ///Now
    glutMainLoop();
}




(3) 把茶壺做延伸












沒有留言:

張貼留言