顯示具有 04160622_林承諺 標籤的文章。 顯示所有文章
顯示具有 04160622_林承諺 標籤的文章。 顯示所有文章

2017年6月30日 星期五

2017年6月12日 星期一

Week 14 承諺的上課筆記

程式碼

#include <opencv/highgui.h> ///for cvLoadImage()
#include <opencv/cv.h> ///for cvCvtColor()
#include <GL/glut.h> ///3D glut
#include <stdio.h>
GLUquadric * quad;
GLuint id;
float angle=0;
void display()
{   glEnable(GL_DEPTH_TEST); ///要啟動 Detph Test 深度值的測試,3D顯示才正確
    glClear(GL_COLOR_BUFFER_BIT  | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();///自動轉很帥
        glRotatef(90, 1,0,0);
        glRotatef(angle, 0,0,1);///自動轉很帥
        gluQuadricTexture(quad, 1);
        gluSphere(quad, 1, 30, 30);///glutSolidTeapot(0.3);
    glPopMatrix();///自動轉很帥
    glFlush();
}
void timer(int t)
{   glutTimerFunc(20, timer, 0);/// 1000 msec   50fps:20msec
    angle+=1;///自動轉很帥
    glutPostRedisplay();
}
int myTexture(char *filename)
{
    IplImage * img = cvLoadImage(filename); ///OpenCV讀圖
    cvCvtColor(img,img, CV_BGR2RGB); ///OpenCV轉色彩 (需要cv.h)
    glEnable(GL_TEXTURE_2D); ///1. 開啟貼圖功能
    GLuint id; ///準備一個 unsigned int 整數, 叫 貼圖ID
    glGenTextures(1, &id); /// 產生Generate 貼圖ID
    glBindTexture(GL_TEXTURE_2D, id); ///綁定bind 貼圖ID
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); /// 貼圖參數, 超過包裝的範圖T, 就重覆貼圖
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); /// 貼圖參數, 超過包裝的範圖S, 就重覆貼圖
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); /// 貼圖參數, 放大時的內插, 用最近點
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); /// 貼圖參數, 縮小時的內插, 用最近點
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img->width, img->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img->imageData);
    return id;
}

void myInit()
{   quad = gluNewQuadric();
    id = myTexture("image.jpg");
}
int main(int argc, char**argv)
{   glutInit(&argc, argv);
    glutCreateWindow("3D");
    glutDisplayFunc(display); ///顯示
    glutTimerFunc(0, timer, 0);
    myInit(); ///我的 init 初始化 把貼圖準備好 前面OpenCV 2行, 後面 OpenGL 9行
    glutMainLoop();
}

2017年6月5日 星期一

Week 13 承諺的上課筆記

  一.內差公式(交叉相乘)
   

  設A為未知數
  A *新 +(1 - A) *舊

  

  二.內插法帶入圖片

  
  

   程式碼

#include <string.h>
#include <stdlib.h>
#include <GL/glut.h>
#include "glm.h"
GLMmodel* pmodel1 = NULL;
GLMmodel* pmodel2 = NULL;
GLMmodel* pmodel3 = NULL;
GLMmodel* pmodel4 = NULL;
GLMmodel* pmodel5 = NULL;
GLMmodel* pmodel6 = NULL;
GLMmodel* pmodel7 = NULL;
GLMmodel* pmodel8 = NULL;
GLMmodel* pmodel9 = NULL;
GLMmodel* pmodel10 = NULL;
GLMmodel* pmodel11 = NULL;
float angle[9]={},dir=1;
float alpha=0.0;
float oldAngle[9]={0,0,0,0,0,0,0,0,0};
float newAngle[9]={40,40,-40,-40,0,0,0,0,0};
void interpolation()
{
    for(int i=0;i<9;i++)
    {
        angle[i] = alpha *newAngle[i] + (1-alpha)*oldAngle[i];
    }
    alpha +=0.1;
}
int now=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(180,0,1,0);
        if (!pmodel1) {
        pmodel1 = glmReadOBJ("data/body.obj");
        if (!pmodel1) exit(0);
        glmUnitize(pmodel1);
        glmFacetNormals(pmodel1);
        glmVertexNormals(pmodel1, 90.0);
        }

        if (!pmodel2) {
        pmodel2 = glmReadOBJ("data/head.obj");
        if (!pmodel2) exit(0);
        glmUnitize(pmodel2);
        glmFacetNormals(pmodel2);
        glmVertexNormals(pmodel2, 90.0);
        }

        if (!pmodel3) {
        pmodel3 = glmReadOBJ("data/leftelbow.obj");
        if (!pmodel3) exit(0);
        glmUnitize(pmodel3);
        glmFacetNormals(pmodel3);
        glmVertexNormals(pmodel3, 90.0);
        }

        if (!pmodel4) {
        pmodel4 = glmReadOBJ("data/rightelbow.obj");
        if (!pmodel4) exit(0);
        glmUnitize(pmodel4);
        glmFacetNormals(pmodel4);
        glmVertexNormals(pmodel4, 90.0);
        }

        if (!pmodel5) {
        pmodel5 = glmReadOBJ("data/leftarm.obj");
        if (!pmodel5) exit(0);
        glmUnitize(pmodel5);
        glmFacetNormals(pmodel5);
        glmVertexNormals(pmodel5, 90.0);
        }

        if (!pmodel6) {
        pmodel6 = glmReadOBJ("data/rightarm.obj");
        if (!pmodel6) exit(0);
        glmUnitize(pmodel6);
        glmFacetNormals(pmodel6);
        glmVertexNormals(pmodel6, 90.0);
        }

        if (!pmodel7) {
        pmodel7 = glmReadOBJ("data/leftthigh.obj");
        if (!pmodel7) exit(0);
        glmUnitize(pmodel7);
        glmFacetNormals(pmodel7);
        glmVertexNormals(pmodel7, 90.0);
        }

        if (!pmodel8) {
        pmodel8 = glmReadOBJ("data/rightthigh.obj");
        if (!pmodel8) exit(0);
        glmUnitize(pmodel8);
        glmFacetNormals(pmodel8);
        glmVertexNormals(pmodel8, 90.0);
        }

        if (!pmodel9) {
        pmodel9 = glmReadOBJ("data/leftcalf.obj");
        if (!pmodel9) exit(0);
        glmUnitize(pmodel9);
        glmFacetNormals(pmodel9);
        glmVertexNormals(pmodel9, 90.0);
        }

        if (!pmodel10) {
        pmodel10 = glmReadOBJ("data/leftcalf.obj");
        if (!pmodel10) exit(0);
        glmUnitize(pmodel10);
        glmFacetNormals(pmodel10);
        glmVertexNormals(pmodel10, 90.0);
        }

        if (!pmodel11) {
        pmodel11 = glmReadOBJ("data/eye.obj");
        if (!pmodel11) exit(0);
        glmUnitize(pmodel11);
        glmFacetNormals(pmodel11);
        glmVertexNormals(pmodel11, 90.0);
        }
        glPushMatrix();///身體
            ///angle[now]+=dir*0.1;///
            ///if(angle[now]>90) dir=-dir;
            ///if(angle[now]<0) dir=-dir;
            glTranslatef(0,0.15,0);
            glScalef(0.7,0.7,0.7);
            glmDraw(pmodel1, GLM_SMOOTH | GLM_MATERIAL);

            glPushMatrix();///頭
                glTranslatef(0,0.675,0);
                glScalef(1.3,1.3,1.3);
                glmDraw(pmodel2, GLM_SMOOTH | GLM_MATERIAL);
            glPopMatrix();

            glPushMatrix();///右上臂
                glTranslatef(0.2,0.4,0);
                glRotatef(angle[0]*1.5 , 0,0,1);
                glTranslatef(0.2,-0.3,0);
                glScalef(0.8,0.8,0.8);
                glmDraw(pmodel3, GLM_SMOOTH | GLM_MATERIAL);

                glPushMatrix();///右下臂
                    glTranslatef(0.1,-0.2,0);
                    glRotatef(angle[1]*2, 0,0,1);
                    glTranslatef(0,-0.4,0);
                    glScalef(0.75,0.8,0.75);
                    glmDraw(pmodel5, GLM_SMOOTH | GLM_MATERIAL);
                glPopMatrix();

            glPopMatrix();

            glPushMatrix();///左上臂
                glTranslatef(-0.2,0.4,0);
                glRotatef(-angle[2]*1.5, 0,0,1);
                glTranslatef(-0.2,-0.3,0);
                glScalef(0.8,0.8,0.8);
                glmDraw(pmodel4, GLM_SMOOTH | GLM_MATERIAL);

                glPushMatrix();///左下臂
                    glTranslatef(-0.2,-0.275,0);
                    glRotatef(-angle[3]*2, 0,0,1);
                    glTranslatef(0,-0.3,0);
                    glScalef(0.7,0.8,0.7);
                    glmDraw(pmodel6, GLM_SMOOTH | GLM_MATERIAL);
                glPopMatrix();

            glPopMatrix();

            glPushMatrix();///左大腿
                glTranslatef(0.2,-0.35,0);
                glRotatef(angle[5] , 0,0,1);
                glTranslatef(0,-0.3,0);
                glScalef(0.4,0.4,0.4);
                glmDraw(pmodel7, GLM_SMOOTH | GLM_MATERIAL);

                glPushMatrix();///左小腿
                    glTranslatef(0.5,-1.4,0);
                    glRotatef(angle[6]*0.08 , 0,0,1);
                    glTranslatef(-0.4,0.8,0);
                    glScalef(0.55,0.55,0.55);
                    glmDraw(pmodel9, GLM_SMOOTH | GLM_MATERIAL);
                glPopMatrix();

            glPopMatrix();

            glPushMatrix();///右大腿
                glTranslatef(-0.2,-0.35,0);
                glRotatef(-angle[7] , 0,0,1);
                glTranslatef(0,-0.3,0);
                glScalef(0.4,0.4,0.4);
                glmDraw(pmodel8, GLM_SMOOTH | GLM_MATERIAL);

                glPushMatrix();///右小腿
                    glTranslatef(-0.5,-1.4,0);
                    glRotatef(-angle[8]*0.08 , 0,0,1);
                    glTranslatef(0.4,0.8,0);
                    glScalef(0.55,0.55,0.55);
                    glmDraw(pmodel10, GLM_SMOOTH | GLM_MATERIAL);
                glPopMatrix();

            glPopMatrix();

            glPushMatrix();///眼
                glTranslatef(0,0.675,0.1);
                glScalef(1.3,1.3,1.3);
                glmDraw(pmodel11, GLM_SMOOTH | GLM_MATERIAL);
            glPopMatrix();
        glPopMatrix();



    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 };

void timer(int t)
{
    glutTimerFunc(1000,timer,t+1);
    interpolation();
    glutPostOverlayRedisplay();
}
int oldX=0,oldY=0;
#include <stdio.h>///寫檔案的第1行
FILE * fout=NULL;///寫檔案的第2行, 空空的
FILE * fin=NULL;///read讀檔案的第1行
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=='s' || key=='S'){
    if(fout==NULL){///寫檔案的第3行, 如果是空的,第一次寫檔
            fout=fopen("file.txt", "w+");///寫檔案的第4行, 真的去開檔案
            printf("現在我產生一個file.txt的檔案在目錄裡面哦\n");
    }
        fprintf(fout, "%.3f %.3f %.3f %.3f %.3f\n", angle[0],angle[1],angle[2],angle[3],angle[4]);///寫檔案的第5行
        printf("現在我把一些數字印到檔案裡面%.3f %.3f %.3f %.3f %.3f\n",
               angle[0],angle[1],angle[2],angle[3],angle[4]);
    }
    if(key=='r' || key=='R'){
        if(fin==NULL){///read讀檔案的第2行
            fin=fopen("file.txt", "r");///read讀檔案的第3行
        }
        fscanf(fin, "%f %f %f %f %f", &angle[0], &angle[1], &angle[2], &angle[3], &angle[4]);///read讀檔案的第4行
        glutPostRedisplay();///read讀檔案後, 要重畫畫面
    }
}
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();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB);
    glutInitWindowSize(500,500);
    glutCreateWindow("04160391");

    glutDisplayFunc(display);
    glutIdleFunc(display);
    glutTimerFunc(0,timer,0);
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);

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

2017年5月22日 星期一

Week 12 承諺的上課筆記

   一.計時器

   

   二.調整手臂軸心

   
   
   

   三.設定另一隻上手臂

   

   

   程式碼

#include <string.h>
#include <stdlib.h>
#include <GL/glut.h>
#include "glm.h"

GLMmodel* pmodel[10] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
/*此為宣告模型變數*/

float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    if (!pmodel[0])
    {
        pmodel[0] = glmReadOBJ("data/body.obj");
        if (!pmodel[0]) exit(0);
        glmUnitize(pmodel[0]);
        glmFacetNormals(pmodel[0]);
        glmVertexNormals(pmodel[0], 90.0);
    }
    if (!pmodel[1])
    {
        pmodel[1] = glmReadOBJ("data/head.obj");
        if (!pmodel[1]) exit(0);
        glmUnitize(pmodel[1]);
        glmFacetNormals(pmodel[1]);
        glmVertexNormals(pmodel[1], 90.0);
    }
    if (!pmodel[2])
    {
        pmodel[2] = glmReadOBJ("data/left_arm_up.obj");
        if (!pmodel[2]) exit(0);
        glmUnitize(pmodel[2]);
        glmFacetNormals(pmodel[2]);
        glmVertexNormals(pmodel[2], 90.0);
    }
    if (!pmodel[3])
    {
        pmodel[3] = glmReadOBJ("data/left_arm_down.obj");
        if (!pmodel[3]) exit(0);
        glmUnitize(pmodel[3]);
        glmFacetNormals(pmodel[3]);
        glmVertexNormals(pmodel[3], 90.0);
    }

    if (!pmodel[4])
    {
        pmodel[4] = glmReadOBJ("data/right_arm_up.obj");
        if (!pmodel[4]) exit(0);
        glmUnitize(pmodel[4]);
        glmFacetNormals(pmodel[4]);
        glmVertexNormals(pmodel[4], 90.0);
    }

     if (!pmodel[5])
    {
        pmodel[5] = glmReadOBJ("data/right_arm_down.obj");
        if (!pmodel[5]) exit(0);
        glmUnitize(pmodel[5]);
        glmFacetNormals(pmodel[5]);
        glmVertexNormals(pmodel[5], 90.0);
    }

    if (!pmodel[6])
    {
        pmodel[6] = glmReadOBJ("data/left_leg_up.obj");
        if (!pmodel[6]) exit(0);
        glmUnitize(pmodel[6]);
        glmFacetNormals(pmodel[6]);
        glmVertexNormals(pmodel[6], 90.0);
    }

    if (!pmodel[7])
    {
        pmodel[7] = glmReadOBJ("data/left_leg_down.obj");
        if (!pmodel[7]) exit(0);
        glmUnitize(pmodel[7]);
        glmFacetNormals(pmodel[7]);
        glmVertexNormals(pmodel[7], 90.0);
    }

    if (!pmodel[8])
    {
        pmodel[8] = glmReadOBJ("data/right_leg_up.obj");
        if (!pmodel[8]) exit(0);
        glmUnitize(pmodel[8]);
        glmFacetNormals(pmodel[8]);
        glmVertexNormals(pmodel[8],90.0);
    }

    if (!pmodel[9])
    {
        pmodel[9] = glmReadOBJ("data/right_leg_down.obj");
        if (!pmodel[9]) exit(0);
        glmUnitize(pmodel[9]);
        glmFacetNormals(pmodel[9]);
        glmVertexNormals(pmodel[9],90.0);
    }
    /*此為匯入模型檔的動作,medel變數可做修改*/
    glPushMatrix();
        //glRotatef(angle, 0,1,0);

        glPushMatrix();///head
            glTranslatef(0,0,0);
            glRotatef(180,0,1,0);
            glRotatef(10,1,0,0);
            glTranslatef(0,0.65,0);
            glScalef(0.7,0.7,0.7);
            glmDraw(pmodel[1], GLM_SMOOTH | GLM_MATERIAL);
        glPopMatrix();

        glPushMatrix(); ///body
            glPushMatrix();
                glTranslatef(0,0,0);
                glRotatef(180,0,1,0);
                glScalef(0.4,0.4,0.4);
                glmDraw(pmodel[0], GLM_SMOOTH | GLM_MATERIAL);///body
            glPopMatrix();

            glPushMatrix();
                glTranslatef(0.21, 0.3, 0);
                glRotatef(angle, 0,0,1);
                glTranslatef(-0.21, -0.3, 0);
                glPushMatrix();///left_arm_up
                    glTranslatef(0.1,0,0);
                    glRotatef(20,0,1,0);
                    glTranslatef(0.17 ,0.15,0);
                    glScalef(0.27,0.27,0.27);
                    glmDraw(pmodel[2], GLM_SMOOTH | GLM_MATERIAL);
                glPopMatrix();

                glTranslatef(0.35, 0, 0);
                glRotatef(angle, 0,0,1);
                glTranslatef(-0.35, 0, 0);
                glPushMatrix(); ///left_arm_down
                    glTranslatef(0.1,0,0);
                    glRotatef(20,0,1,0);
                    glScalef(0.4,0.4,0.4);
                    glTranslatef(0.79,-0.35,0);
                    glmDraw(pmodel[3], GLM_SMOOTH | GLM_MATERIAL);
                glPopMatrix();
            glPopMatrix();

            glPushMatrix();///for test
                glTranslatef(-0.17 ,+0.2,0);
                glRotatef(-angle, 0,0,1);///先做旋轉看看
                glTranslatef(0.17 ,-0.2,0);///move rotation center to center
                glPushMatrix();///right_arm_up
                    glTranslatef(0.1,0,0);
                    glRotatef(-15,0,1,0);
                    glTranslatef(-0.35,0.15,0.15);
                    glScalef(0.27,0.27,0.27);
                    glmDraw(pmodel[4], GLM_SMOOTH | GLM_MATERIAL);
                glPopMatrix();

            glPopMatrix();

        glPopMatrix();



        glPushMatrix();///right_arm_down
            glTranslatef(0.1,0,0);
            glRotatef(-20,0,1,0);
            glTranslatef(-0.58,-0.14,-0.1);
            glScalef(0.4,0.4,0.4);
            glmDraw(pmodel[5], GLM_SMOOTH | GLM_MATERIAL);
        glPopMatrix();

        glPushMatrix();///left_leg_up
            glTranslatef(0,0,0);
            glRotatef(0,0,0,0);
            glTranslatef(0.12,-0.42,-0);
            glScalef(0.28,0.28,0.28);
            glmDraw(pmodel[6], GLM_SMOOTH | GLM_MATERIAL);
        glPopMatrix();

        glPushMatrix();///left_leg_down
            glTranslatef(0,0,0);
            glRotatef(0,0,0,0);
            glTranslatef(0.12,-0.63,-0);
            glScalef(0.45,0.56,0.43);
            glmDraw(pmodel[7], GLM_SMOOTH | GLM_MATERIAL);
        glPopMatrix();

        glPushMatrix();///right_leg_up
            glTranslatef(0,0,0);
            glRotatef(0,0,0,0);
            glTranslatef(-0.12,-0.42,-0);
            glScalef(0.28,0.28,0.28);
            glmDraw(pmodel[8], GLM_SMOOTH | GLM_MATERIAL);
        glPopMatrix();

        glPushMatrix();///right_leg_down
            glTranslatef(0,0,0);
            glRotatef(0,0,0,0);
            glTranslatef(-0.12,-0.63,-0);
            glScalef(0.45,0.56,0.43);
            glmDraw(pmodel[9], GLM_SMOOTH | GLM_MATERIAL);
        glPopMatrix();

        /*此為對匯入模型檔作變形並顯示在視窗介面的動作*/

    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[] = { -3.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 };
#include <stdio.h>
void timer(int t)///計時器叫的時候, 要做什麼呢?
{
    glutTimerFunc(100, timer, t+1);///先撥下一個鬧鐘
    angle++;///做了要做的事
    printf("現在時間是 %d, 我起床了, 等一下鬧鐘會再叫一下哦  ", t);
    glutPostRedisplay();///提醒電腦,有空要畫一下畫面哦
    printf("... 然後我就又睡了....\n");
}///再度沈睡
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB);
    glutCreateWindow("04160152_rb");

    glutDisplayFunc(display);
    glutIdleFunc(display);
    glutTimerFunc(0, timer, 0);///(1) 第一次呼叫timer計時器

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

2017年5月15日 星期一

Week 11 承諺的上課筆記

   一.小考
   
 
   glPushMatrix();
glTranslatef(0.4,-1.0,0);
glRotatef(angle,0,0,1);
glTranslatef(0.2,-0.5,0);
drawLeg();
   glPopMatrix();

   
 
   glPushMatrix();
glTranslatef(-0.5,0.35,0);
glRotatef(-angle,0,0,1);
glTranslatef(-0.3,0,0);
drawArm();
   glPopMatrix();

   二.OpenCV
 
   1.開照片
   
   

   三.Opencv設定

   
   
   
   
   
   

   四.讓打開地球而且選轉

   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
 
   五.把茶壺印出來

   

2017年5月8日 星期一

Week 10 承諺的上課筆記

   一.攝影機運鏡(由左而右運鏡)

   

   二.茶壺運鏡

   
   
   

   三.讓茶壺轉動

   
   
   

   四.(fovy視野大小,aspect視野寬窄,鏡頭遠近,背景遠近)
        (eye攝影機位置,center目標位置,up攝影機擺放角度)
   

   五.攝影機旋轉不破圖

   

   六.TRT(會考)