week13-1_glm_gundam_keyboard_angleID_mouse_motion_angle
先安裝openCV,CodeBlocks要重開
要改環境Search directories->Compiler 增加 C:\OpenCV2.1\include
Search directories->Linker 增加 C:\OpenCV2.1\lib
Linker settings-> 增加 cv210、cxcore210、highgui210
載git hub把第12周的12-3 抓下來就可以了
float angle[20] = {};///20個角度,都設成0
int angleID = 0; ///可以是角度0,角度1,角度2
void motion(int x,int y){ ///加入 mouse motion 對應的
angle[angleID] = y;///當我們的 mouse motion 時
glutPostRedisplay();///要重畫畫面
}
void motion(int x,int y){ ///加入 mouse motion 對應的函式
angle[angleID] += y-oldy;///當我們的 mouse motion 時,y座標
oldx=x;///y-oldy;加上移動多少
oldy=y;
glutPostRedisplay();///要重畫畫面
}
void mouse(int button , int state, int x,int y){
oldx=x;
oldy=y;
}
void keyboard(unsigned char key,int x,int y){
if(key == '0') angleID = 0;
if(key == '1') angleID = 1;
if(key == '2') angleID = 2;
if(key == '3') angleID = 3;
}
week13-2_FILE_fopen_faprintf_fscanf
把week13-1複製到week13-2
#include <stdio.h>
FILE * fin = NULL;
FILE * fout = NULL;
void motion(int x,int y){ ///加入 mouse motion 對應的函式
angle[angleID] += y - oldy;
oldx = x;
oldy = y;
glutPostRedisplay();
if(fout==NULL) fout = fopen("angle.txt","w+");
for(int i=0; i<20; i++){
printf("%.1f ",angle[i]); ///顯示座標的位置
fprintf(fout," %.1f ",angle[i]);///要記的加空格不然會壞掉
}
printf("\n");
fprintf(fout,"\n");
}
if(key == 'r'){
if(fin==NULL) fin=fopen("angle.txt","r");
for(int i=0; i<20; i++){
fscanf(fin,"%f",&angle[i]);
}
glutPostRedisplay();
}
glPushMatrix();
glRotatef(angle[0],0,1,0);
glRotatef(180,0,1,0);///轉成正面
drawbody();///畫身體
glPopMatrix();
///glutSolidSphere(0.1,30,30);
glEnable(GL_TEXTURE_2D);///再把貼圖功能開起來,才能draw
glColor3f(1,1,1);
glPushMatrix();
glTranslatef(-0.1,0,0);
glRotatef(angle[1],0,0,1);
glRotatef(angle[2],1,0,0);
glTranslatef(0,-0.07,0);
drawUpperA();///(3)上手臂放好
glPushMatrix(); ///(0)
glTranslatef(-0.02,-0.09,0);///(3)再掛到上手臂的位置
glRotatef(angle[3],1,0,0);///(2) x軸轉
glTranslatef(0,-0.21,0);///(1)
drawLowerA(); ///(0)
glPopMatrix(); ///(0)
glPopMatrix();



沒有留言:
張貼留言