顯示具有 04160011_陳姮羽 標籤的文章。 顯示所有文章
顯示具有 04160011_陳姮羽 標籤的文章。 顯示所有文章

2017年6月12日 星期一

Week 08

主題:

(1)期中模擬考
(2)T-R-T複習
(3)打光
(4)機器人
(5)回家作業



1.複習期中考題  T-R-T


glPushMatrix();///備份矩陣
    glTranslatef(x,y,z);///移動
    glRotatef(angle,x,y,z);///旋轉
    glScalef(x,y,z);///縮放
    glBegin(GL_PLOYGON);///開始畫
        glNormal3f(nx,ny,nz);///打光的法向量
        glTexCoord2f(tx,ty);///貼圖座標
        glColor3f(r,g,b);///顏色
        glVertex3f(x,y,z);///頂點
    glEnd();///結束畫
glPopMatrix();///還原矩陣


2.打光


#include <GL/glut.h>
static void display(void)
{
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3d(1,0,0);
    glPushMatrix();
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}
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 };
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitWindowSize(640,480);
    glutInitWindowPosition(10,10);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("GLUT Shapes");
    glutDisplayFunc(display);
    glClearColor(1,1,1,1);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    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);
    glutMainLoop();
    return EXIT_SUCCESS;
}




3.旋轉中的打光


#include <GL/glut.h>
float angle=0;
static void display(void)
{
    angle++;
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3d(1,0,0);
    glPushMatrix();
        glRotatef(angle,0,1,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}
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 };
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitWindowSize(640,480);
    glutInitWindowPosition(10,10);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("GLUT Shapes");

    glutDisplayFunc(display);
    glutIdleFunc(display);

    glClearColor(1,1,1,1);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);

    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);
    glutMainLoop();
    return EXIT_SUCCESS;
}


4.各種形狀

glutSolidCone(0.8,0.3,30,30);


glutSolidCone(0.3,0.8,30,30);


glutWireCone(0.3,0.8,30,30);


glutSolidCube(0.5);


glScalef(0.5,0.5,0.5);
glutSolidDodecahedron();


5.一個靜止,一個旋轉


glPushMatrix();
        glTranslatef(0,0.5,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glPushMatrix();
        glRotatef(angle,0,1,0);
        glutSolidTeapot(0.3);
    glPopMatrix();


Week 03

建立點.線.面.色彩



data.
win32.
glut32.dll


windows檔解壓縮並打開shapes檔


右鍵選PLOYGON



複習上週程式



茶壺上色


glColor3f(1,0,0); //紅
glColor3f(0,1,0); //綠
glColor3f(0,0,1); //藍




有顏色的三角形


刪除glutSolidTeapot(0.3);
多加glBegin(GL_POLYGON);
 glColor3f(1,0,0);
 glVertex3f(0,0,0);//Vertex:頂點
 glColor3f(0,1,0);
 glVertex3f(1,1,0);
 glColor3f(0,0,1);
 glVertex3f(-1,1,0);
glEnd();

2017年6月11日 星期日

Week 16

Week  16

主題: 
         (1) 下周期末作品Demo
         (2) 內插公式  v.s  動作
         (3) 存槽,讀檔
         (4) 利用Timer自動內插
         (5)學期複習

課堂作業 :  用Excel試內插公式
                 A2x(新角度) + (1-A2)x(舊角度)



課堂作業 :  用自己或同學的作業   Bulid成功
                 (A)working 目錄
                 (B)include  lib 目錄
                 (C)freeglut


課堂作業 :  寫檔案... hw1.動作存檔 

int oldX=0,oldY=0;
FILE * fout=NULL;///存檔的步驟2, 宣告一個檔案的指標, (一開始是空的NULL)
void keyboard(unsigned char key,int x,int y)
{
    printf("%c\n", key);///你按了什麼鍵,印出來,方便了解老師按了什麼鍵
    if(key=='s'){///存檔的步驟3, 在按下 's' 鍵 save存檔
        if(fout == NULL){/// (一開始是空的NULL)
            fout = fopen("file.txt", "w+");///開啟檔案,檔名準備好, 並且是用 write加 模式
            printf("現在開啟一個檔案file.txt, w+模式\n");
        }
        printf("想要寫這些數值到檔案%f %f %f %f %f %f %f %f %f\n", angle[0], angle[1], angle[2], angle[3], angle[4], angle[5], angle[6], angle[7], angle[8]);
        fprintf( fout, "%f %f %f %f %f %f %f %f %f\n", angle[0], angle[1], angle[2], angle[3], angle[4], angle[5], angle[6], angle[7], angle[8]);
    }

    if(key=='0') now=0;
    if(key=='1') now=1;
    if(key=='2') now=2;
    if(key=='3') now=3;
    if(key=='4') now=4;
    if(key=='5') now=5;
    if(key=='6') now=6;
    if(key=='7') now=7;
    if(key=='8') now=8;
}
void mouse(int button,int state,int x,int y)
{
    oldX=x;  oldY=y;
    glutPostRedisplay();
}
void motion(int x,int y)
{
    angle[now]+=(x-oldX);
    oldX=x;
    glutPostRedisplay();
}






課堂作業 :  讀檔案...hw2動作存檔加讀檔


int oldX=0,oldY=0;
FILE * fout=NULL;///存檔的步驟2, 宣告一個檔案的指標, (一開始是空的NULL)
FILE * fin=NULL;///讀檔的步驟1, 宣告一個檔案的指標, (一開始是空的NULL)
void keyboard(unsigned char key,int x,int y)
{
    printf("%c\n", key);///你按了什麼鍵,印出來,方便了解老師按了什麼鍵
    if(key=='s'){///存檔的步驟3, 在按下 's' 鍵 save存檔
        if(fout == NULL){/// (一開始是空的NULL)
            fout = fopen("file.txt", "w+");///開啟檔案,檔名準備好, 並且是用 write加 模式
            printf("Now open file.txt for write+ Mode\n");
        }
        printf("Now write angle[] %f %f %f %f %f %f %f %f %f\n", angle[0], angle[1], angle[2], angle[3], angle[4], angle[5], angle[6], angle[7], angle[8]);
        fprintf( fout, "%f %f %f %f %f %f %f %f %f\n", angle[0], angle[1], angle[2], angle[3], angle[4], angle[5], angle[6], angle[7], angle[8]);
    }
    if(key=='r'){///讀檔的步驟2, 按下 'r' 去read
        if(fin == NULL){
            fin = fopen("file.txt", "r");///讀檔的步驟3,檔名準備好, 並且是用 read 模式
            printf("Now open file.txt for read Mode\n");
        }
        fscanf(fin, "%f %f %f %f %f %f %f %f %f", &angle[0], &angle[1], &angle[2], &angle[3], &angle[4], &angle[5], &angle[6], &angle[7], &angle[8]);
        printf("Now read angle[] Pa Pa Pa\n");   ///讀檔的步驟 fscanf()讀進來
        glutPostRedisplay();
    }

    if(key=='0') now=0;
    if(key=='1') now=1;
    if(key=='2') now=2;
    if(key=='3') now=3;
    if(key=='4') now=4;
    if(key=='5') now=5;
    if(key=='6') now=6;
    if(key=='7') now=7;
    if(key=='8') now=8;
}
void mouse(int button,int state,int x,int y)
{
    oldX=x;  oldY=y;
    glutPostRedisplay();
}
void motion(int x,int y)
{
    angle[now]+=(x-oldX);
    oldX=x;
    glutPostRedisplay();
}





課堂作業 :  結合...hw3動作存檔加讀檔 

void timer(int t)
{
    glutTimerFunc(10, timer, t+1);
    if(fin == NULL){
        fin = fopen("file.txt", "r");///讀檔的步驟3,檔名準備好, 並且是用 read 模式
        printf("Now open file.txt for read Mode\n");
        fscanf(fin, "%f %f %f %f %f %f %f %f %f", &newAngle[0], &newAngle[1], &newAngle[2], &newAngle[3], &newAngle[4], &newAngle[5], &newAngle[6], &newAngle[7], &newAngle[8]);
    }

    if(alpha >= 1.0){///如果讀太多,alpha超過了, 就要再讀新的angle, 而且要把原來新的,先變舊的
        /// oldAngle = newAngle
        for(int i=0;i<9;i++) oldAngle[i] = newAngle[i];
        /// read newAngle
        fscanf(fin, "%f %f %f %f %f %f %f %f %f", &newAngle[0], &newAngle[1], &newAngle[2], &newAngle[3], &newAngle[4], &newAngle[5], &newAngle[6], &newAngle[7], &newAngle[8]);
        printf("Now read angle[] Pa Pa Pa\n");   ///讀檔的步驟 fscanf()讀進來
        alpha=0.0;
    }

    ///angle = alpha * newAngle + (1-alpha)* oldAngle;
    for(int i=0;i<9;i++){///小心, 角度不見得只有9個,可能更多哦! 要調好,有更多,就要內插更多 ex. 20個
        angle[i]=alpha*newAngle[i] + (1-alpha)*oldAngle[i];///現在要改成交叉相乘的內插方式算角度
    }
    alpha += 0.01;///現在要改成交叉相乘的內插方式算角度, 每次加一點點alpha

    glutPostRedisplay();
}

........

 glutTimerFunc(1000,timer,0);


2017年6月6日 星期二

Week 12

Week  11

主題: 
         (1) 3D TRT 轉動
         (2) 矩陣,投影矩陣
         (3) 攝影機運鏡
         (4) 會動的機器人
         (5) [補]MP3播放



         課堂作業 :  播MP3最簡單

          #include <iostream>
          #include "CMP3_MCI.h"///(1) 放在同一個程式碼專案的目錄中哦
          CMP3_MCI myMP3;///(2) 宣告一個變數,叫 myMP3

          using namespace std;
          ///在 main()函式裡面
         int main()
         {
           myMP3.Load("yukai.mp3"); /// "C:/dropbox/yukai.mp3"
           myMP3.Play();/// (4) Play the file

          int n;
          cin >> n;///
          cout << "Hello world!" << endl;
          return 0;
        }



         課堂作業 : 運鏡 ex.變型金剛導演
         課堂作業 :  jsyeh/3dcg1Q 下載
                          data.zip → 桌面\windows\data\模型
                          window.zip → 桌面\windows\project.exe
                          glut32.dll → 桌面\windows\glut32.dll
         課堂作業 : glutLookAt(eyeX,eyeY,eyeZ,centerX,centerY,centerZ,upX,upY,upZ);     
         課堂作業 : 04160011_hw4_gluLook.zip專案 解壓,執行
         課堂作業 : 改eyeX,eyeY,eyeZ, (-0.8~0~0.8)
         課堂作業 : 04160011_hw5_gluPerspective.cpp

         課堂作業 : 04160011_hw6_pushTRT.cpp