2023年5月10日 星期三

chiche_week13

 Week13

step01



開啟連結 https://jsyeh.org/3dcg10/

下載檔案model_obj


step02

開啟maya,匯入模型obj檔


step03


選取頭部,匯出


step04

上傳檔案git指令

1. git指令
2. cd desktop
3. git clone https://github.com/你的帳號/2023graphicsa
4. cd 2023graphicsa
5. start .

step05

複製freeglut 資料夾到github/2023graphicsa/final_project 裡

step06


開啟檔案final_project.cbp


step07

修改.gitignore 26/27行 加#

step08




修改路徑


執行成功

step09

新增model 資料夾到 github/2023graphicsa/final_project 裡

把剛剛maya裁切的模型放入資料夾

step10

複製week10 檔案到github/2023graphicsa/final_project 裡

step11



step12

save everything

step13

程式碼:

#include <stdio.h>
#include <GL/glut.h>
#include "glm.h"
GLMmodel * head = NULL;
GLMmodel * body = NULL;
GLMmodel * uparmR = NULL;
GLMmodel * lowarmR = NULL;


FILE * fout = NULL;
FILE * fin = NULL;
float teapotX=0 , teapotY=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        //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;
        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)
{
    if (fin==NULL)
    {
        fclose(fout);
        fin = fopen("file4.txt","r");
    }
    fscanf(fin,"%f %f",&teapotX , &teapotY);
    display();
}
int main(int argc,char** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week12");

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

    glutMainLoop();
}

step14

程式碼:

#include <stdio.h>
#include <GL/glut.h>
#include "glm.h"
GLMmodel * head = NULL;
GLMmodel * body = NULL;
GLMmodel * ass = NULL;
GLMmodel * uparmR = NULL;
GLMmodel * lowarmR = NULL;


FILE * fout = NULL;
FILE * fin = NULL;
float teapotX=0 , teapotY=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glScalef(0.2,0.2,0.2);
        if(body==NULL){
            body = glmReadOBJ("model/body.obj");
            head = glmReadOBJ("model/head.obj");
            ass = glmReadOBJ("model/ass.obj");
            //glmUnitize(body);
        }
        glmDraw(body, GLM_MATERIAL);
        glmDraw(head, GLM_MATERIAL);
        glmDraw(ass, 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;
        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)
{
    if (fin==NULL)
    {
        fclose(fout);
        fin = fopen("file4.txt","r");
    }
    fscanf(fin,"%f %f",&teapotX , &teapotY);
    display();
}
int main(int argc,char** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week12");

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

    glutMainLoop();
}
執行成果

step15

程式碼:

#include <stdio.h>
#include <GL/glut.h>
#include "glm.h"
GLMmodel * head = NULL;
GLMmodel * body = NULL;
GLMmodel * ass = NULL;
GLMmodel * uparmR = NULL;
GLMmodel * armR = NULL;
GLMmodel * uparmL = NULL;
GLMmodel * armL = NULL;
int show[7] = {0,1,0,0,0,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];
    if(key=='4') show[4] = !show[4];
    if(key=='5') show[5] = !show[5];
    if(key=='6') show[6] = !show[6];
    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){
            body = glmReadOBJ("model/body.obj");
            head = glmReadOBJ("model/head.obj");
            ass = glmReadOBJ("model/ass.obj");
            uparmR = glmReadOBJ("model/uparmR.obj");
            armR = glmReadOBJ("model/armR.obj");
            uparmL = glmReadOBJ("model/uparmL.obj");
            armL = glmReadOBJ("model/armL.obj");
            //glmUnitize(body);
        }
        if (show[0]) glmDraw(body, GLM_MATERIAL);
        if (show[1]) glmDraw(head, GLM_MATERIAL);
        glPushMatrix();
            glTranslatef(teapotX,teapotY,0);
            if (show[2]) glmDraw(ass, GLM_MATERIAL);
        glPopMatrix();
        if (show[3]) glmDraw(uparmR, GLM_MATERIAL);
        if (show[4]) glmDraw(armR, GLM_MATERIAL);
        if (show[5]) glmDraw(uparmL, GLM_MATERIAL);
        if (show[6]) glmDraw(armL, 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);
}

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;
        ///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)
//{
//    if (fin==NULL)
//    {
//        fclose(fout);
//        fin = fopen("file4.txt","r");
//    }
//    fscanf(fin,"%f %f",&teapotX , &teapotY);
//    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();
}
執行成果


#include <stdio.h>
#include <GL/glut.h>
#include "glm.h"
GLMmodel * head = NULL;
GLMmodel * body = NULL;
GLMmodel * ass = NULL;
GLMmodel * uparmR = NULL;
GLMmodel * armR = NULL;
int show[5] = {0,0,0,0,1}; ///show[1]來決定要不要顯示
int ID = 4;
void keyboard(unsigned char key,int x,int y)
{
    if(key=='0') ID = 0;
    if(key=='1') ID = 1;
    if(key=='2') ID = 2;
    if(key=='3') ID = 3;
    if(key=='4') ID = 4;
    ///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];
    ///if(key=='4') show[4] = !show[4];
    glutPostRedisplay();
}
FILE * fout = NULL;
FILE * fin = NULL;
float angle=0;
float teapotX=0 , teapotY=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glScalef(0.2,0.2,0.2);
        if(body==NULL){
            head = glmReadOBJ("model/head.obj");
            body = glmReadOBJ("model/body.obj");
            ass = glmReadOBJ("model/ass.obj");
            uparmR = glmReadOBJ("model/uparmR.obj");
            armR = glmReadOBJ("model/armR.obj");
        }
        if (ID==0) glColor3f(1,0,0);
        else glColor3f(1,1,1);
        if (show[0]) glmDraw(head, GLM_MATERIAL);

        if (ID==1) glColor3f(1,0,0);
        else glColor3f(1,1,1);
        if (show[1]) glmDraw(body, GLM_MATERIAL);

        glPushMatrix();///屁股
            ///glTranslatef(-0.013333, 0.646666, 0);
            glRotatef(angle, 0, 0, 1);
            glTranslatef(0.013333, -0.646666, 0);
            ///glTranslatef(teapotX,-teapotY,0);
            ///glTranslatef(teapotX,teapotY,0);

            if (ID==2) glColor3f(1,0,0);
            else glColor3f(1,1,1);
            if (show[2]) glmDraw(ass, GLM_MATERIAL);
        glPopMatrix();

            if (ID==3) glColor3f(1,0,0);
            else glColor3f(1,1,1);
            if (show[3]) glmDraw(uparmR, GLM_MATERIAL);

        glPushMatrix(); ///下手臂
            glTranslatef(-1.946665, +0.120001, 0);
            glRotatef(angle, 0, 0, 1);
            glTranslatef(1.946665, -0.120001, 0);
            ///glTranslatef(teapotX,teapotY,0);
            if (ID==4) glColor3f(1,0,0);
            else glColor3f(1,1,1);
            if (show[4]) glmDraw(armR, GLM_MATERIAL);
        glPopMatrix();

    glPopMatrix();
    glColor3f(0, 1, 0);
    glutSolidTeapot(0.02);
    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;
    angle = x;
    printf("glTranslatef(%f, %f, 0);\n",teapotX,teapotY);
    glutPostRedisplay();
}
void mouse(int button,int state,int x,int y)
{
    if(state==GLUT_DOWN)
    {
        teapotX = (x-150)/150.0;
        teapotY = (150-y)/150.0;
        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)
//{
//    if (fin==NULL)
//    {
//        fclose(fout);
//        fin = fopen("file4.txt","r");
//    }
//    fscanf(fin,"%f %f",&teapotX , &teapotY);
//    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();
}


step16

上傳檔案git指令

1. git指令
2. cd desktop
3. git clone https://github.com/chiche/2023graphicsa
4. cd 2023graphicsa
5. start .
6. git add . 
7. git status

8. git config --global user.email "liao2013823@gmail.com"

9. git config --global user.name "chiche0306"

10. git commit -m "week13"

11. git push





沒有留言:

張貼留言