2023年5月10日 星期三

Lisa的電腦圖學 - week13

➤ Week13_匯出模型

1 - 開啟Maya,將al.obj模型拉進場景,分別選取頭、身、手、腳
2 - 點選File ➝ Export Selection  Desktop  Cancel






➤ Week13_綜合練習

1 - 下載git-2.30.0.2-64-bit.exe,將2023graphicsa叫到桌面
        cd desktop 進入桌面
        git clone https://github.com/happylisaya/2023graphicsa把雲端複製下來
        2023graphicsa
        start .

2 - 將freeglut複製進Final_Project,把lib裡的libfreeglut.a複製貼上,重新命名為libglut32.a
3 - Project  Properties  Project's build options  Search directories  Compiler 將路進改成freeglut\include,Linker 將路進改成freeglut\include,最後File  Save Everything





4 - 右鍵notepad++開啟.gitignore檔案,在.a、.lib前加入#,就可以註解掉


5 - 將模型拉進新建的model資料夾

➤ Week13_模型匯入、組合

1 - 將week10_glm_gundam裡的glm.cpp、glm.h複製進Final_Project專案裡

2 - 右鍵Add files  glm.cpp,最後File  Save Everything

3 - 修改main.cpp程式碼
#include <stdio.h>
#include <GL/glut.h>
#include "glm.h"
GLMmodel * head = NULL;
GLMmodel * body = NULL;
GLMmodel * uparmR = NULL;
GLMmodel * lowarmR = NULL;
int show[4] = {0, 1, 0, 0};
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();
}
FILE * fout = NULL;
FILE * fin = NULL;
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);
        if(body==NULL){///week13 step02-1
            head = glmReadOBJ("model/head.obj");
            body = glmReadOBJ("model/body.obj");
            uparmR = glmReadOBJ("model/uparmR.obj");
            lowarmR = glmReadOBJ("model/lowarmR.obj");
        }
        glColor3f(1,0,0);
        if(show[0]) glmDraw(head, GLM_MATERIAL);
        glColor3f(0,1,0);
        if(show[1]) glmDraw(body, GLM_MATERIAL);
        glPushMatrix();
            glTranslatef(teapotX, teapotY, 0);

            if(show[2]) glmDraw(uparmR, GLM_MATERIAL);
        glPopMatrix();
        if(show[3]) glmDraw(lowarmR, GLM_MATERIAL);
    glPopMatrix();
    glutSwapBuffers();
}
int oldX = 0, oldY = 0;
void motion(int x, int y){
    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;
        oldY = y;
        angle = x;
    }
    display();
}
int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week12");

    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutKeyboardFunc(keyboard);

    glutMainLoop();
}

沒有留言:

張貼留言