顯示具有 06160681_羅翊軒 標籤的文章。 顯示所有文章
顯示具有 06160681_羅翊軒 標籤的文章。 顯示所有文章

2019年5月31日 星期五

DannyLo筆記 Week15

本周主題:攝影機運鏡,投影

投影

1.開啟Projection程式

2.
        Eye----> 眼睛位置 (也就是相機位置)
    Center---->相機所拍的正中心要在哪
 Up---->相機 "自身" 的轉動

------------------------------------------------------------程式--------------------------------------------------------
1.打開source資料夾,把三個丟到專案資料夾中

2.把glm.c改成glm.cpp

3.在codeblock的專案中 右鍵 ADD file 把glm.cpp加進來

4.然後把data 模型資料夾放到 freeglut的bin資料夾中

5.然後把projection中的程式碼取代掉main.cpp中的程式

Step01-1 做出白白的人 沒有打光 所以只有模型


Step01-2 打光


Step01-3 旋轉運鏡 (破圖)


Step01-4 旋轉運鏡 (改center 往上移 可把鏡調高)


Step01-5 旋轉運鏡(更改鏡頭)

2019年5月24日 星期五

DannyLo筆記 Week14

本周主題:計時器,內插公式(補間動畫),動畫(KeyFrame)


計時器

1.先開GLUT專案

2.程式碼
#include <GL/glut.h> #include <mmsystem.h>///NOW (0)發聲音 void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glutSwapBuffers(); } void timer(int t)///NOW (2) { glutTimerFunc(1000, timer, 0);///NOW2 每延遲1秒 呼叫timer PlaySoundA("fart.wav", NULL, SND_ASYNC);///NOW (2) 播音檔 } int main(int argc, char**argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(500,500);///大一點 glutCreateWindow("week14 timer"); glutDisplayFunc(display); glutTimerFunc(1000, timer, 0);///NOW (1) glutMainLoop(); }

3.旋轉茶壺
#include <GL/glut.h> #include <mmsystem.h>///NOW (0)發聲音 #include <stdio.h>///NOW3 for printf() float angle=0;///NOW4 void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix();///NOW4 glRotatef(angle, 0, 0, 1);///NOW4 glutSolidTeapot( 0.3 );///NOW4 glPopMatrix();///NOW4 glutSwapBuffers(); } void timer(int t)///NOW (2) { glutTimerFunc(30, timer, t+1);///NOW4 ///NOW3 一起床,馬上撥下一個鬧鐘, 時間才會準
///延遲30/1000秒 才會呼叫timer 並做加1的動作
///因為延遲 所以先轉動 才會呼叫 timer printf("現在的 timer(t)的t是: %d\n", t);///NOW3 angle = t;///NOW4 每秒跟著t轉1度 glutPostRedisplay();///NOW4 要更新畫面 } int main(int argc, char**argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(500,500);///大一點 glutCreateWindow("week14 timer"); glutDisplayFunc(display); glutTimerFunc(1000, timer, 0);///NOW (1) glutMainLoop(); }

內插公式

alpha 0.0~1.0
內插: alpha*新+(1-alpha)*舊

#include <GL/glut.h>
#include <mmsystem.h>///NOW (0)發聲音 #include <stdio.h>///NOW3 for printf() float angle=0;///NOW4 float nowX=0;///NOW5 void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix();///NOW4 ///glRotatef(angle, 0, 0, 1);///NOW4 glTranslatef(nowX, 0, 0);///NOW5 glutSolidTeapot( 0.3 );///NOW4 glPopMatrix();///NOW4 glutSwapBuffers(); } void timer(int t)///NOW (2) {/// 1000 ms = 1秒, 30ms = 0.03秒 => 33*30=(大約)1000, 每1秒30fps glutTimerFunc(30, timer, t+1);///NOW4 ///NOW3 一起床,馬上撥下一個鬧鐘, 時間才會準 printf("現在的 timer(t)的t是: %d\n", t);///NOW3 float alpha = (t%30) / 30.0;///變成 alpha: 0.0 ~ 1.0 ///NOW5 t到30會再回到0 nowX = alpha*1.0 + (1-alpha)* -1.0;///NOW5 glutPostRedisplay();///NOW4 要更新畫面 } int main(int argc, char**argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(500,500);///大一點 glutCreateWindow("week14 timer"); glutDisplayFunc(display); glutTimerFunc(1000, timer, 0);///NOW (1) glutMainLoop(); }

2019年5月17日 星期五

DannyLo筆記 Week13

本周主題:開檔案、存取檔案,擺動關節、動作


1.開啟Console application專案

2.程式
#include <stdio.h> FILE * fout=NULL;///宣告 檔案指標 變數 int main() { fout=fopen("filename.txt","w+");///開檔案 /// 檔案名稱.檔案類型 w+為write寫入的縮寫 +為進化版 for(int i=0;i<20;i++) { fprintf(fout,"Hello World\n"); ///在fout檔案中寫入20個Hello World } }

3.開啟的檔案


4.複習浮點數陣列
#include <stdio.h> FILE * fout=NULL;///宣告 檔案指標 變數 float angle[20]; int main() { fout=fopen("motion.txt","w+");///開檔案 /// w+為write寫入的縮寫 +為進化版 for(int i=0;i<20;i++) { fprintf(fout,"%.1f ",angle[i]); ///在fout檔案中寫入20個陣列中的浮點數
///%.1f為只印小數點後第一位 } }

結合glut

1.開啟glut專案

2.程式 (畫出右肩)
#include <GL/glut.h> float angle[20];///NOW void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix();///body glColor3f(1,1,1);///white glutSolidTeapot( 0.3 );///body glPushMatrix();///right Arm glTranslatef(0.18, 0, 0);///(3)掛到肩上 glRotatef(angle[1], 0,0,1);///(2)轉動 ///NOW glTranslatef(0.18, 0, 0);///(1)改變旋轉中心,放到中心 glColor3f(1,0,0);///red glutSolidTeapot( 0.2 );///right upper arm glPopMatrix(); glPopMatrix(); glutSwapBuffers(); } int oldX;///NOW void mouse(int button, int state, int x, int y)///NOW { oldX = x;///把滑鼠按下去的點設為舊的點 } void motion(int x, int y)///NOW { angle[1] += (x-oldX);///持續的對angle1的數值做更動 把移動度滑鼠往右正值為逆時針
往左負值為順時針 oldX = x;///NOW display();///NOW } int main(int argc, char**argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH); ///glutInitWindowSize(600,600);///我們可以開很大的視窗 glutCreateWindow("week 13 motion TRT angle file"); glutMouseFunc(mouse);///NOW glutMotionFunc(motion);///NOW glutDisplayFunc(display); glutMainLoop(); }

3.(畫出右手臂+整隻左手)
#include <GL/glut.h> float angle[20];///NOW void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix();///body glColor3f(1,1,1);///white glutSolidTeapot( 0.3 );///body glPushMatrix();///right Arm glTranslatef(0.18, 0, 0);///(3)掛到肩上 glRotatef(angle[1], 0,0,1);///(2)轉動 ///NOW glTranslatef(0.18, 0, 0);///(1)改變旋轉中心,放到中心 glColor3f(1,0,0);///red glutSolidTeapot( 0.2 );///right upper arm glPushMatrix();///NOW2 長出下手臂 glTranslatef(0.18, 0, 0);///(3)掛到肘上 glRotatef(angle[1], 0,0,1);///(2)轉動 ///NOW glTranslatef(0.18, 0, 0);///(1)改變旋轉中心,放到中心 glColor3f(1,0,0);///red glutSolidTeapot( 0.2 );///right lower arm glPopMatrix(); glPopMatrix(); glPushMatrix();///left Arm
///glRotatef(180,0,1,0);多加這一行 並把以下移動改為正 可以變成鏡像 glTranslatef(-0.18, 0, 0);///(3)掛到肩上 glRotatef(angle[1], 0,0,1);///(2)轉動 ///NOW glTranslatef(-0.18, 0, 0);///(1)改變旋轉中心,放到中心 glColor3f(1,0,0);///red glutSolidTeapot( 0.2 );///left upper arm glPushMatrix();///NOW2 長出下手臂 glTranslatef(-0.18, 0, 0);///(3)掛到肘上 glRotatef(angle[1], 0,0,1);///(2)轉動 ///NOW glTranslatef(-0.18, 0, 0);///(1)改變旋轉中心,放到中心 glColor3f(1,0,0);///red glutSolidTeapot( 0.2 );///left lower arm glPopMatrix(); glPopMatrix(); glPopMatrix(); glutSwapBuffers(); } int oldX;///NOW void mouse(int button, int state, int x, int y)///NOW { oldX = x;///NOW } void motion(int x, int y)///NOW { angle[1] += (x-oldX);///NOW oldX = x;///NOW display();///NOW } int main(int argc, char**argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH); ///glutInitWindowSize(600,600);///我們可以開很大的視窗 glutCreateWindow("week 13 motion TRT angle file"); glutMouseFunc(mouse);///NOW glutMotionFunc(motion);///NOW glutDisplayFunc(display); glutMainLoop(); }

4.先跑好動作再按w會儲存在檔案裡 再按住r可讀入連續動作
#include <stdio.h> ///(0) ///NOW4 #include <GL/glut.h> FILE * fout=NULL;///(1) ///NOW4 FILE * fin =NULL;///(1) ///NOW5 float angle[20];///NOW int angleID=1;///第幾個要轉動的關節 ///NOW3 void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix();///body glColor3f(1,1,1);///white glutSolidTeapot( 0.3 );///body glPushMatrix();///right Arm glTranslatef(0.18, 0, 0);///(3)掛到肩上 glRotatef(angle[1], 0,0,1);///(2)轉動 ///NOW glTranslatef(0.18, 0, 0);///(1)改變旋轉中心,放到中心 glColor3f(1,0,0);///red glutSolidTeapot( 0.2 );///right upper arm glPushMatrix();///NOW2 長出下手臂 glTranslatef(0.18, 0, 0);///(3)掛到肘上 glRotatef(angle[1], 0,0,1);///(2)轉動 ///NOW glTranslatef(0.18, 0, 0);///(1)改變旋轉中心,放到中心 glColor3f(1,0,0);///red glutSolidTeapot( 0.2 );///right lower arm glPopMatrix(); glPopMatrix(); glPushMatrix();///left Arm glRotatef(180,0,1,0); glTranslatef(0.18, 0, 0);///(3)掛到肩上 glRotatef(angle[2], 0,0,1);///(2)轉動 ///NOW glTranslatef(0.18, 0, 0);///(1)改變旋轉中心,放到中心 glColor3f(1,0,0);///red glutSolidTeapot( 0.2 );///left upper arm glPushMatrix();///NOW2 長出下手臂 glTranslatef(0.18, 0, 0);///(3)掛到肘上 glRotatef(angle[2], 0,0,1);///(2)轉動 ///NOW glTranslatef(0.18, 0, 0);///(1)改變旋轉中心,放到中心 glColor3f(1,0,0);///red glutSolidTeapot( 0.2 );///left lower arm glPopMatrix(); glPopMatrix(); glPushMatrix();///right Arm glTranslatef(0.18, -0.3, 0);///(3)掛到肩上 glRotatef(angle[3], 0,0,1); glRotatef(-90,0,0,1); glTranslatef(0.18, 0, 0);///(1)改變旋轉中心,放到中心 glColor3f(1,0,0);///red glutSolidTeapot( 0.2 );///right upper arm glPushMatrix();///NOW2 長出下手臂 glTranslatef(0.18, 0, 0);///(3)掛到肘上 glRotatef(angle[3], 0,0,1);///(2)轉動 ///NOW glTranslatef(0.18, 0, 0);///(1)改變旋轉中心,放到中心 glColor3f(1,0,0);///red glutSolidTeapot( 0.2 );///right lower arm glPopMatrix(); glPopMatrix(); glPushMatrix();///left Arm glRotatef(180,0,1,0); glTranslatef(0.18, -0.3, 0);///(3)掛到肩上 glRotatef(angle[4], 0,0,1); glRotatef(-90,0,0,1); glTranslatef(0.18, 0, 0);///(1)改變旋轉中心,放到中心 glColor3f(1,0,0);///red glutSolidTeapot( 0.2 );///left upper arm glPushMatrix();///NOW2 長出下手臂 glTranslatef(0.18, 0, 0);///(3)掛到肘上 glRotatef(angle[4], 0,0,1);///(2)轉動 ///NOW glTranslatef(0.18, 0, 0);///(1)改變旋轉中心,放到中心 glColor3f(1,0,0);///red glutSolidTeapot( 0.2 );///left lower arm glPopMatrix(); glPopMatrix(); glPopMatrix(); glutSwapBuffers(); } int oldX;///NOW void mouse(int button, int state, int x, int y)///NOW { oldX = x;///NOW } void motion(int x, int y)///NOW { angle[angleID] += (x-oldX);///NOW ///NOW3 oldX = x;///NOW if(fout==NULL) fout=fopen("motion.txt", "w+");///NOW4 for(int i=0; i<20; i++){///NOW4 滑鼠邊動邊讀入 printf( "%.1f ", angle[i]);///NOW4 fprintf( fout, "%.1f ", angle[i]);///NOW4 } printf("\n");///NOW4 fprintf(fout, "\n");///NOW4 display();///NOW } void keyboard(unsigned char key, int x, int y)///NOW3 { if(key=='1') angleID=1;///NOW3 if(key=='2') angleID=2;///NOW3 if(key=='3') angleID=3;///NOW3 if(key=='4') angleID=4;///NOW3 if(key=='w' || key=='W'){///NOW4 小寫的 w 如果寫了上面的滑鼠讀入 就不用寫這裡的w ///可以直接按r跑 if(fout==NULL) fout=fopen("motion.txt", "w+");///NOW4 for(int i=0; i<20; i++){///NOW4 printf( "%.1f ", angle[i]);///NOW4 fprintf( fout, "%.1f ", angle[i]);///NOW4 } printf("\n");///NOW4 fprintf(fout, "\n");///NOW4 } if(key=='r'){///NOW5 if(fin==NULL) fin = fopen("motion.txt", "r");///NOW5 for(int i=0; i<20;i++){///NOW5 fscanf(fin, "%f", &angle[i]);///NOW5 }///NOW5 } glutPostRedisplay();///和 display()很像,但更好 ///NOW5 } int main(int argc, char**argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH); ///glutInitWindowSize(600,600);///我們可以開很大的視窗 glutCreateWindow("week 13 motion TRT angle file"); glutKeyboardFunc(keyboard);///NOW3 glutMouseFunc(mouse);///NOW glutMotionFunc(motion);///NOW glutDisplayFunc(display); glutMainLoop(); }