2023年5月10日 星期三

擦 大哥 week13-綜合練習

 week13-綜合練習

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檔


((關機 漂亮51號機


#include <stdio.h>
#include <GL/glut.h>
#include "glm.h"
GLMmodel * head = NULL;
GLMmodel * body = NULL;
GLMmodel * uparmR = NULL;
GLMmodel * lowarmR = NULL;///Week13-2-1
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();
        ///glTranslatef(teapotX, teapotY, 0);
        ///glTranslatef(????); ///step3-2 
        ///glRotatef(angle, 0, 0, 1);
        ///glTranslatef(0.400000, -0.060000, 0);
        ///glTranslatef(teapotX, teapotY, 0);
        ///glutSolidTeapot( 0.3 );
        if(body==NULL){
            body=glmReadOBJ("model/body.obj");
            glmUnitize(body);
        }
        glmDraw(body,GLM_MATERIAL);
    glPopMatrix();
    glutSwapBuffers();
}
void mouse(int button, int state, int x, int y)
{
    if(state==GLUT_DOWN){
        teapotX = (x-150)/150.0;
        teapotY = (150-y)/150.0;
        angle = x;
        printf("glTranslatef(%f, %f, 0);\n", teapotX, teapotY);
        if(fout==NULL) fout = fopen("file4.txt", "w"); 
        ///fprintf(fout, "%f %f\n", teapotX, teapotY); 
    }
    display();
}
void keyboard(unsigned char key, int x, int y) ///step02-2 keyboard函式
{
    if(fin==NULL){ ///step2-2 如果檔案還沒 fopen(), 就開它
        fclose(fout); ///前面mouse會開fout指標, 所以要關掉
        fin = fopen("file4.txt", "r"); ///step2-2 沒開檔,就開
    }
    ///fscanf(fin, "%f %f", &teapotX, &teapotY); ///step2-2 真的讀檔
    display(); ///step2-2 重畫畫面
}
int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week13");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutKeyboardFunc(keyboard); ///step2-2 keyboard要做事囉(開檔、讀檔)
    glutMainLoop();
}
        teapotY = (150-y)/150.0;
        angle = x;
        printf("glTranslatef(%f, %f, 0);\n", teapotX, teapotY);
        if(fout==NULL) fout = fopen("file4.txt", "w"); ///step02-2 沒開檔,就開
        ///fprintf(fout, "%f %f\n", teapotX, teapotY); ///step02-2 要再存座標
    }
    display();
}
void keyboard(unsigned char key, int x, int y) ///step02-2 keyboard函式
{
    if(fin==NULL){ ///step2-2 如果檔案還沒 fopen(), 就開它
        fclose(fout); ///前面mouse會開fout指標, 所以要關掉
        fin = fopen("file4.txt", "r"); ///step2-2 沒開檔,就開
    }
    ///fscanf(fin, "%f %f", &teapotX, &teapotY); ///step2-2 真的讀檔
    display(); ///step2-2 重畫畫面
}
int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week13");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutKeyboardFunc(keyboard); ///step2-2 keyboard要做事囉(開檔、讀檔)
    glutMainLoop();
}
        teapotY = (150-y)/150.0;

        angle = x;
        printf("glTranslatef(%f, %f, 0);\n", teapotX, teapotY);
        if(fout==NULL) fout = fopen("file4.txt", "w"); ///step02-2 沒開檔,就開
        ///fprintf(fout, "%f %f\n", teapotX, teapotY); ///step02-2 要再存座標
    }
    display();
}
void keyboard(unsigned char key, int x, int y) ///step02-2 keyboard函式
{
    if(fin==NULL){ 

        fclose(fout);
        fin = fopen("file4.txt", "r"); 

}
int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week13");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutKeyboardFunc(keyboard); 
    glutMainLoop();
}



#include <stdio.h>

#include <GL/glut.h>
#include "glm.h"
GLMmodel * head = NULL;
GLMmodel * body = NULL;
GLMmodel * uparmR = NULL;
GLMmodel * lowarmR = NULL;///Week13-2-1
int show[4]={0,1,0,0};///用show[]來決定要不要顯示出來
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; ///一開始,檔案沒有開, NULL
FILE * fin = NULL; ///要讀檔用的指標, 一開始也是 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);///week13-02-2改大小
        if(body==NULL){
            head=glmReadOBJ("model/head.obj");
            body=glmReadOBJ("model/body.obj");///Week13-2-1
            uparmR=glmReadOBJ("model/uparmR.obj");///Week13-3-1
            lowarmR=glmReadOBJ("model/lowarmR.obj");///Week13-3-1
            ///glmUnitize(body);///Week13-2-1這行之後會改
        }
        if (show[0]) glmDraw(head, GLM_MATERIAL);///week13-03-1
        glPushMatrix();
            //
            if (show[1]) glmDraw(body, GLM_MATERIAL);
        glPopMatrix();
        if (show[2]) glmDraw(uparmR, GLM_MATERIAL);///Week13-3-1
        if (show[3]) glmDraw(lowarmR, GLM_MATERIAL);///Week13-3-1
    glPopMatrix();
    glutSwapBuffers();
}
int oldX=0, oldY=0;///week13-03-2
void motion(int x, int y){///week13-03-2
    teapotX += (x -oldX)/150.0;///week13-03-2
    teapotY -= (y -oldY)/150.0;///week13-03-2
    oldX=x;
    oldY=y;
    printf("glTranslatef(%f, %f, 0);\n",teapotX,teapotY);
    glutPostRedisplay();///week13-03-2
}
void mouse(int button, int state, int x, int y)
{
    if(state==GLUT_DOWN){
        oldX = x;///teapotX = (x-150)/150.0;
        oldY = y;///teapotY = (150-y)/150.0;
        angle = x;
        ///printf("glTranslatef(%f, %f, 0);\n", teapotX, teapotY);
        ///if(fout==NULL) fout = fopen("file4.txt", "w"); ///step2-2 沒開檔,就開
        ///fprintf(fout, "%f %f\n", teapotX, teapotY); ///step2-2 要再存座標
    }
    display();
}
///void keyboard(unsigned char key, int x, int y) ///step02-2 keyboard函式
///{
    ///if(fin==NULL){ ///step2-2 如果檔案還沒 fopen(), 就開它
        ///fclose(fout); ///前面mouse會開fout指標, 所以要關掉
        ///fin = fopen("file4.txt", "r"); ///step2-2 沒開檔,就開
   /// }
    ///fscanf(fin, "%f %f", &teapotX, &teapotY); ///step2-2 真的讀檔
    ///display(); ///step2-2 重畫畫面
///}
int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week13");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutKeyboardFunc(keyboard); ///step2-2 keyboard要做事囉(開檔、讀檔)
    glutMainLoop();
}


沒有留言:

張貼留言