2023年5月10日 星期三

ww-week13-綜合練習_作業: (你的)模型擺Pose

 1.裁切模型、組模型

在https://jsyeh.org/3dcg10/中下載[data][win32]兩個檔案 / 在資料夾中開啟後分別解壓縮 / 將data資料夾放到window裡 / 

開啟MAYA/Import/匯入:al.obj / 分別裁切上手臂、下手臂、頭、身體 / file / Export Selection匯出選擇的物件/


小葉老師上課軟體下載git / 將2023graphicsa clone 下來


在codeblocks 開啟2023Grahhicsa 的Final_Project / file / open 開啟.cbp檔

將freeglut加入Final_Project專案裡(為了解決每次都要安裝freeglut的問題)
/並更改freeglut裡的libfreeglut.a複製一個改名為libglut32.a

在專案上面右鍵Properties / Project's build options/

更改兩個工作執行目錄的位置改成相對路徑/compiler和linker都要記得改

修改.gitignore清單,把.lib 和.a註解調解鎖(檢查.dll是否有解鎖)
在第10週用的glm.cpp 和 glm.h 都複製到你的Final_Project專案裡 / 在專案裡Add File把glm.cpp加進去 / save everything / 在FinalProject內新增modle資料夾 / 將剛切好的身體部位複製進去

開始畫出模型 / 先印身體
調整大小並印出頭

用鍵盤控制物件的顯示加入keyboard函式(將之前寫得先註解掉)

加入滑鼠移動功能可以幫助移動到畫面中心,並印出位移量可以幫助之後做TRT時需要的移動



更改gitignore內確認是否有將.obj(3Dmodel檔) .dll(libfreeglut.dll) .a .lib(freegult內的lib目錄)解鎖 / 記得save everything


#include <stdio.h>
#include <GL/glut.h>
#include "glm.h"///week13-1
GLMmodel * head =NULL;///week13-1
GLMmodel * uparmR =NULL;///week13-1
GLMmodel * lowarmR =NULL;///week13-1
GLMmodel * body =NULL;///week13-1
int show[4]={0,1,0,0};///week13-3
void keyboard(unsigned char key,int x, int y){///week13-3
    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();
}///原來的keyboard先註解
FILE * fout=NULL;///step2-2
FILE * fin =NULL;///2
float teapotX=0,teapotY=0;
float angle=0,angle2=0,angle3=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glScalef(0.2,0.2,0.2);///week13-2
        if(body==NULL){///week13-1
            head = glmReadOBJ("model/head.obj");///week13-2
            body = glmReadOBJ("model/body.obj");///week13-1
            uparmR = glmReadOBJ("model/uparmR.obj");///week13-3
            lowarmR = glmReadOBJ("model/lowarmR.obj");///week13-3
            ///glmUnitize(body);///week13-1
        }
        if(show[0]) glmDraw(body, GLM_MATERIAL);///week13-1
        if(show[1]) glmDraw(head, GLM_MATERIAL);///week13-2
        glPushMatrix();///week13-4
            glTranslatef(teapotX,teapotY,0);///week13-4
            if(show[2]) glmDraw(uparmR, GLM_MATERIAL);///week13-3
        glPopMatrix();///week13-4
        if(show[3]) glmDraw(lowarmR, GLM_MATERIAL);///week13-3
    glPopMatrix();
    glutSwapBuffers();
}
int oldX=0,oldY=0;///week13-4
void motion (int x,int y){///week13-4
    teapotX += (x-oldX)/150.0;
    teapotY-= (y-oldY)/150.0;
    oldX = x;
    oldY = y;
    printf("glTranslatef(%f,%f,0);\n",teapotX,teapotY);
    glutPostRedisplay();
}

void mouse(int button,int state,int x,int y)
{
    if(state==GLUT_DOWN){
        oldX = x;///week13-4teapotX = (x-150)/150.0;
        oldY = y;///week13-4teapotY = (150-y)/150.0;
        angle =x;///week13-4
        ///if(fout==NULL)fout =fopen("file4.txt","w");week12
        ///fprintf(fout,"%f %f\n",teapotX,teapotY);
    }
    display();
}
//void keyboard(unsigned char key ,int x,int y)///2keyboard函式
//{
//    if(fin==NULL){///2如果檔案還沒fopen(),就開他
//        fclose(fout);///2前面的mouse會開fout 指標,所以要關掉
//        fin = fopen("file4.txt","r");///2開檔
//    }
//    fscanf(fin,"%f %f",&teapotX,&teapotY);///2讀檔
//    display();///2重畫畫面
//}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week13");

glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);///week13-4
glutKeyboardFunc(keyboard);///2keboard要做事了

    glutMainLoop();
}


git指令
cd desktop
git clone https://github.com/你的帳號/2023graphicsa
cd 2023graphicsa
加入檔案
git add . 
git status

git config --global user.email "jsyeh@mail.mcu.edu.tw"

git config --global user.name "jsyeh"

git commit -m "week10"

git push













沒有留言:

張貼留言