顯示具有 00370915_蔡昀佑 標籤的文章。 顯示所有文章
顯示具有 00370915_蔡昀佑 標籤的文章。 顯示所有文章

2015年6月10日 星期三

00370915 蔡昀佑 Computer Graphics Week16 - fout & fin & Interpolate

#include<GL/glut.h>
#include<stdio.h>
FILE * fout = NULL;
FILE * fin = NULL;
float oldX=0, oldY=0;
float angle[48]={0};
int now = 0;
void timerPlay(int t)
{
    glutTimerFunc(10,timerPlay,0);
    if(fin==NULL) fin=fopen("a.txt","r");
    {
        for(int i=0; i<48 ;i++)
        {
            fscanf(fin,"%f",&angle[i]);
           // printf("%f ",angle[i]);
        }
    }
}

void keyboard(unsigned char key, int x,int y)
{
    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=='p') glutTimerFunc(10,timerPlay,0);
    glutPostRedisplay();
}
void drawBody(){
    glPushMatrix();
    glScalef(0.35, 0.35, 0.35);
    glutSolidCube(1);
    glPopMatrix();
}
void drawUpArm(){
    glPushMatrix();
    glScalef(0.35, 0.14, 0.14);
    glutSolidCube(1);
    glPopMatrix();
}
void drawDownArm(){
    glPushMatrix();
    glScalef(0.35, 0.12, 0.12);
    glutSolidCube(1);
    glPopMatrix();
}
void drawHand(){
    glPushMatrix();
    glScalef(0.11, 0.11, 0.11);
    glutSolidCube(1);
    glPopMatrix();
}
void drawFinger(){
    glPushMatrix();
    glScalef(0.1, 0.02, 0.02);
    glutSolidCube(1);
    glPopMatrix();
}
void drawDownBody(){
    glPushMatrix();
    glScalef(0.3, 0.3, 0.3);
    glutSolidCube(1);
    glPopMatrix();
}
void display()
{
    ///Lighting
    glColor3ub(166,132,100);
    GLfloat pos[]={0, 0, -1, 0};
    glLightfv(GL_LIGHT0, GL_POSITION, pos);
    glEnable(GL_LIGHT0);
   // glEnable(GL_LIGHTING);
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
    glTranslatef(0, 0, 0);
    glRotatef(angle[8], 1,0,0);
    glTranslatef(0, 0.2,0);
    drawBody();
        glPushMatrix();
            glTranslatef(0.1, 0.1, 0);
            glRotatef(angle[1], 0,0,1);
            glTranslatef(0.2, 0,0);
            drawUpArm();
            glPushMatrix();
                glTranslatef(0.12, 0, 0);
                glRotatef(angle[2], 0,0,1);
                glTranslatef(0.2, 0,0);
                drawDownArm();
                glPushMatrix();
                    glTranslatef(0.2, 0, 0);
                    glRotatef(angle[5], 0,1,0);
                    glTranslatef(0, 0,0);
                    drawHand();
                    glPushMatrix();
                        glTranslatef(0.01, 0.04, 0);
                        glRotatef(angle[7], 0,1,0);
                        glTranslatef(0.05, 0,0);
                        drawFinger();
                    glPopMatrix();
                    glPushMatrix();
                        glTranslatef(0.01, 0.013, 0);
                        glRotatef(angle[7], 0,1,0);
                        glTranslatef(0.05, 0,0);
                        drawFinger();
                    glPopMatrix();
                    glPushMatrix();
                        glTranslatef(0.01, -0.014, 0);
                        glRotatef(angle[7], 0,1,0);
                        glTranslatef(0.05, 0,0);
                        drawFinger();
                    glPopMatrix();
                    glPushMatrix();
                        glTranslatef(0.01, -0.04, 0);
                        glRotatef(angle[7], 0,1,0);
                        glTranslatef(0.05, 0,0);
                        drawFinger();
                    glPopMatrix();
                glPopMatrix();
            glPopMatrix();
        glPopMatrix();
        glPushMatrix();
            glTranslatef(-0.1, 0.1, 0);
            glRotatef(-angle[3], 0,0,1);
            glTranslatef(-0.2, 0,0);
            drawUpArm();
            glPushMatrix();
                glTranslatef(-0.12, 0, 0);
                glRotatef(-angle[4], 0,0,1);
                glTranslatef(-0.2, 0,0);
                drawDownArm();

                glPushMatrix();
                    glTranslatef(-0.2, 0, 0);
                    glRotatef(-angle[6], 0,1,0);
                    glTranslatef(0, 0,0);
                    drawHand();
                    glPushMatrix();
                        glTranslatef(-0.01, 0.04, 0);
                        glRotatef(-angle[7], 0,1,0);
                        glTranslatef(-0.05, 0,0);
                        drawFinger();
                    glPopMatrix();
                    glPushMatrix();
                        glTranslatef(-0.01, 0.013, 0);
                        glRotatef(-angle[7], 0,1,0);
                        glTranslatef(-0.05, 0,0);
                        drawFinger();
                    glPopMatrix();
                    glPushMatrix();
                        glTranslatef(-0.01, -0.014, 0);
                        glRotatef(-angle[7], 0,1,0);
                        glTranslatef(-0.05, 0,0);
                        drawFinger();
                    glPopMatrix();
                    glPushMatrix();
                        glTranslatef(-0.01, -0.04, 0);
                        glRotatef(-angle[7], 0,1,0);
                        glTranslatef(-0.05, 0,0);
                        drawFinger();
                    glPopMatrix();
                glPopMatrix();

            glPopMatrix();
        glPopMatrix();
    glPopMatrix();
    drawDownBody();
    glFlush();
}
void motion(int x, int y)
{   angle[now] -= y - oldY;
    oldY=y; oldX=x;
    if(fout==NULL) fout=fopen("a.txt","w+");
    {
        for(int i=0; i<48 ;i++)
        {
            fprintf(fout,"%.1f\t",angle[i]);
        }
        fprintf(fout,"\n");
    }
}
void mouse(int button, int state, int x, int y){
    if(state==GLUT_DOWN) { oldX=x; oldY=y; }
}
void timer(int t)
{
    glutTimerFunc(20, timer, t+1);
    //angle++;
    glutPostRedisplay();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("T-R-T test");
    glutDisplayFunc(display);
    glutTimerFunc(20, timer, 0);
    glutMouseFunc(mouse);
    glutKeyboardFunc(keyboard);
    glutMotionFunc(motion);
    glutMainLoop();
}


2015年5月27日 星期三

00370915 蔡昀佑 Computer Graphics Week14 - T-R-T local rotate

ToDo1:
     先畫出一個茶壺
ToDo2:
     茶壺位移
ToDo3:
     旋轉(會以中心轉)
 ToDo4:
     再位移並在原位置顯示做為身體會呈現有關節感
ToDo5:
     換成長方體
ToDo6:
     增加手臂
ToDo6:
     增加另一邊


2015年5月20日 星期三

00370915 蔡昀佑 Computer Graphics Week13 - Ortho & Prespective

ToDo1:
    看jsyeh.org/3dcg10

     下載Viewing in 3D
     PDF檔ToDo2:
    課本範例 

   Projection.exe
   gluLookAt(eye x y z
                      center x y z
                      up x y z)
   Perspective(fovy,aspect,znear,zfar);
   Ortho(左,右,下,上,近,遠);



2015年5月13日 星期三

00370915 蔡昀佑 Computer Graphics Week12 - Import 3D maya model

ToDo1:
    跑範例
ToDo2:
    今天glm.c有6行讀入3D模型(glm....)
ToDo3:
    試著做
    (1) new - Project - GLUT
    (2) 把 source.zip 的 glm.h 和 glm.cpp 放資料夾
    (3) 寫6行 Code 
     #include "glm.h"

     GLMmodel * pmodel = NULL;
     pmodel = glmReadOBJ("porsche.obj");
     glmUnitize(pmodel);
     glmFacetNormals(pmodel);

     glmVertexNormals(pmodel , 90.0);
ToDo4:
    Rebuild 技巧
ToDo5:
    glut 的頭尾

ToDo4:
    打光加進去(4行):
    GLfloat pos[] = {0.0 , 0.0 , -1.0, 0.0};
    glLightfv(GL_LIGHT0, GL_POSITION,pos);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);



2015年5月6日 星期三

00370915 蔡昀佑 Computer Graphics Week11 - Make a little game part3

ToDo1:
    下載freeglut並解壓
    下載OpenCV2.1並安裝
ToDo2:
    上周Project設定
          (A)Compiler的include
          (B)Linker的lib
          (C)Link參數
ToDo3:
    會轉動的地球
ToDo4:
    設定Timer
    (1)glutTimerFunc(2000,timer,0);
    (2)void timer(int t)
       {
            glutTimerFunc(20,timer,0);
            glutPostRedisplay();
       }

ToDo5:
    憤怒的茶壺
    利用Timer對茶壺運動
    設定狀態鎖設定茶壺運動種類
    置入mouse跟motion函式抓取滑鼠座標
    狀態0 = 靜止不動
    狀態1 = 跟隨滑鼠拖曳
    狀態2 = 反拖曳的方向做彈出


2015年4月29日 星期三

00370915 蔡昀佑 Computer Graphics Week10 - Make a little game part2 (Texture Test)

ToDo1:
    下載OpenCV2.1,並安裝。
ToDo2:
    設定OpenCV
       (1) File-New-Project.
           (貝殼.Console Applocation)
       (2)Project-Build設定

            Directories:
                Compile -> C:\OpenCV2.1\include

                Link  -> C:\OpemCV2.1\lib

            Link:
                cv210
                cxcore210
                highgui210

           專案中放入
                cv210.dll
                cxcore210.dll
                highgui210.dll

       (3)測試程式(秀圖)
                #include<opencv/highgui.h>
                int main()
                {
                     IplImage * img = cvLoad
                }
ToDo3:
   設定OpenGL
       (1)Project-Build設定

            Directories:
                Compile -> C:\Users\USER\Desktop\freegult\include
                Link  -> C:\Users\USER\Desktop\freegult\lib

            Link:
                freeglut (要最先加)
                opengl32
                glu32
                gdi32
                winmm

           專案中放入
                freeglut.dll

       (2)測試程式(同時秀3D與2D圖)
ToDo4:
       合併2D貼圖於3D模組中





2015年4月15日 星期三

2015年4月8日 星期三

00370915 蔡昀佑 Computer Graphics Week7 - Mouse、Keyboard、UI

ToDo1:Keyboard函式運用 使輸出顯示出 鍵盤的輸入值

ToDo2:Mouse函式運用 加入音效使滑鼠觸發後發出聲音
音樂函式:PlaySound("檔名",NULL,執行方式)
執行方式:SND_ASYNC 同步撥放
                 SND_SYNC    非同步撥放
標頭檔 #include<mmsystem.h>




2015年3月25日 星期三

00370915 蔡昀佑 Computer Graphics Week5 - drawing a flight、roate by mouse

ToDo1: 畫出一個方形

ToDo2:畫面自動轉
     glutIdleFunc(display); ///沒事一直呼叫display函式
ToDo3:用glBegin(GL_POLYGON);
     及glBegin(GL_QUAD_STRIP);
     畫出長條形
ToDo4:glutMotionFunc(motion);
     mouse的motion來轉動
     截圖可能看不出差異,所以多給長條形畫外邊分離面的辨別模糊





2015年3月18日 星期三

00370915 蔡昀佑 Computer Graphics Week4 - Translate、Rotate、Scale

課堂筆記:

Translate(移動)
係數(x,y,z)以符點數表示數值
**要先備份再還原


Rotate(旋轉)
係數(angle,x,y,z) angle為旋轉角度 x,y,z為旋轉軸方向分量
**要清畫面
想要連續執行旋轉需要以glutIdleFunc()呼叫函式



2015年3月4日 星期三

00370915 蔡昀佑 Computer Graphics Week2 - draw a teacup

只用一點點的程式碼就能畫出一個茶壺真是不可思議呢! 不過為甚麼畫茶壺是內建的呢?