1.https://jsyeh.org/3dcg10/
下載data 裡面有模型
裁切身體部位 頭,右手,左手,身體
-Alt-左健: 旋轉
-Alt-中健: 平移
-滾輸: 縮放
-左鍵: 選取
-File-Import 匯入模型
-File-Export Selection 匯出模型
開final project
Project-Properties-Project build option-Search directioies-freeglut\include
修改程式碼
#include <stdio.h>
#include <GL/glut.h>
#include "glm.h"
GLMmodel * head = NULL;
GLMmodel * body = NULL;
GLMmodel * uparmR = NULL;
GLMmodel * lowarmR = NULL;
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){
head = glmReadOBJ("model/head.obj");
body = glmReadOBJ("model/body.obj");
}
glmDraw(head, GLM_MATERIAL);
glmDraw(body, GLM_MATERIAL);
glPopMatrix();
glutSwapBuffers();
}
void mouse(int button,int state,int x,int y)
{
if(state==GLUT_DOWN){
teapotX=(x-150)/150.0;
teapotY=(150-y)/150.0;
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);
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
#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];
gluPostRedisplay();
}
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){
head = glmReadOBJ("model/head.obj");
body = glmReadOBJ("model/body.obj");
}
glmDraw(head, GLM_MATERIAL);
glmDraw(body, GLM_MATERIAL);
glPopMatrix();
glutSwapBuffers();
}
int oldX = 0, oldY = 0;
void motion(int x, int y){
teapotX += (x-oldx)/150.0;
teapotX -= (x-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();
}
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);
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard);
glutMainLoop();
}


沒有留言:
張貼留言