顯示具有 09160430_黃柏瑀 標籤的文章。 顯示所有文章
顯示具有 09160430_黃柏瑀 標籤的文章。 顯示所有文章

2022年6月14日 星期二

A

 WEEK17

1.講解期末報告評分、該如何製作
2.程式碼:
#include <GL/glut.h>
 void display()
 {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3f(1,1,0);
    glutSolidTeapot(0.3);

    glutSwapBuffers();
 }
 int main(int argc, char *argv[])//main()主函式 進階版
 {
    glutInit(&argc,argv);//把參數送給glutInit初始化
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);//雙緩衝區+3D深度功能
    glutCreateWindow("第02週的程式喔!!");//開GLUT視窗

    glutDisplayFunc(display);//顯示用的函式

    glutMainLoop();
 }


打光:

const GLfloat light_ambient[]  = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[]  = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };

const GLfloat mat_ambient[]    = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[]    = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[]   = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };
函示宣告
 glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);

    glEnable(GL_LIGHT0);
    glEnable(GL_NORMALIZE);
    glEnable(GL_COLOR_MATERIAL);
    glEnable(GL_LIGHTING);

    glLightfv(GL_LIGHT0, GL_AMBIENT,  light_ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE,  light_diffuse);
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);

    glMaterialfv(GL_FRONT, GL_AMBIENT,   mat_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE,   mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR,  mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);

2022年6月7日 星期二

A

 week16

1. alpha 內插公式: 0.0 ~ 1.0 ➡ angle=alpha*新角度+(1-alpha)*舊角度

2-1.複製上週 week15-angle-TRT-again 程式碼 

檔名: week16-interpolation

2-2.改善按r之後動作不連續的狀況,利用alpha內插法




程式碼:#include <GL/glut.h>

void reshape(int w,int h){
    const float ar = (float) w / (float) h;

    glViewport(0, 0, w, h);///3D變2D
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60,ar,0.1,100);

    glMatrixMode(GL_MODELVIEW);///3D Model+View
    glLoadIdentity() ;
    gluLookAt(0,0,3,
              0,0,0,
              0,1,0
              );
}
void display(){
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glutSolidTeapot(1);
    glutSwapBuffers();
}
int main(int argc,char** argv){
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week16");

    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutMainLoop();
}





2022年5月31日 星期二

A

 WEEK15

1.1 先設立資料夾在桌面 命名為week14-1_ fprintf

1.2  open-empty file 存檔為week14-1.cpp

1.3 程式碼

#include <stdio.h>

int main()

{///檔案指標  fout  開啟檔案(檔名 , 寫)

    FILE * fout = fopen("file.txt", "w+");

    printf(     "Hello world\n");

    fprintf(fout,"Hello World\n");

    fclose(fout);///關閉檔案

}

2.1開啟 codeblocks 建立一個新檔(File > New > Empty File> : week15-1_PlaySound.cpp


2.2 上週使用 PlaySound( "檔名.wav" , NULL , SND_ASYNC);  //不等待/不同步
    本週使用 PlaySound( "檔名.wav" , NULL , SND_SYNC);  //等待/同步

2.3要注意工作執行目錄 working_dir (in C:\....)

3.1  codeBlocks / File / Project / 檔名:week15--angles-TRT_again

ctrl c 上週程式:week14-angles-fprintf-fscanf,改善按r鍵時,動畫先拉

一下才恢復原先速度的情況



2022年5月24日 星期二

A

    

 week14

1.今日課程:寫檔fprintf()、讀檔fscanf()、寫檔fprintf()+project、讀檔fscanf()+project

1.1  程式碼:#include<stdio.h>

int main()

{

///檔案指標fout 開啟檔案(檔名,write模式)


    FILE * fout = fopen("write.txt","w+");

    printf("Hello world\n");

    fprintf(fout,"Hello world\n");

    fclose(fout);


}

1.2  程式碼:#include<stdio.h>

int main()

{

///檔案指標fout 開啟檔案(檔名,write模式)


    FILE * fout = fopen("file.txt","w+");

    fprintf(fout,"3.1415926\n");

    fclose(fout);///關檔



    float angle =0;

    FILE * fin=fopen("file.txt","r");

    fscanf(fin,"%f",&angle);///沒加&會當

    printf("讀到了角度:%f",angle);

    fclose(fin);


}

1.3 加上my read 按下鍵盤r可以撥放音樂

#include <opencv/highgui.h>
 #include <opencv/cv.h>  #include <GL/glut.h>  #include <stdio.h> float angle[20],oldx=0;
int angleID=0;
FILE * fout = NULL,* fin= NULL;
void myWrite()
{
if(fout==NULL) fout=fopen("file.txt","w+");
for(int i=0;i<20;i++)
{
printf("%.1f",angle[i]);
fprintf(fout,"%.1f",angle[i]);
}
printf("\n");
fprintf(fout,"\n");
} void myRead()
{
if(fout!=NULL) {fclose(fout); fout=NULL;}
if(fin==NULL) fin=fopen("file.txt","r");
for(int i=0;i<20;i++)
{
fscanf(fin,"%f",&angle[i]);
}
glutPostRedisplay();
}
void keyBoard(unsigned char key,int x,int y)
{
if(key=='r') myRead();
if(key=='0') angleID=0;
if(key=='1') angleID=1;
if(key=='2') angleID=2;
if(key=='3') angleID=3;
} void mouse(int button,int state,int x,int y)
{
oldx=x;
} void motion(int x,int y)
{
angle[angleID]+=(x-oldx);///改變量質
myWrite();
oldx=x;
glutPostRedisplay();///重畫畫面
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); ///畫圖前,清畫面
glColor3f(1,1,1);///白色的
glRectf(0.3,0.5,-0.3,-0.5);
glPushMatrix();///右半邊
glTranslatef(0.3,0.4,0);///將方塊掛回原來的地方
glRotatef(angle[0],0,0,1);///對z軸旋轉
glTranslatef(-0.3,-0.4,0);///將方塊中心移到世界中心
glColor3f(1,0,0);///紅色
glRectf(0.3,0.5,0.7,0.3);///上手臂
glPushMatrix();
glTranslatef(0.7,0.4,0);///將方塊掛回原來的地方
glRotatef(angle[1],0,0,1);///對z軸旋轉
glTranslatef(-0.7,-0.4,0);///將方塊中心移到世界中心
glColor3f(0,1,0);///綠色
glRectf(0.7,0.5,1.0,0.3);///下手肘
glPopMatrix();
glPopMatrix();
glPushMatrix();///左半邊
glTranslatef(-0.3,0.4,0);///將方塊掛回原來的地方
glRotatef(angle[2],0,0,1);///對z軸旋轉
glTranslatef(0.3,-0.4,0);///將方塊中心移到世界中心
glColor3f(1,0,0);///紅色
glRectf(-0.3,0.5,-0.7,0.3);///上手臂
glPushMatrix();
glTranslatef(-0.7,0.4,0);///將方塊掛回原來的地方
glRotatef(angle[3],0,0,1);///對z軸旋轉
glTranslatef(0.7,-0.4,0);///將方塊中心移到世界中心
glColor3f(0,1,0);///綠色
glRectf(-0.7,0.5,-1.0,0.3);///下手肘
glPopMatrix();
glPopMatrix();
glutSwapBuffers(); ///畫好後,交換出來
}
int main(int argc,char**argv) ///main()主函式進階版
{
glutInit(&argc,argv); ///把參數給glutInit初始化
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH); ///雙緩衝區,3D深度功能
glutCreateWindow("第13的程式"); ///開啟GLUT視窗
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutKeyboardFunc(keyBoard);
glutDisplayFunc(display); ///用來顯示函式
glutMainLoop();
}







VERY BEAUTIFUL, VERY POWERFUL

一.     一樣先安裝且設定好freeglut,OpecCV, 開啟CodeBlocks建立新專案 week11_gundam,                 把 MyGundam.zip下載解壓縮後的data資料夾放到freeglut/bin裡面 把week09_openc...