顯示具有 04163013_吳乾坤 標籤的文章。 顯示所有文章
顯示具有 04163013_吳乾坤 標籤的文章。 顯示所有文章

2017年6月11日 星期日

Week16 oOvOo吳乾坤的上課作業

1.用Excel


2.用內差法放入timer函式
程式碼如下
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 %f %f %f %f", &newAngle[0], &newAngle[1], &newAngle[2], &newAngle[3], &newAngle[4], &newAngle[5], &newAngle[6], &newAngle[7], &newAngle[8], &newAngle[8], &newAngle[9], &newAngle[10], &newAngle[11], &newAngle[12]);
    }
    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 %f %f %f %f", &newAngle[0], &newAngle[1], &newAngle[2], &newAngle[3], &newAngle[4], &newAngle[5], &newAngle[6], &newAngle[7], &newAngle[8], &newAngle[8], &newAngle[9], &newAngle[10], &newAngle[11], &newAngle[12]);
        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();
}


3.讀檔案

}void keyboard(unsigned char key, int x, int y)
{
     printf("%c\n", key);///你按了什麼鍵,印出來,方便了解老師按了什麼鍵
    if(key=='z'){///存檔的步驟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 %f %f %f %f\n", angle[0], angle[1], angle[2], angle[3], angle[4], angle[5], angle[6], angle[7], angle[8],angle[9],angle[10],angle[11],angle[12]);
        fprintf( fout, "%f %f %f %f %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],angle[9],angle[10],angle[11],angle[12]);
    }

    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;
    if(key=='9')now=9;
    if(key=='q')now=10;
    if(key=='w')now=11;
    if(key=='e')now=12;
    if(key=='r')now=13;
    if(key=='a')now=14;
    if(key=='s')now=15;
}

Week14 oOvOo吳乾坤的上課作業

1.將呼叫模型進入程式畫出手臂的程式做整理
2.把上手臂及下手臂弄在同一組程式碼內
  glPushMatrix();///整枝左手
            glTranslatef(-0.09,0.1,0);
            glRotatef(-angle[3], 0,0,1);
            glTranslatef(0,-0.1,0);
            drawRA1();///左大手臂

            glTranslatef(0,-0.18,0);
            glRotatef(-angle[4], 0,0,1);
            glTranslatef(0,-0.1,0);
            drawRA2();///左小手臂

            glTranslatef(0,-0.15,0);
            glRotatef(-angle[11], 0,0,1);
            glTranslatef(0.02,0.06,0);
            drawLL1();///左小手臂

        glPopMatrix();
3.加入鍵盤 滑鼠函式
float angle[20] = {} ;
int now=0;
int oldX=0, oldY=0;
void keyboard(unsigned char key, int x, int y)
{


    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;
    if(key=='9')now=9;
    if(key=='q')now=10;
    if(key=='w')now=11;
    if(key=='e')now=12;
    if(key=='r')now=13;
    if(key=='a')now=14;
    if(key=='s')now=15;
}
void mouse(int button, int state, int x, int y)
{
    oldX=x; oldY=y;
    glutPostRedisplay();
}
int main()
{
  glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
}

Week13 oOvOo吳乾坤的上課作業

作業一 
TRT講解 

glPushMatrix();  // 10%
  glTranslatef(0.6,0.4,0); // 20%移動 最後把 照著想要的軸心旋轉的手軸 移動到 真的畫面裡
  glRotatef( -80,0,0,1); // 20% 接著設定旋轉的值
  glTranslatef(0.3,0.3,0); // 20% 先把手軸對好旋轉中心
  drawHand(); // 20% 畫手
glPopMatrix(); // 10%

Week12 oOvOo吳乾坤的上課作業

一、加入程式碼讓程式能撥放音樂
去FB載老師給的檔案

程式碼如下:

#include "CMP3_MCI.h"           //檔案放同目錄
 CMP3_MCI  myMP3;               //宣告變數
int main(....)                  //Load檔案
{                                       
        myMP3.Load("音樂mp3");
        myMP3.Play( );          //Play播放
//小心,要卡住;
}
二、調整自己的視角


程式碼如下:

float eyeX=0,eyeY=0,eyeZ=1;
float centerX=0,centerY=0,centerZ=0;
float upX=0,upY=1,upZ=0;
static void display(void)
{

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3d(1,0,0);
    glPushMatrix();
        gluLookAt(eyeX,eyeY,eyeZ,
                  centerX,centerY,centerZ,
                  upX,upY,upZ);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}

2017年5月2日 星期二

Week 11 吳乾坤

一、
1.搜尋 3d exploration並下載
2.開啟足球檔


3.Save as

4.存成cpp檔
5.要選SampleAPP
6.開一個Open GL Project
7.Delet掉原本的main涵式
8.將足球檔加入有main涵式的資料夾
9.加入足球檔,並刪除錯誤的程式碼
二、畫海豚
1.打開海豚,發現有三隻,存成OBJ檔,下方改成visible object only。

2.使用老師給的檔案,並將剛剛存好的三隻海豚檔放入data資料夾內。



 3.複製程式碼


4.執行可愛ㄉ海豚
5.加一點旋轉、縮放,做成機器人的樣子




2017年4月27日 星期四

Week6 oOvOo吳乾坤的上課作業

1.打光的茶壺

2.讓茶壺旋轉
  加上 angle參數,還有glRotatef(angle,0,1,0);函式
減少每次angle+的數值,能讓他轉得更慢。
3.畫多邊形

A.實心圓錐
 加入glutSolidCone(0.3,0.8,30,30);///實心圓錐
B.空心圓椎
glutWireCone(0.3,0.8,30,5);
C.實心正方體
 glutSolidCube(0.5);
D.五邊形體
 glScalef(0.5,0.5,0.5); 利用縮放函式讓形體小一點
        glutSolidDodecahedron();///五邊形體
E.三邊形體
glutSolidIcosahedron();
F.鑽石體
glutSolidOctahedron();
G.金字塔體
glutSolidTetrahedron();
H.圓球
glutSolidSphere(0.7,30,30);

I.空心圓球
glutWireSphere(0.7,30,30);









2017年3月27日 星期一

Week05 oOvOo吳乾坤的上課作業



1.畫茶壺

+上mouseX mouseY讓其隨著滑鼠移動



2.將Translated改成glScalef



3.加入rotX,使其向中心插著一根竹籤般旋轉。


2017年3月22日 星期三

Week04 oOvOo吳乾坤的上課作業

1.      利用math函式庫寫一個圓形

#include <GL/glut.h>
#include <math.h>
void display()
{
    glBegin(GL_POLYGON);
    for(float angle=0;angle<=3.1415926*2;angle+=0.01)
    {
        glVertex2f(cos(angle),sin(angle));
    }
    glEnd();
    glutSwapBuffers();
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("04163013 Number 1");//
改視窗名稱


    glutDisplayFunc(display);
    glutMainLoop();

    return EXIT_SUCCESS;
}
2.     利用滑鼠點擊變色(增加mouse函式)

#include <GL/glut.h>
#include <math.h>
#include <stdio.h>
void display()
{
    glBegin(GL_POLYGON);
    for(float angle=0;angle<=3.1415926*2;angle+=0.01)
    {
        glVertex2f(cos(angle),sin(angle));
    }
    glEnd();
    glutSwapBuffers();
}
void mouse(int button,int state,int x,int y)
{
    printf("%d %d %d %d\n",button,state,x,y);
    glColor3f(1,x/300.0,y/300.0);
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("04163013 Number 1”);
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMainLoop();

    return EXIT_SUCCESS;

}
3.     滑鼠移動改變顏色(增加motion函式)

#include <GL/glut.h>
#include <math.h>
#include <stdio.h>
void display()
{
    glBegin(GL_POLYGON);
    for(float angle=0;angle<=3.1415926*2;angle+=0.01)
    {
        glVertex2f(cos(angle),sin(angle));
    }
    glEnd();
    glutSwapBuffers();
}
void mouse(int button,int state,int x,int y)
{
   // printf("%d %d %d %d\n",button,state,x,y);
   // glColor3f(1,x/300.0,y/300.0);
}
void motion(int x,int y)
{
    glColor3f(1,x/300.0,y/300.0);
    glutPostRedisplay();
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("04163013 Number 1");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMotiFunc(motion);
    glutMainLoop();

    return EXIT_SUCCESS;

}
4.

#include <GL/glut.h>
#include <math.h>
#include <stdio.h>
float mouth=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glBegin(GL_TRIANGLE_FAN);
    glVertex2f(0,0);
    for(float angle=0+mouth;angle<=3.1415926*2-mouth;angle+=3.1415926/100)
    {
        glVertex2f(cos(angle),sin(angle));
    }
    glEnd();
    glutSwapBuffers();
}
void mouse(int button,int state,int x,int y)
{
   // printf("%d %d %d %d\n",button,state,x,y);
   // glColor3f(1,x/300.0,y/300.0);
}
void motion(int x,int y)
{
    mouth=x/300.0;
    glColor3f(1,x/300.0,y/300.0);
    glutPostRedisplay();
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("04163013 Number 1");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();

    return EXIT_SUCCESS;

}

2017年3月14日 星期二

Week03 oOvOo吳乾坤的上課作業

使用老師直播中所教的技巧繪圖

1.將上週所留下來的10行程式碼叫出再稍作改寫


2.使用glBegin(GL_POLYGON);和 glEnd();搭配預備寫出圖形

3.小技巧(1)
     使用
    glClearColor(1,1,1, 0);
    glClear(GL_COLOR_BUFFER_BIT);
   可以將執行背景變為白色
4.使用
glVertex2f((409-1000)/1000.0,-(157-1000)/1000.0);
        glVertex2f((439-1000)/1000.0,-(153-1000)/1000.0);
        glVertex2f((465-1000)/1000.0,-(153-1000)/1000.0);
三行程式碼即可畫出一個圖形

5.利用小畫家

(1)找座標
將滑鼠移動到圖上任一點,即可用逗點前的數字做為X座標,逗點後做為Y座標
(因為數值需要小數,所以須將座標數據-1000再除以1000,又因圖形會上下顛倒,故將Y值都加上一個負號。)

(2)取顏色
用滴管取出想要的顏色,再打開編輯色彩,即能取得三元色素值,將數值套入glColor3f(255/255.0,255/255.0,255/255.0);即可取得此顏色。

5.注意
由於GL_POLYGON只能使用凸多邊形,故須將圖形切割成凸多邊形再行繪圖。

6.實作
(1).可用註記的方式才不會每次都要重新找尋頂點
(2).記得標記分組//-----17

7.完成

8.後記

以後要記得作業的最後上傳時間,才不會很用心的做作業發現上傳時間已經結束了,幫自己默哀三秒鐘...
.
.
.
.
.
.
.
.
.
默哀結束。












2017年2月21日 星期二

Week01 oOvOo吳乾坤的上課作業


1.WebGL Water.


2.一直轉ㄉ三角形

步驟一:打開Code blocks


步驟二:開新專案 File>new>project


步驟三:開啟Open GLproject


步驟四:選擇存放路徑為桌面


步驟五:點開main.c 可以發覺程式碼超多行QQ



步驟六:執行


完成!!! 





3.很多圖形轉轉轉~
步驟一:開新專案 File>new>project 選擇 GLUT project


 步驟二:下載程式


步驟三:選擇路徑



步驟四:執行


完成666666~~



4.畫茶壺

步驟一:把剛剛的程式碼刪刪刪刪刪刪刪刪

從這樣


 變成這樣


步驟二:再加上 glitSolidTeapot(0.3);這行程式碼




執行後完成~~