week12
開啟上禮拜的檔案
打開git bash
並cd desktop
git clone
cd2023graphicsb
用codeblocks開啟上禮拜Final Project資料夾
變成相對路徑
在properties中更改設定
按右下角 改Search directories的Compiler和Linker
讓git 馬上備份上傳
把.gitignore用notepad++開啟
.a .lib .dll都註解 並存檔 即可放行
*CodeBlocks 也要存檔
切割模型
打開MAYA並把模型import進來
開始切割
File Export Selection
並存OBJ檔
畫出頭
week13-1
*讀出模型的頭
#include <stdio.h>
#include <GL/glut.h>
#include "glm.h"
GLMmodel * head = NULL;
GLMmodel * body = 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");
glmUnitize(head);
}
glmDraw(head, GLM_MATERIAL);
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();
}
畫出身體
week13-2
*讀出模型的頭與身體
#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/rhandup.obj");
lowarmR = glmReadOBJ("model/rhanddown.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();
}
用鍵盤讓模型出現
week13-3
*鍵盤0123出現不同部位
#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] = {1, 0, 0, 0};
float teapotX = 0, teapotY = 0;
FILE * fout = NULL;
FILE * fin = NULL;
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();
}
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/rhandup.obj");
lowarmR = glmReadOBJ("model/rhanddown.obj");
}
glPushMatrix();
glScalef(0.3, 0.3, 0.3);
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)
{
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();
}
用滑鼠移動頭的位子
week13-4
#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] = {1, 0, 0, 0};
float teapotX = 0, teapotY = 0;
FILE * fout = NULL;
FILE * fin = NULL;
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();
}
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/rhandup.obj");
lowarmR = glmReadOBJ("model/rhanddown.obj");
}
glPushMatrix();
glScalef(0.3, 0.3, 0.3);
glPushMatrix();
glTranslatef(teapotX, teapotY, 0);
if(show[0])glmDraw(head, GLM_MATERIAL);
glPopMatrix();
if(show[1])glmDraw(body, GLM_MATERIAL);
if(show[2])glmDraw(uparmR, GLM_MATERIAL);
if(show[3])glmDraw(lowarmR, GLM_MATERIAL);
glPopMatrix();
glutSwapBuffers();
}
int oldX=0, oldY=0;
void mouse(int button, int state, int x, int y)
{
if(state==GLUT_DOWN){
oldX = x;
oldY = y;
}
}
void motion(int x, int y){
teapotX += (x-oldX)/150.0;
teapotY -= (y-oldY)/150.0;
oldX = x;
oldY = y;
glutPostRedisplay();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week12");
glutMotionFunc(motion);
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop();
}











沒有留言:
張貼留言