Week13 (補)
1 - 開啟Maya,將al.obj模型拉進場景,分別選取頭、身、手、腳
2 - 點選File ➝ Export Selection ➝ Desktop ➝ Cancel用小黑把程式庫抓到桌面
開啟上星期的final_Project將week10的glm.cpp和glm.h丟進去
freeglut也丟進去(還是要改32)
建一個資料夾把其中四個部分的模型丟進去
最後 修改main.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};
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;
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){///week13 step02-1
head = glmReadOBJ("model/head.obj");
body = glmReadOBJ("model/body.obj");
uparmR = glmReadOBJ("model/uparmR.obj");
lowarmR = glmReadOBJ("model/lowarmR.obj");
}
glColor3f(1,0,0);
if(show[0]) glmDraw(head, GLM_MATERIAL);
glColor3f(0,1,0);
if(show[1]) glmDraw(body, GLM_MATERIAL);
glPushMatrix();
glTranslatef(teapotX, teapotY, 0);
if(show[2]) glmDraw(uparmR, GLM_MATERIAL);
glPopMatrix();
if(show[3]) glmDraw(lowarmR, 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);
glutPostRedisplay();
}
void mouse(int button, int state, int x, int y)
{
if(state==GLUT_DOWN){
oldX = x;
oldY = y;
angle = x;
}
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();
}
沒有留言:
張貼留言