安裝git指令,clone資料庫。
解壓縮資料庫的Final_Project,找到freeglut.dll檔案。
相對位置設置說明:
打開codeblocks,final_project打開再到project -->properties
project setting-->project build option-->search direction
compiler修改-->左邊刪掉改成freeglut\include
linker修改-->左邊刪掉改成freeglut\lib
最後再把freeglut拉近final_project的 資料夾。
結果
修改github資料庫的.gitignore並註解放行#*dll #*a #*lib再儲存修改結果。
指令重新上傳githhub。
week13-1:
打開maya,import al.obj
分解五個軀幹,頭部、身體、右上手臂、右下手臂、左上手臂、左下手臂、上下腿。
複製貼上week08-2的2個glm檔案,到final裡面codeblocks開啟final.cbp-->add file glm.cpp
step02-2程式碼:#include <stdio.h>
#include <GL/glut.h>
#include "glm.h"
GLMmodel*head=NULL;
GLMmodel*body=NULL;
GLMmodel*uphandr=NULL;
GLMmodel*downhandr=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");
uphandr=glmReadOBJ("model/uphandr.obj");
downhandr=glmReadOBJ("model/downhandr.obj");
}
glPushMatrix();
glScalef(0.3,0.3,0.3);
glmDraw(head,GLM_MATERIAL);
glmDraw(body,GLM_MATERIAL);
glmDraw(uphandr,GLM_MATERIAL);
glmDraw(downhandr,GLM_MATERIAL);
glPopMatrix();
glutSwapBuffers();
}
step03-1程式碼:
#include <stdio.h>
#include <GL/glut.h>
#include "glm.h"
GLMmodel*head=NULL;
GLMmodel*body=NULL;
GLMmodel*uphandr=NULL;
GLMmodel*downhandr=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");
uphandr=glmReadOBJ("model/uphandr.obj");
downhandr=glmReadOBJ("model/downhandr.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(uphandr,GLM_MATERIAL);
if(show[3]) glmDraw(downhandr,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();
}
step03-2程式碼:
#include <stdio.h>
#include <GL/glut.h>
#include "glm.h"
GLMmodel*head=NULL;
GLMmodel*body=NULL;
GLMmodel*uphandr=NULL;
GLMmodel*downhandr=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");
uphandr=glmReadOBJ("model/uphandr.obj");
downhandr=glmReadOBJ("model/downhandr.obj");
}
glPushMatrix();
glTranslatef(teapotX,teapotY,0);
glScalef(0.3,0.3,0.3);
if(show[0]) glmDraw(head,GLM_MATERIAL);
glPopMatrix();
if(show[1]) glmDraw(body,GLM_MATERIAL);
if(show[2]) glmDraw(uphandr,GLM_MATERIAL);
if(show[3]) glmDraw(downhandr,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();
}
滑鼠移動物件:
全部上傳github













沒有留言:
張貼留言