2023年5月10日 星期三

Orangutan - 第十三週 - 綜合練習


=========================================================================

THIRTEENTH

一、Maya 裁切模型

老師的網址(https://jsyeh.org)

1.開啟Maya並匯入模型(File=>Import)

2.選取想要匯出的部位

3.進行匯出(File=>Export Selection),記得要存成OBJ檔


4.使用Git Bash將上週存在github的Final_Project從雲端下載下來

5.將Freeglut放到Final_Project資料夾中

6.將Final Project開啟(File=>Open)

7.設定路徑(Project=>Properties)

8.Project settings=>Compiler路徑改成freeglut\include(設成相對路徑)

9.
Project settings=>Linker路徑改成freeglut\lib
(設成相對路徑)


10.設定完之後就可以成功執行了


11.到2023graphicsa=>.gitignore將.a、.lib用#註解掉


二、組合模型

1.將week10的glm.h、glm.cpp檔複製到Final_Project專案中

2.在Final_Project中新增一個model資料夾,並把裁切好的模型OBJ檔案拉到裡面

3.Add files將glm.cpp加入Final_Project專案中

4.會看到glm.cpp

5.將以下程式碼放入main.cpp中
GLMmodel * head = NULL;
GLMmodel * body = NULL;
GLMmodel * uparmR = NULL;
GLMmodel * lowarmR = NULL;
if(body==NULL){ body = glmReadOBJ("model/body.obj"); glmUnitize(body);///這行之後會改
}
glmDraw(body , GLM_MATERIAL);///這行之後會改

6.執行之後就會看到剛剛所裁切的身體模型

7.使用glScalef()將比例大小調整好,並加上頭的模型看看是否正確

8.執行完之後就會看到模型的大小適中並且有放到正確的位子

9.將原來的keyboard函式註解掉並改為以下的程式碼
int show[4]={0, 1, 2, 3};///來決定要不要顯示 void keyboard(unsigned char key,int x, int y) { if(key=='0') show[0] = !show[0]; if(key=='1') show[1] = !show[1]; if(key=='2') show[2] = !show[2]; if(key=='3') show[3] = !show[3]; glutPostRedisplay(); }
以下是修改display程式碼的部分
if(body==NULL){
        head = glmReadOBJ("model/head.obj");
        body = glmReadOBJ("model/body.obj");
        uparmR = glmReadOBJ("model/uparmR.obj");
        lowarmR = glmReadOBJ("model/lowarmR.obj");
        //glmUnitize(body);
}
if(show[0]) glmDraw(head , GLM_MATERIAL);
if(show[1]) glmDraw(body , GLM_MATERIAL);
if(show[2]) glmDraw(uparmR , GLM_MATERIAL);
if(show[3]) glmDraw(lowarmR , GLM_MATERIAL);

10.執行之後使用數字鍵0、1、2、3就可以讓部位顯示或隱藏

11.將紅框中的程式碼加上或是修改

在display中修改的部分
glPushMatrix();     glTranslatef(teapotX, teapotY, 0);     ///glTranslatef(1.040000, 0.066666, 0);     if(show[2]) glmDraw(uparmR , GLM_MATERIAL); glPopMatrix();

新加的motion函式
int oldX = 0, oldY = 0; void motion(int x,int y) { teapotX += (x - oldX)/150.0; teapotY += (y - oldY)/150.0; printf("glTranslatef(%f, %f, 0);\n",teapotX, teapotY); glutPostRedisplay(); }

在mouse中修改的部分
if(state==GLUT_DOWN){
        oldX = x;
        oldY = y;
        angle = x;
}

記得在main函式中加入
glutMotionFunc(motion);

12.執行後只要移動滑鼠就會顯示座標

13.最後記得檢查.gitignore裡的obj、dill、a、lib是否都有註解掉(註解掉才能儲存到雲端中)







沒有留言:

張貼留言