2019年3月14日 星期四

~~~Week04

作業一
1.先到http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/ ,下載data win32 glut32.dll

2.將windows壓縮檔解壓縮

3.把data壓縮檔裡面的data檔案和glut32.dll放到解壓縮的windows檔案裡面

4.到windows裡面開啟Transformation.exe可以看到東西

5.更改數值可以移動物體

6.到右邊的視窗點選滑鼠右鍵可以更改圖案

作業二
1.進入https://www.transmissionzero.co.uk/software/freeglut-devel/下載

freeglut 3.0.0 MinGW Package

2.到freegult/lib將libfreeglut.a複製,把檔名改成libglut32.a
3.到codeblocks開啟glut,複製freeglut的位址,貼到glut的GLUT's location

4.就可以開啟

課堂作業
1.將程式刪光

2.打完指令,就可以開啟茶壺
程式碼:
#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();

}


3.讓茶壺可以跟著滑鼠移動
程式碼:
#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
{///滑鼠motion
    x=nowX; y=nowY;///滑鼠motion
    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();
}

沒有留言:

張貼留言