2019年3月14日 星期四

林芷祺的筆記Week04

Week04   2019/3/14

主題:移動

1.重複上禮拜的動作,開啟http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
2.下載data,win32,glut32.dll (3個檔案)

 3.把window解壓縮

4.data的資料夾移至window

 5.glut32.dll也移至window

6.把Transformation.exe打開 (右上滑鼠右鍵切換圖形/鍵盤R回預設值)



移動茶壺(GLUT)

7.重複上禮拜的動作,開啟glut專案(檔案位置記得存!!!!!!!!)

 8.搜尋freeglut window下載Download freeglut 3.0.0 for MinGW 

9.複製檔案位置 

 10.複製libfreeglut.a--->改成libglut32.a

11.把GLUT的main.cpp裡的程式全部刪掉,改成


#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("06160531_Week04!!");
    glutDisplayFunc(display);
    glutMainLoop();
}

12.執行



用滑鼠移動茶壺

13.將程式改成

#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;///滑鼠motion
    display();///滑鼠motion(馬上更新)
}
int main(int argc, char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("06160531_Week04!!");
    glutDisplayFunc(display);
    glutMotionFunc(motion);///滑鼠motion
    glutMainLoop();
}


 14.執行(按著滑鼠茶壺會跟著跑)






沒有留言:

張貼留言