2023年5月11日 星期四

劉 電腦圖學

 week12 

第一堂課

下載 git bash
先輸入 cd desktop(設定桌面路徑)


再輸入https://github.com/wayne00182/2023graphicsa





開啟 Final_project




更改code block 的目錄


將freeglut加進去Final_project的資料夾

執行程式



開啟gitgnore ==>用notepad++

在*.a和*.lib前面加上#

  

第二堂課

開啟MAYA



將模型拆解並在Final_project建立資料夾model

將8-1的檔案也加進去


將glm.cpp 加進去


加入程式碼
#include "glm.h"

GLMmodel * head = NULL;
GLMmodel * body = NULL;















第三堂課





程式碼==>還需要修改
#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] = (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];
     glutPostRedidplay();
}
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    if(head==NULL){
        head= glmReadOBJ("model/head.obj");
        body = glmReadOBJ("model/body.obj")
        glmUnitize(head);
    }
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(uparmR, GLM_MATERIAL);
    if(show[3]) glmDraw(lowarmR, 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-oldx)/150.0;
    teapotY = (y-oldy)/150.0;
    oldX = x;
    oldY = y;
    glutPostRedisplay();
    }
///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");

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

   glutMainLoop();
}




沒有留言:

張貼留言