開啟maya / 裁切模型
去到https://jsyeh.org/3dcg10/
下載 1.[data] 2.[win32] 兩個檔案 並且解壓縮win32
將data丟進解壓縮後的windows 找到al.obj檔案 匯入maya(file / import)
將模型檔案打開後 / 裁切(選取)他的身體 / 分別匯出(file / export selection)
1.head.obj 2.body.obj 3.uparmR.obj 4.lowarmR.obj
下載git指令 開啟git bash
步驟如下:1.cd desktop 2.git clone https://github.com/你的帳號/2023graphicsa3.cd 2023graphicsa 4.start .
去到codeblocks開舊專案 file-open 點選fianl project 的 project.cbp
把freeglut目錄解壓縮在我們fianl project 裡頭
記得要將裡頭lib的libfreeglut.a複製並貼上將複製的改檔名為libglut32.a
File - Open - 檔案.cbp 開啟檔案
開啟檔案 在檔案上按右鍵
點選edit 更改路徑 freeglut\include
點選edit 更改路徑 freeglut\lib
去到2023graphicsa資料夾內找到gitignore檔案 按右鍵 開啟notepad++
找到.a .lib在前方加#
去到Final Project 裡的freeglut / bin 的.dll檔複製
去到第10週 將glm.cpp glm.h檔案複製到Final Project專案裡
點選專案按右鍵 Add File 把glm.cpp加進去
File -Save- everything 才會存檔 不然會備份到(還沒存檔的舊黨內)
把剛剛裁切好的模型複製到Final Project專案裡頭 新增的model資料夾
第一個程式(粉紅色是更改位置)
///要用keyboard mouse來控制茶壺,可存檔,可自己動
#include <stdio.h>
#include <GL/glut.h>
#include "glm.h"
GLMmodel * head =NULL;///week13 step02-1
GLMmodel * body =NULL;
GLMmodel * uparmR =NULL;
GLMmodel * lowarmR =NULL;
FILE * fout = NULL;///一開始,檔案沒有開 NULL
FILE * fin = NULL;///要讀檔用的指標,一開始也是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();
///glTranslatef(teapotX,teapotY,0);
///glutSolidTeapot(0.3);
if(body==NULL)
{
body=glmReadOBJ("model/body.obj");
glmUnitize(body);///這之後還會更改
}
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)///如果檔案還沒fopen(),就開它
{
fclose(fout);///要關掉前面mouse開的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("week13");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard);///keyboard要開檔,讀檔
glutMainLoop();
}
開啟身體的模型
第一個程式版本2(顏色是有更改的位置)
///要用keyboard mouse來控制茶壺,可存檔,可自己動
#include <stdio.h>
#include <GL/glut.h>
#include "glm.h"
GLMmodel * head =NULL;///week13 step02-1
GLMmodel * body =NULL;
GLMmodel * uparmR =NULL;
GLMmodel * lowarmR =NULL;
FILE * fout = NULL;///一開始,檔案沒有開 NULL
FILE * fin = NULL;///要讀檔用的指標,一開始也是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");
///glmUnitize(body);///這之後還會更改註解掉
}
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)///如果檔案還沒fopen(),就開它
{
fclose(fout);///要關掉前面mouse開的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("week13");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard);///keyboard要開檔,讀檔
glutMainLoop();
}
開啟頭和身體的模型
第一個程式版本3(顏色是有更改的位置)
///要用keyboard mouse來控制茶壺,可存檔,可自己動
#include <stdio.h>
#include <GL/glut.h>
#include "glm.h"
GLMmodel * head =NULL;///week13 step02-1
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];///!是將1變0,0變1
if(key=='1') show[1] = !show[1];
if(key=='2') show[2] = !show[2];
if(key=='3') show[3] = !show[3];
glutPostRedisplay();
}///將原本的keyboard函式先註解掉
FILE * fout = NULL;///一開始,檔案沒有開 NULL
FILE * fin = NULL;///要讀檔用的指標,一開始也是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");
uparmR=glmReadOBJ("model/uparmR.obj");
lowarmR=glmReadOBJ("model/lowarmR.obj");
///glmUnitize(body);///這之後還會更改
}
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();
}
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)///如果檔案還沒fopen(),就開它
// {
// fclose(fout);///要關掉前面mouse開的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("week13");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard);///keyboard要開檔,讀檔
glutMainLoop();
}
p.s ///如何全部註解 選取要註解掉的地方 edit - comment
第一個程式版本4(顏色是有更改的位置)
///要用keyboard mouse來控制茶壺,可存檔,可自己動
#include <stdio.h>
#include <GL/glut.h>
#include "glm.h"
GLMmodel * head =NULL;///week13 step02-1
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];///!是將1變0,0變1
if(key=='1') show[1] = !show[1];
if(key=='2') show[2] = !show[2];
if(key=='3') show[3] = !show[3];
glutPostRedisplay();
}///將原本的keyboard函式先註解掉
FILE * fout = NULL;///一開始,檔案沒有開 NULL
FILE * fin = NULL;///要讀檔用的指標,一開始也是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");
uparmR=glmReadOBJ("model/uparmR.obj");
lowarmR=glmReadOBJ("model/lowarmR.obj");
///glmUnitize(body);///這之後還會更改
}
if(show[0]) glmDraw(head,GLM_MATERIAL);
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;///teapotX = (x-150)/150.0;
oldY = y;///teapotY = (150-y)/150.0;
angle = x;
///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)///如果檔案還沒fopen(),就開它
// {
// fclose(fout);///要關掉前面mouse開的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("week13");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutKeyboardFunc(keyboard);///keyboard要開檔,讀檔
glutMainLoop();
}
可以移動右上手臂 可以移動它到中心點 並且可以得知位置
去到gitignore檔案內 用notepad++ 將obj註解掉 因為我們要備份obj模型 並儲存





















沒有留言:
張貼留言