Week 13
到Maya把模型分割身體部位,然後把上周的Final Project打開
到project----->到properities----->到右下角的Build Option----->到Search directories把complier跟linker的目錄改成feeeglut\include就好
之後把第十周的glm.h 跟glm .cpp放到目錄下,然後把剛剛裁切的身體obj檔創一個
資料夾也放到目錄下
記得freeglut跟freeglut.dll都要放進專案裡
去把.gitignore裡面的lib 、.a、obj、還有.dll前面加個井號這樣上傳才不會被捨棄掉
之後專案加上glm.cpp就可以了
#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] = {0, 1, 0, 0};/// show[i] 來決定要不要顯示
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; ///step02-2 一開始,檔案沒有開, NULL
FILE * fin = NULL; ///step02-2 要讀檔用的指標, 一開始也是 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_step02-2
if(body==NULL){///week13 step02-1
head = glmReadOBJ("model/head.obj");
body = glmReadOBJ("model/body.obj");///week13 step02-1
uparmR = glmReadOBJ("model/uparmR.obj");///Week13 step03-1
lowarmR = glmReadOBJ("model/lowarmR.obj");///Week13 step03-1
///glmUnitize(body); ///week13 step02-1 這行之後會改
}
glColor3f(1,0,0);
if(show[0]) glmDraw(head, GLM_MATERIAL);///Week13 step03-1
glColor3f(0,1,0);
if(show[1]) glmDraw(body, GLM_MATERIAL);///week13 step02-1這行之後會改
glPushMatrix();
glTranslatef(teapotX, teapotY, 0);
if(show[2]) glmDraw(uparmR, GLM_MATERIAL);///Week13 step03-1
glPopMatrix();
if(show[3]) glmDraw(lowarmR, GLM_MATERIAL);///Week13 step03-1
glPopMatrix();
glutSwapBuffers();
}
int oldX = 0, oldY = 0; ///Week13 step03-2
void motion(int x, int y){ ///Week13 step03-2
teapotX += (x - oldX)/150.0; ///Week13 step03-2
teapotY -= (y - oldY)/150.0; ///Week13 step03-2
oldX = x;
oldY = y;
printf("glTranslatef(%f, %f, 0);\n", teapotX, teapotY);
glutPostRedisplay(); ///Week13 step03-2
} ///Week13 step03-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"); ///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){ ///step02-2 如果檔案還沒 fopen(), 就開它
// fclose(fout); ///前面mouse會開fout指標, 所以要關掉
// fin = fopen("file4.txt", "r"); ///step02-2 沒開檔,就開
// }
// ///fscanf(fin, "%f %f", &teapotX, &teapotY); ///step02-2 真的讀檔
// display(); ///step02-2 重畫畫面
//}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week12");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion); ///Week13 step03-3
glutKeyboardFunc(keyboard); ///step02-2 keyboard要做事囉(開檔、讀檔)
glutMainLoop();
}






沒有留言:
張貼留言