step 01-1
從github下載並開啟舊專案Final_Project
把絕對路徑改成相對路徑
project-properties 右下 project's build
search directories-complier 路徑前面刪掉 只剩free/include
search directories-linker 路徑前面刪掉 只剩free/lib
把設定好的 freeglut資料夾放進 Final_Project目錄裡
執行剛剛開啟的Project,便能順利執行
step 02-1
去 https://jsyeh.org/3dcg10/ 下載 data 用 Maya import
將人物分解成頭、身體、手、腳
再把存好的所有mtl跟obj檔案存到Final Project新增的model資料夾
step3-1
把第10周的glm.h跟glm.cpp複製到Final project的資料夾裡
最左邊按右鍵add file 把glm.cpp加進來
#include <stdio.h>
#include <GL/glut.h>
#include "glm.h"
GLMmodel * head =NULL;
GLMmodel * body =NULL;
GLMmodel * uparmR =NULL;
GLMmodel * LowarmR =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");
uparmR = glmReadOBJ("model/uparmR.obj");
lowarmR = glmReadOBJ("model/lowarmR.obj");
}
glPushMatrix();
glScalef(0.3,0.3 0.3);
glmDraw(head, GLM_MATERIAL);
glmDraw(body, GLM_MATERIAL);
glmDraw(uparmR, GLM_MATERIAL);
glmDraw(LowarmR, 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("week12");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop();
}
程式碼改成:
把模型縮小成 0.3 ,執行後變正常

.png)
.png)
.png)
.png)








沒有留言:
張貼留言