又到了選擇模型的時刻 找個卡比來玩玩好了
第一節課
打開maya
將老師傳的模型丟進去
把頭、身體、手腳等部位拆解另存成obj檔
開啟上星期的final_Project
把glm.cpp新增進去
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);
///glTranslatef(????); ///step03-2 擺動作
///glRotatef(angle, 0, 0, 1);///擺動作
///glTranslatef(0.400000, -0.060000, 0);///擺動作
///glTranslatef(teapotX, teapotY, 0);
///glutSolidTeapot( 0.3 );
if(body==NULL){
body=glmReadOBJ("model/body.obj");
glmUnitize(body);///week13-02-1這行之後會改
}
glmDraw(body,GLM_MATERIAL);///week13-02-1這行之後會改
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;
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("week13");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard); ///step02-2 keyboard要做事囉(開檔、讀檔)
glutMainLoop();
}
將week10的glm.cpp和glm.h丟進去
freeglut也丟進去(還是要改32)
建一個資料夾把其中四個部分的模型丟進去
排版出問題了 擊敗
算了
程式碼:
#include <stdio.h>
#include <GL/glut.h>
#include "glm.h"
GLMmodel * head = NULL;
GLMmodel * body = NULL;
GLMmodel * uparmR = NULL;
GLMmodel * lowarmR = NULL;///week13-02-1
#include <GL/glut.h>
#include "glm.h"
GLMmodel * head = NULL;
GLMmodel * body = NULL;
GLMmodel * uparmR = NULL;
GLMmodel * lowarmR = NULL;///week13-02-1
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);
///glTranslatef(????); ///step03-2 擺動作
///glRotatef(angle, 0, 0, 1);///擺動作
///glTranslatef(0.400000, -0.060000, 0);///擺動作
///glTranslatef(teapotX, teapotY, 0);
///glutSolidTeapot( 0.3 );
if(body==NULL){
body=glmReadOBJ("model/body.obj");
glmUnitize(body);///week13-02-1這行之後會改
}
glmDraw(body,GLM_MATERIAL);///week13-02-1這行之後會改
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;
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("week13");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard); ///step02-2 keyboard要做事囉(開檔、讀檔)
glutMainLoop();
}
#include <stdio.h>
#include <GL/glut.h>
#include "glm.h"
GLMmodel * head = NULL;
GLMmodel * body = NULL;
GLMmodel * uparmR = NULL;
GLMmodel * lowarmR = NULL;///week13-02-1
int show[4]={0,1,0,0};///用show[]來決定要不要顯示出來
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; ///一開始,檔案沒有開, 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);///week13-02-2改大小
if(body==NULL){
head=glmReadOBJ("model/head.obj");
body=glmReadOBJ("model/body.obj");///week13-02-1
uparmR=glmReadOBJ("model/uparmR.obj");///week13-03-1
lowarmR=glmReadOBJ("model/lowarmR.obj");///week13-03-1
///glmUnitize(body);///week13-02-1這行之後會改
}
if (show[0]) glmDraw(head, GLM_MATERIAL);///week13-03-1
glPushMatrix();
//
if (show[1]) glmDraw(body, GLM_MATERIAL);
glPopMatrix();
if (show[2]) glmDraw(uparmR, GLM_MATERIAL);///week13-03-1
if (show[3]) glmDraw(lowarmR, GLM_MATERIAL);///week13-03-1
glPopMatrix();
glutSwapBuffers();
}
int oldX=0, oldY=0;///week13-03-2
void motion(int x, int y){///week13-03-2
teapotX += (x -oldX)/150.0;///week13-03-2
teapotY -= (y -oldY)/150.0;///week13-03-2
oldX=x;
oldY=y;
printf("glTranslatef(%f, %f, 0);\n",teapotX,teapotY);
glutPostRedisplay();///week13-03-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("week13");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutKeyboardFunc(keyboard); ///step02-2 keyboard要做事囉(開檔、讀檔)
glutMainLoop();
}
由於排版出不來 感覺整個亂掉 所以有夠不爽 不寫了ˋˊ 總之就是各個模型找旋轉點的東東
沒有留言:
張貼留言