2019年4月25日 星期四

06160123_Week10電腦圖學

🔺電腦圖學2019-04-25 Week10


(1)期中考:Open GL必背10函式

(2)複習:移動、旋轉、縮放

(3)主題:T-R-T旋轉(改變旋轉軸)

(4)主題:glut


TODO:點名:Veyon Config > 服務 >啟動服務-
TODO:到小葉老師的網站3D Graphics download資料
download:window.zip  解壓縮 至window 
                    data.zip    解壓縮 data拉至window
                   glut32.dll   解壓縮 glut32.dll移至window資料夾

> 開啟 Window >Transformation


       
> 開啟後會看見Texture.exe 視窗

Translate面表示自轉

Translate面表示公轉

轉動移到右邊的胖胖車子」

移動轉動中、比例怪怪的車子


#安裝 GLUT

1、Search Freeglut > Download Freeglut3.0.0 MSVC Package Download freeglut 3.0.0 for MinGW

2、將檔案解壓縮後複製一個libfreeglut.a檔並重新命名為libglut32.a

3、開啟Code Blocks>新增一個新的專案>點選Glut project

4、命名專案>選擇資料存放區(C:\Users\user\Downloads\freeglut\lib)>Finish

5、於左側project開啟程式碼>執行


把程式碼全部刪光光

貼上前幾週學的茶壺程式碼

#include <GL/glut.h>

void display(){

    glutSolidTeapot( 0.3 );
    glutSwapBuffers();
}

int main(int argc,char**argv){

    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("06160123");
    glutDisplayFunc(display);

    glutMainLoop();

}

稍微修改一下程式碼 

#include <GL/glut.h>

float angle=0;
void display(){

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslatef( 0, 0.5 , 0 );///這是往上移度的茶壺
        glutSolidTeapot(0.3);///This is a Teapot
    glPopMatrix();
    glPushMatrix();

    glPopMatrix();

    glPushMatrix();
        glTranslatef( 0.50, 0.625 , 0 );///(3)把它掛在你要的地方
        glRotatef( angle, 0, 0, 1 );///(1)先有個轉動,但怪怪的
        glTranslatef( 0.6, 0 , 0 );///(2)要更早去移動旋轉中心

        glRotatef(-90, 0, 1, 0);///(0)轉動90度的Cone
        glutSolidCone(0.2, 0.6, 30, 30);///直直的Cone
    glPopMatrix();
    glutSwapBuffers();

}


void motion(int x,int y){ ///滑鼠的部分

    angle=x;
    display();

}

int main(int argc,char**argv ){

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("Week10_TRT");

    glutDisplayFunc(display);
    glutMotionFunc(motion);

    glutMainLoop();


}


成果展示,按著移動滑鼠Cone就會旋轉



沒有留言:

張貼留言