2023年5月11日 星期四

逃離電腦圖學 Week13

 


改這兩個東西
然後GIT PUSH
再開MAYA 裁切Al.obj
拆成 六個部位 保存
再去第八周 複製這兩個檔案到Final_Project
Add File後加入這幾行

#include "glm.h"
GLMmodel * head = NULL;
GLMmodel * body = NULL;
GLMmodel * lefthand = NULL;
GLMmodel * righthand = NULL;

下面程式碼改成這樣

 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    if(head==NULL){
       head=glmReadOBJ("model/head.obj");
       body=glmReadOBJ("model/body.obj");
       lefthand=glmReadOBJ("model/lefthand.obj");
       righthand=glmReadOBJ("model/righthand.obj");
    }
    glPushMatrix();
        glScalef(0.3,0.3,0.3);
        glmDraw(head, GLM_MATERIAL);
        glmDraw(body, GLM_MATERIAL);
        glmDraw(lefthand, GLM_MATERIAL);
        glmDraw(righthand, GLM_MATERIAL);
    glPopMatrix();
    glutSwapBuffers();


加入這串
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();
}
下面改這樣
 if (show[0]) glmDraw(head, GLM_MATERIAL);
 if (show[1])glmDraw(body, GLM_MATERIAL);
 if (show[2])glmDraw(lefthand, GLM_MATERIAL);
 if (show[3])glmDraw(righthand, GLM_MATERIAL);
案0123操作不同部位的顯示
增加滑鼠移動功能
glPushMatrix();
            glTranslatef(teapotX,teapotY,0);
            if (show[0]) glmDraw(head, GLM_MATERIAL);
        glPopMatrix();
另外加
int oldX=0, oldY=0;
void mouse(int button, int state, int x, int y){
    if(state==GLUT_DOWN){
    oldX = x;
    oldY = y;
    }
}
void motion(int x, int y){
    teapotX += (x - oldX)/150.0;
    teapotY -= (y - oldY)/150.0;
    oldX=x;
    oldY=y;
    glutPostRedisplay();
}
最後面加int main
glutMotionFunc(motion);



















沒有留言:

張貼留言