WEEK15
week15-1 攝影機
調整方向 視角 並使用攝影機
去jsyeh.org下載wundows~data.zip 執行projection.exe
eye center會決定攝影機主線 角度的話靠up
week1-2
glutLookAt()的last後三個參數是up向量
eye center會決定攝影機輔助
eye射向center 要攝影機照著軸線再360度旋轉 由up向量決定 有9個參數即可決定攝影機的拍攝方式
week1-3
ginPerspective參數是縮寫 (fov=field of viesw) (fovy有y方向的fov)
fov角度越大 東西越小
aspeo aspect ratio長寬比
長寬取決aspect的值
zNear zFsr->z方向近遠各切一刀 決定他投影到哪個方塊
fovy:field of view(y方向視野的角度)
aspect:aspect ratio長寬比
week2-1
gluPerspective()參數 從glut專案找 有resize()寒士裡面有glFrustum()函式來設左右上下左右前後邊界 成透視投影的矩陣
開glut專案 用git把github倉庫clone複製 所以2023graphicsa已有freeglut可以用
week2-2
glMatrixMode(GL_PROJECTION);
glOrtho(-ar*3, ar*3, -1*3, 1*3, -100, +100)=>把frustum註解,去執行之後視角會更正面
cd desktop
git clone http://github.com/yang91127/2023graphicsa
cd 2023graphicsa
start.
git status
git add
git
git clone
--user.name yang91127
--user,.email 10160916@ms1.mcu.edu.tw
git push
week15-3
切換不同的關節和角度
int angle[20] angle[0] angle[1]用這些來旋轉
motion() angle[ID]來改
TRT_keyboard_mouse要用keyboard_mouse來操作
原來的keyboard註解先不用 一開始的檔案沒有NULL
WEEK15-3-2
讓原來的eyboard先註解 擺不同動作
FILE*fout=NULL;
FILE*fin=NULL;
float teapotX=0,teapotY=0;
float angle[20]={}; 變成陣列
void display();
總程式:
| #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,1,1,1};///用show[i] 來決定要不要顯示 | |
| int ID=3;///0:頭 1:身體 2:上手臂 3:下手臂 | |
| FILE * fout = NULL;///一開始檔案沒有開,NULL | |
| FILE * fin = NULL;///要讀檔案用的指標,一開始也是NULL | |
| float teapotX=0,teapotY=0; | |
| ///float angle=0,angle2=0,angle3=0; | |
| float angle[20] = {}; | |
| ///NULL空指標 | |
| void keyboard(unsigned char key,int x,int y) | |
| { | |
| if(key=='0') ID=0; | |
| if(key=='1') ID=1; | |
| if(key=='2') ID=2; | |
| if(key=='3') ID=3; | |
| if(key=='s'){ | |
| if(fout==NULL) fout = fopen("motion.txt","w"); | |
| for(int i=0;i<20;i++){ | |
| fprintf(fout,"%.2f ",angle[i]); | |
| } | |
| fprintf(fout,"\n"); | |
| }else if(key=='r'){ | |
| if(fin==NULL) fin = fopen("motion.txt","r"); | |
| for(int i=0;i<20;i++){ | |
| fscanf(fin,"%f",&angle[i]); | |
| } | |
| glutPostRedisplay(); | |
| } | |
| glutPostRedisplay(); | |
| } | |
| 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"); | |
| } | |
| if(ID==0) glColor3f(1,0,0);///選定的,設紅色 | |
| else glColor3f(1,1,1);///沒選定的,設白色 | |
| if(show[0]) glmDraw(head,GLM_MATERIAL); | |
| if(ID==1) glColor3f(1,0,0); | |
| else glColor3f(1,1,1); | |
| if(show[1]) glmDraw(body,GLM_MATERIAL); | |
| glPushMatrix(); | |
| glTranslatef(-1.366666,+0.573333,0);///建立T-R-T | |
| glRotatef(angle[2],0,0,1);///建立T-R-T | |
| glTranslatef(1.366666,-0.573333,0);///建立T-R-T | |
| if(ID==2) glColor3f(1,0,0); | |
| else glColor3f(1,1,1); | |
| if(show[2]) glmDraw(uparmR,GLM_MATERIAL); | |
| glPushMatrix(); | |
| glTranslatef(-1.999999,+0.073333,0); | |
| glRotatef(angle[3],0,0,1); | |
| glTranslatef(1.999999,-0.073333,0); | |
| if(ID==3) glColor3f(1,0,0); | |
| else glColor3f(1,1,1); | |
| if(show[3]) glmDraw(lowarmR,GLM_MATERIAL); | |
| glPopMatrix(); | |
| glPopMatrix(); | |
| glPopMatrix(); | |
| glColor3f(0,1,0); | |
| glutSolidTeapot(0.02); | |
| glutSwapBuffers(); | |
| } | |
| int oldX=0,oldY=0; | |
| void motion(int x,int y) | |
| { | |
| teapotX += (x -oldX)/150.0; | |
| teapotY -= (y -oldY)/150.0; | |
| angle[ID] +=(x - oldX); | |
| oldX=x; | |
| oldY=y; | |
| ///angle = x; | |
| 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("week15"); | |
| glutDisplayFunc(display); | |
| glutMouseFunc(mouse); | |
| glutMotionFunc(motion); | |
| glutKeyboardFunc(keyboard);///keyboard要做事了(開檔、讀檔) | |
| glutMainLoop(); | |
| } |





沒有留言:
張貼留言