2023年5月11日 星期四

幫我想周末可以幹嘛,快點!week13

 week13

step01-1

先裝git在桌面的2022葉正聖老師上課軟體

複製倉庫
cd desktop 進入桌面
git clone 複製你的檔案
cd 進入你的檔案
start . 開啟檔案資料夾

打開codeblock開啟上週的Final_Project裡的Final_Project.cbp


把freeglut丟進Final_Project
再複製libfreeglut.a改成libglut32.a


註解掉 .lib和.a 在前面打#
送到github裡
git add . 加入你的檔案
git status 確認你的檔案
git config --global user.email "你的Gmail"
git config --global user.name "你的GitHubID"
git commit -m "你的周次"
git push 上傳

step02-1

打開maya

匯入檔案
丟進model裡
把week08-1的glm.cpp和glm.h丟進Final_Project
示範

上半身
#include <stdio.h>
#include <GL/glut.h>
#include "glm.h"
GLMmodel * head = NULL;
GLMmodel * body = NULL;
GLMmodel * lhand = NULL;
GLMmodel * rhand = NULL;


float teapotX=0,teapotY=0;
FILE * fout =NULL;
FILE * fin =NULL;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    if(head==NULL){
        head = glmReadOBJ("model/head.obj");
        body = glmReadOBJ("model/body.obj");
        lhand = glmReadOBJ("model/lhand.obj");
        rhand = glmReadOBJ("model/rhand.obj");
    }
    glPushMatrix();
        glScaled(0.3,0.3,0.3);
        glmDraw(head, GLM_MATERIAL);
        glmDraw(body, GLM_MATERIAL);
        glmDraw(lhand, GLM_MATERIAL);
        glmDraw(rhand, GLM_MATERIAL);
    glPopMatrix();
    glutSwapBuffers();
}
void  mouse(int button,int state,int x,int y)
{
    teapotX=(x-150)/150.0;
    teapotY=(150-y)/150.0;
    if(state==GLUT_DOWN){
        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("week13");

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

    glutMainLoop();
}
消失術
#include <stdio.h>
#include <GL/glut.h>
#include "glm.h"
GLMmodel * head = NULL;
GLMmodel * body = NULL;
GLMmodel * lhand = NULL;
GLMmodel * rhand = NULL;
int show[4]={1,0,0,0};


float teapotX=0,teapotY=0;
FILE * fout =NULL;
FILE * fin =NULL;
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();
}
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    if(head==NULL){
        head = glmReadOBJ("model/head.obj");
        body = glmReadOBJ("model/body.obj");
        lhand = glmReadOBJ("model/lhand.obj");
        rhand = glmReadOBJ("model/rhand.obj");
    }
    glPushMatrix();
        glScaled(0.3,0.3,0.3);
      if(show[0])  glmDraw(head, GLM_MATERIAL);
      if(show[1])  glmDraw(body, GLM_MATERIAL);
      if(show[2]) glmDraw(lhand, GLM_MATERIAL);
      if(show[3]) glmDraw(rhand, GLM_MATERIAL);
    glPopMatrix();
    glutSwapBuffers();
}
void  mouse(int button,int state,int x,int y)
{
    teapotX=(x-150)/150.0;
    teapotY=(150-y)/150.0;
    if(state==GLUT_DOWN){
        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("week13");

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

    glutMainLoop();
}

step03-1

上傳github做備份當個乖寶寶

移動的部分
#include <stdio.h>
#include <GL/glut.h>
#include "glm.h"
GLMmodel * head = NULL;
GLMmodel * body = NULL;
GLMmodel * lhand = NULL;
GLMmodel * rhand = NULL;
int show[4]={1,0,0,0};


float teapotX=0,teapotY=0;
FILE * fout =NULL;
FILE * fin =NULL;
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();
}
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    if(head==NULL){
        head = glmReadOBJ("model/head.obj");
        body = glmReadOBJ("model/body.obj");
        lhand = glmReadOBJ("model/lhand.obj");
        rhand = glmReadOBJ("model/rhand.obj");
    }
    glPushMatrix();
        glScaled(0.3,0.3,0.3);
    glPushMatrix();
      glTranslatef(teapotX,teapotY,0);
      if(show[0])  glmDraw(head, GLM_MATERIAL);
    glPopMatrix();
      if(show[1])  glmDraw(body, GLM_MATERIAL);
      if(show[2]) glmDraw(lhand, GLM_MATERIAL);
      if(show[3]) glmDraw(rhand, GLM_MATERIAL);
    glPopMatrix();
    glutSwapBuffers();
}
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-150)/150.0;
     teapotY=(150-y)/150.0;
     oldX=x;
     oldY=y;
     glutPostRedisplay();
}
int main(int argc,char** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week13");

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

    glutMainLoop();
}
最後的備份以及上傳到github

step03-2

上傳github
cd desktop
git clone https://github.com/帳號/2023graphicsb
cd 2023graphicsb
git status(紅色)
git add .
git status(綠色)
git config --global user.email 帳號
git config --global user.name 名子
git commit -m "週次"
git push

沒有留言:

張貼留言