顯示具有 06160291_温鎮瑋 標籤的文章。 顯示所有文章
顯示具有 06160291_温鎮瑋 標籤的文章。 顯示所有文章

2019年5月31日 星期五

瑋的日常筆記week15

5/31天氣晴
今日主題:
1.攝影機,運鏡
2.投影矩陣
3.位置移動轉移
4.背景貼圖

先去下載data,window及glut32.dll
然後將glut32跟data放入window。
就可以開啟下面的東西。

上面是教學內容。

然後還要下載source去將裡面的

這三個移動出來放入freeglut裡面
並且將glm.c變成glm.cpp
之後開啟專案即可,之後addfile將glm.cpp加入專案中

然後開啟後將下面程式碼
覆蓋main.cpp
#include <GL/glut.h>
#include "glm.h" ///for glmReadOBJ(), glmDraw(), glmUnitized()....
GLMmodel * pmodel=NULL;///NOW
void drawmodel(void)///放入OBJ檔案的程式碼
{
    if (!pmodel) {
pmodel = glmReadOBJ("data/al.obj");
if (!pmodel) exit(0);
glmUnitize(pmodel);
glmFacetNormals(pmodel);
glmVertexNormals(pmodel, 90.0);
    }
    glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
}
void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    drawmodel();
    glutSwapBuffers();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(500,500);
    glutCreateWindow("week15");
    glutDisplayFunc(display);

    glutMainLoop();
}
之後會變成這個樣子

接下來增加打光效果
#include <GL/glut.h>
#include "glm.h" ///for glmReadOBJ(), glmDraw(), glmUnitized()....
GLMmodel * pmodel=NULL;///NOW
void drawmodel(void)
{
    if (!pmodel) {
pmodel = glmReadOBJ("data/al.obj");
if (!pmodel) exit(0);
glmUnitize(pmodel);
glmFacetNormals(pmodel);
glmVertexNormals(pmodel, 90.0);
    }
    glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
}
void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    drawmodel();
    glutSwapBuffers();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(500,500);
    glutCreateWindow("week15");

    glutDisplayFunc(display);

    GLfloat light_pos[] = { 0.0, 0.0, -1.0, 0.0 };///NOW2 打光的位置
    ///上面是-1.0是因為我們光打要是背面才用1.0
    glEnable(GL_DEPTH_TEST);///NOW2 有立體的功能
    glEnable(GL_LIGHT0);    ///NOW2 打光後變立體的彩色的
    glEnable(GL_LIGHTING);  ///NOW2 打光後變立體的彩色的
    glLightfv(GL_LIGHT0, GL_POSITION, light_pos);///NOW2 打光的位置
    ///上面是增加的打光效果。
    glutMainLoop();
}
變成下面這樣
接下來要讓他可以去360度的移動
下面是程式碼

#include <GL/glut.h>
#include "glm.h" ///for glmReadOBJ(), glmDraw(), glmUnitized()....
GLMmodel * pmodel=NULL;///NOW
void drawmodel(void)
{
    if (!pmodel) {
pmodel = glmReadOBJ("data/al.obj");
if (!pmodel) exit(0);
glmUnitize(pmodel);
glmFacetNormals(pmodel);
glmVertexNormals(pmodel, 90.0);
    }
    glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
}
void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    drawmodel();
    glutSwapBuffers();
}
#include <math.h>
float eyeX=1, eyeY=0, eyeZ=0;
void timer(int t)///NOW3
{
    ///t+1讓他一直去旋轉
    glutTimerFunc(33, timer, t+1);///NOW3
    float angle=t/180.0*3.1415926;///NOW3 算出一個角度
    eyeX=cos(angle); eyeZ=sin(angle);///NOW3


    glMatrixMode(GL_MODELVIEW);///NOW3
    glLoadIdentity();///NOW3
    gluLookAt(eyeX, eyeY, eyeZ, ///NOW3 LookAt的 eye
              0.0, 0.8, 0.0, ///NOW3 LookAt的 center
              0, 1, 0);///NOW3 LookAt的 up

    glutPostRedisplay();///NOW3 Re-display
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(500,500);
    glutCreateWindow("week15");

    glutDisplayFunc(display);
    glutTimerFunc(33, timer, 0);///NOW3

    GLfloat light_pos[] = { 0.0, 0.0, -1.0, 0.0 };///NOW2 打光的位置
    glEnable(GL_DEPTH_TEST);///NOW2 有立體的功能
    glEnable(GL_LIGHT0);    ///NOW2 打光後變立體的彩色的
    glEnable(GL_LIGHTING);  ///NOW2 打光後變立體的彩色的
    glLightfv(GL_LIGHT0, GL_POSITION, light_pos);///NOW2 打光的位置

    glutMainLoop();
}
可是放出來的模型會破圖
變成下面那樣
因此要增加程式碼來讓他
不會因此而破圖,要將程式碼放在NOW3的中間

#include <GL/glut.h>
#include "glm.h" ///for glmReadOBJ(), glmDraw(), glmUnitized()....
GLMmodel * pmodel=NULL;///NOW
void drawmodel(void)
{
    if (!pmodel) {
pmodel = glmReadOBJ("data/al.obj");
if (!pmodel) exit(0);
glmUnitize(pmodel);
glmFacetNormals(pmodel);
glmVertexNormals(pmodel, 90.0);
    }
    glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
}
void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    drawmodel();
    glutSwapBuffers();
}
#include <math.h>
float eyeX=1, eyeY=0, eyeZ=0;
void timer(int t)///NOW3
{
    glutTimerFunc(33, timer, t+1);///NOW3
    float angle=t/180.0*3.1415926;///NOW3 算出一個角度
    eyeX=cos(angle); eyeZ=sin(angle);///NOW3

    glMatrixMode(GL_PROJECTION);///NOW4
    glLoadIdentity();///NOW4
glOrtho(-1,+1, -1,+1, -10,+10);///NOW4 可以看到範圍比較大的投影法
       上面這一段程式碼是很重要的如果破圖了要使用這個
    glMatrixMode(GL_MODELVIEW);///NOW3
    glLoadIdentity();///NOW3
    gluLookAt(eyeX, eyeY, eyeZ, ///NOW3 LookAt的 eye
              0.0, 0.6, 0.0, ///NOW3 LookAt的 center
              0, 1, 0);///NOW3 LookAt的 up

    glutPostRedisplay();///NOW3 Re-display
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(500,500);
    glutCreateWindow("week15");

    glutDisplayFunc(display);
    glutTimerFunc(33, timer, 0);///NOW3

    GLfloat light_pos[] = { 0.0, 0.0, 1.0, 0.0 };///NOW2 打光的位置
    glEnable(GL_DEPTH_TEST);///NOW2 有立體的功能
    glEnable(GL_LIGHT0);    ///NOW2 打光後變立體的彩色的
    glEnable(GL_LIGHTING);  ///NOW2 打光後變立體的彩色的
    glLightfv(GL_LIGHT0, GL_POSITION, light_pos);///NOW2 打光的位置

    glutMainLoop();
}
就會變成這個樣子
概念是從這裡出來的

然而有兩個可以放大縮小的鏡頭
一樣放在NOW3的裡面
NOW4跟NOW5兩著選一個
都可以去完成運鏡的效果

#include <GL/glut.h>
#include "glm.h" ///for glmReadOBJ(), glmDraw(), glmUnitized()....
GLMmodel * pmodel=NULL;///NOW
void drawmodel(void)
{
    if (!pmodel) {
pmodel = glmReadOBJ("data/al.obj");
if (!pmodel) exit(0);
glmUnitize(pmodel);
glmFacetNormals(pmodel);
glmVertexNormals(pmodel, 90.0);
    }
    glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
}
void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    drawmodel();
    glutSwapBuffers();
}
#include <math.h>
float eyeX=1, eyeY=0, eyeZ=0;
void timer(int t)///NOW3
{
    glutTimerFunc(33, timer, t+1);///NOW3
    float angle=t/180.0*3.1415926;///NOW3 算出一個角度
    eyeX=cos(angle); eyeZ=sin(angle);///NOW3

    glMatrixMode(GL_PROJECTION);///NOW4
    glLoadIdentity();///NOW4
    gluPerspective(120, 1, 0.001, 1000);///NOW5
///glOrtho(-1,+1, -1,+1, -10,+10);///NOW4 可以看到範圍比較大的投影法

    glMatrixMode(GL_MODELVIEW);///NOW3
    glLoadIdentity();///NOW3
    gluLookAt(eyeX, eyeY, eyeZ, ///NOW3 LookAt的 eye
              0.0, 0.6, 0.0, ///NOW3 LookAt的 center
              0, 1, 0);///NOW3 LookAt的 up

    glutPostRedisplay();///NOW3 Re-display
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(500,500);
    glutCreateWindow("week15");

    glutDisplayFunc(display);
    glutTimerFunc(33, timer, 0);///NOW3

    GLfloat light_pos[] = { 0.0, 0.0, 1.0, 0.0 };///NOW2 打光的位置
    glEnable(GL_DEPTH_TEST);///NOW2 有立體的功能
    glEnable(GL_LIGHT0);    ///NOW2 打光後變立體的彩色的
    glEnable(GL_LIGHTING);  ///NOW2 打光後變立體的彩色的
    glLightfv(GL_LIGHT0, GL_POSITION, light_pos);///NOW2 打光的位置

    glutMainLoop();
}
會變成下面這樣子



2019年5月24日 星期五

瑋的日常筆記week14

5/24天氣晴
今日程式碼開頭(TIMER)

#include <GL/glut.h>
#include <mmsystem.h>///NOW (0)發聲音
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glutSwapBuffers();
}
void timer(int t)///NOW (2)
{
    glutTimerFunc(1000, timer, 0);///NOW2
    PlaySoundA("fart.wav", NULL, SND_ASYNC);///NOW (2)
    ///上面抓音樂檔案的路徑
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(500,500);///視窗大小
    glutCreateWindow("week14 timer");///視窗標題

    glutDisplayFunc(display);
    glutTimerFunc(1000, timer, 0);///NOW (1)

    glutMainLoop();
}

第二程式碼

#include <GL/glut.h>
#include <mmsystem.h>///NOW (0)發聲音
#include <stdio.h>///NOW3 for printf()
float angle=0;///NOW4
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();///NOW4
        glRotatef(angle, 0, 0, 1);///NOW4
        glutSolidTeapot( 0.3 );///NOW4
    glPopMatrix();///NOW4
    glutSwapBuffers();
}
void timer(int t)///NOW (2)///int t是計算他跑了幾次下面就有做他跑了幾次
{
    glutTimerFunc(30, timer, t+1);///NOW4 ///NOW3 一起床,馬上撥下一個鬧鐘, 時間才會準
    printf("現在的 timer(t)的t是: %d\n", t);///NOW3
    angle = t;///NOW4
    glutPostRedisplay();///NOW4 要更新畫面
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(500,500);///大一點
    glutCreateWindow("week14 timer");

    glutDisplayFunc(display);
    glutTimerFunc(1000, timer, 0);///NOW (1)

    glutMainLoop();
}
第三組程式碼
#include <GL/glut.h>
#include <mmsystem.h>///NOW (0)發聲音
#include <stdio.h>///NOW3 for printf()
float angle=0;///NOW4
float nowX=0;///NOW5內插公式
float nowY=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();///NOW4
        ///glRotatef(angle, 0, 0, 1);///NOW4
        glTranslatef(nowX, nowY, 0);///NOW5
        glutSolidTeapot( 0.2 );///NOW4
    glPopMatrix();///NOW4
    glutSwapBuffers();
}
void timer(int t)///NOW (2)
{/// 1000 ms = 1秒,   50ms = 0.02秒 => 50*20=1000,  30fps
    glutTimerFunc(50, timer, t+1);///NOW4 ///NOW3 一起床,馬上撥下一個鬧鐘, 時間才會準
    printf("現在的 timer(t)的t是: %d\n", t);///NOW3
    float alpha = (t%50) / 50.0;///變成 alpha: 0.0 ~ 1.0  ///NOW5
    if(nowX<1&&nowX!=1){
         nowX = alpha*1.0 + (1-alpha)* -1.0;///NOW5內插公式
    }
    if(nowY<1&&nowY!=1){
        nowY = alpha*1.0 + (1-alpha)* -1.0;///NOW5內插公式
    }
    /*
    if(nowX==1){
        nowX = alpha*1.0 - (1-alpha)* -1.0;///NOW5內插公式
    }
    if(nowY==1){
        nowY = alpha*1.0 - (1-alpha)* -1.0;///NOW5內插公式
    }*/
    glutPostRedisplay();///NOW4 要更新畫面
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(500,500);///大一點
    glutCreateWindow("week14 timer");
    glutDisplayFunc(display);
    glutTimerFunc(1000, timer, 0);///NOW (1)
    glutMainLoop();
}

下面開始製作動畫
差別AFTER BEFORT
紀錄已動作的地方然後存入記事本,讓下次使用時可以調到那個位子
但是這個時候還不太能,只能先記錄檔案而已



下面是最後完成檔案
#include <stdio.h>///NOW1 for fprintf()
FILE * fout=NULL;///NOW1 for fopen() + fprintf()
FILE * fin =NULL;///NOW2 for fopen() + fscanf()
#include <GL/glut.h>
#include "glm.h"
GLMmodel* pmodel = NULL;
GLMmodel* pmodel2 = NULL;
GLMmodel* pmodel21 = NULL;
GLMmodel* pmodel3 = NULL;
GLMmodel* pmodel31 = NULL;
GLMmodel* pmodel4 = NULL;
GLMmodel* pmodel41 = NULL;
GLMmodel* pmodel5 = NULL;
GLMmodel* pmodel51 = NULL;

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

float angle[20];///NOW1
float oldAngle[20];///NOW4
float newAngle[20];///NOW4
int angleID=1;

void display(){
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    ///身體
    glPushMatrix();
        glTranslatef(0, 0.3,0 );
        glScalef(0.5,0.5,0.5);

            if (!pmodel) {
                pmodel = glmReadOBJ("data/06160451.obj");
            if (!pmodel) exit(0);
                glmUnitize(pmodel);
                glmFacetNormals(pmodel);
                glmVertexNormals(pmodel, 90.0);
            }
        glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
        ///右上臂
        glPushMatrix();
            glTranslatef(0.45,0.3,0 );
            glScalef(0.5,0.5,0.5);
            glRotatef(angle[1], 0,0,1);
            glTranslatef(0,-0.7, 0);
            if (!pmodel2) {
                pmodel2 = glmReadOBJ("data/123.obj");
            if (!pmodel2) exit(0);
                glmUnitize(pmodel2);
                glmFacetNormals(pmodel2);
                glmVertexNormals(pmodel2, 90.0);
            }
            glmDraw(pmodel2, GLM_SMOOTH | GLM_MATERIAL);

            glPushMatrix();
            glTranslatef(0,-1.1,0 );
            glScalef(1,1,1);
            glRotatef(angle[2], 0,0,1);
            glTranslatef(0,-0.7, 0);
            if (!pmodel2) {
                pmodel2 = glmReadOBJ("data/123.obj");
            if (!pmodel2) exit(0);
                glmUnitize(pmodel2);
                glmFacetNormals(pmodel2);
                glmVertexNormals(pmodel2, 90.0);
            }
            glmDraw(pmodel2, GLM_SMOOTH | GLM_MATERIAL);
            glPopMatrix();
        glPopMatrix();
        glPushMatrix();
            glTranslatef(-0.45,0.3,0 );
            glScalef(0.5,0.5,0.5);
            glRotatef(angle[3], 0,0,1);
            glTranslatef(0,-0.7, 0);
            if (!pmodel2) {
                pmodel2 = glmReadOBJ("data/123.obj");
            if (!pmodel2) exit(0);
                glmUnitize(pmodel2);
                glmFacetNormals(pmodel2);
                glmVertexNormals(pmodel2, 90.0);
            }
            glmDraw(pmodel2, GLM_SMOOTH | GLM_MATERIAL);

            glPushMatrix();
            glTranslatef(0,-1.1,0 );
            glScalef(1,1,1);
            glRotatef(angle[4], 0,0,1);
            glTranslatef(0,-0.7, 0);
            if (!pmodel2) {
                pmodel2 = glmReadOBJ("data/123.obj");
            if (!pmodel2) exit(0);
                glmUnitize(pmodel2);
                glmFacetNormals(pmodel2);
                glmVertexNormals(pmodel2, 90.0);
            }
            glmDraw(pmodel2, GLM_SMOOTH | GLM_MATERIAL);
            glPopMatrix();
        glPopMatrix();

        glPushMatrix();
            glTranslatef(0.2,-1.05,0 );
            glScalef(0.5,0.5,0.5);
            glRotatef(angle[5], 0,0,1);
            glTranslatef(0,-0.7, 0);
            if (!pmodel2) {
                pmodel2 = glmReadOBJ("data/123.obj");
            if (!pmodel2) exit(0);
                glmUnitize(pmodel2);
                glmFacetNormals(pmodel2);
                glmVertexNormals(pmodel2, 90.0);
            }
            glmDraw(pmodel2, GLM_SMOOTH | GLM_MATERIAL);


            glPushMatrix();
                glTranslatef(0,-1.2,0 );
                glScalef(1,1,1);
                glRotatef(angle[6], 0,0,1);
                glTranslatef(0,-0.7, 0);
                if (!pmodel2) {
                    pmodel2 = glmReadOBJ("data/123.obj");
                    if (!pmodel2) exit(0);
                    glmUnitize(pmodel2);
                    glmFacetNormals(pmodel2);
                    glmVertexNormals(pmodel2, 90.0);
                }
                glmDraw(pmodel2, GLM_SMOOTH | GLM_MATERIAL);
                glPopMatrix();
            glPopMatrix();

        glPushMatrix();
            glTranslatef(-0.2,-1.05,0 );
            glScalef(0.5,0.5,0.5);
            glRotatef(angle[7], 0,0,1);
            glTranslatef(0,-0.7, 0);
            if (!pmodel2) {
                pmodel2 = glmReadOBJ("data/123.obj");
            if (!pmodel2) exit(0);
                glmUnitize(pmodel2);
                glmFacetNormals(pmodel2);
                glmVertexNormals(pmodel2, 90.0);
            }
            glmDraw(pmodel2, GLM_SMOOTH | GLM_MATERIAL);


            glPushMatrix();
                glTranslatef(0,-1.2,0 );
                glScalef(1,1,1);
                glRotatef(angle[8], 0,0,1);
                glTranslatef(0,-0.7, 0);
                if (!pmodel2) {
                    pmodel2 = glmReadOBJ("data/123.obj");
                    if (!pmodel2) exit(0);
                    glmUnitize(pmodel2);
                    glmFacetNormals(pmodel2);
                    glmVertexNormals(pmodel2, 90.0);
                }
                glmDraw(pmodel2, GLM_SMOOTH | GLM_MATERIAL);
                glPopMatrix();
            glPopMatrix();

    glPopMatrix();

    glutSwapBuffers();
}
int oldX=0;
void mouse(int button, int state, int x, int y)///NOW2
{
    oldX = x;
}
#include <stdio.h>
void motion(int x, int y)
{
    angle[angleID] += x-oldX;
    oldX = x;
    for(int i=0;i<20;i++){
    printf(" %.2f ", angle[i]);
    }
    printf("\n");
    display();
}
void timer(int t)///NOW3
{
    glutTimerFunc(33, timer, t+1);///NOW3 ///NOW4 快一點
    if(t%30==0){///NOW4 每 30frame要讀新資料
        if(fin==NULL) fin=fopen("motion.txt", "r");///NOW3
        for(int i=0; i<20; i++){///NOW3
            oldAngle[i] = newAngle[i]; ///NOW4
            fscanf(fin, "%f", &newAngle[i]);///NOW4 新資料
        }
    }
    float alpha = (t%30)/30.0;///NOW4 今天第1節有寫過它,內插
    for(int i=0;i<20;i++){///NOW4
        angle[i] = alpha*newAngle[i] + (1-alpha)*oldAngle[i];///NOW4
    }
    glutPostRedisplay();///NOW4
}

void keyboard(unsigned char key, int x, int y)
{
    if(key=='1') angleID=1;
    if(key=='2') angleID=2;
    if(key=='3') angleID=3;
    if(key=='4') angleID=4;
    if(key=='5') angleID=5;
    if(key=='6') angleID=6;
    if(key=='7') angleID=7;
    if(key=='8') angleID=8;
    if(key=='w'){///NOW1
        if(fout==NULL) fout=fopen("motion.txt", "w+");///NOW1
        for(int i=0; i<20; i++){///NOW1
            fprintf(fout, "%.1f ", angle[i]);///NOW1
        }///NOW1
        fprintf(fout, "\n");///NOW1
    }
    if(key=='r'){///NOW2
        if(fin==NULL) fin=fopen("motion.txt", "r");///NOW2
        for(int i=0; i<20; i++){///NOW2
            fscanf(fin, "%f", &angle[i]);///NOW2
        }
    }
    if(key=='t' || key=='p'){///NOW3 ///啟動timer 或是 play
        glutTimerFunc(33, timer, 0);///NOW3 ///NOW4 變快了
        if(fin==NULL) fin=fopen("motion.txt", "r");///NOW3
        for(int i=0; i<20; i++){///NOW3
            fscanf(fin, "%f", &newAngle[i]);///NOW3 ///NOW4 新角度
        }
    }
    glutPostRedisplay();///NOW2 請讀到angle[i]之後, 重畫畫面
}

int main(int argc,char**argv){
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("Week06");

    glutDisplayFunc(display);
    glutIdleFunc(display);
    glClearColor(1,1,1,1);
    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);
    glutKeyboardFunc(keyboard);///NOW3
    glutMouseFunc(mouse);///NOW2
    glutMotionFunc(motion);///NOW2
    glutDisplayFunc(display);

    glutMainLoop();
}




2019年5月17日 星期五

瑋的日常筆記Week13

#include <stdio.h>
FILE * fout=NULL;///宣告檔案指標變數
int main()
{
    fout=fopen("file0517.txt","w+");///W+=write以及UPdate
    ///R=READ,A=Append?,b=Binary;
    for(int i=0;i<20;i++){
        printf("Hello World\n");///將Hello World寫在視窗上面
        fprintf(fout,"Hello World\n");///將Hello World 寫在資料夾上的記事本
    }
}
醬子,讓在CODE上面打的程式碼變到資料夾裡面
感覺上面的比較有趣比較有用,將程式碼可以放入記事本裡面。
步驟一

作業二
#include <stdio.h> ///(0)  ///NOW4
#include <GL/glut.h>
FILE * fout=NULL;///(1) ///NOW4
FILE * fin =NULL;///(1) ///NOW5
float angle[20];///NOW
int angleID=1;///第幾個要轉動的關節 ///NOW3
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glPushMatrix();///body
        glColor3f(1,1,1);///white
        glutSolidTeapot( 0.3 );///body

        glPushMatrix();///right Arm
            glTranslatef(0.18, 0, 0);///(3)掛到肩上
            glRotatef(angle[1], 0,0,1);///(2)轉動 ///NOW
            glTranslatef(0.18, 0, 0);///(1)改變旋轉中心,放到中心

            glPushMatrix();///right Arm
            glTranslatef(0.18, 0, 0);///(3)掛到肩上
            glRotatef(angle[1], 0,0,1);///(2)轉動 ///NOW
            glTranslatef(0.18, 0, 0);///(1)改變旋轉中心,放到中心

            glColor3f(1,0,0);///red
            glutSolidTeapot( 0.2 );///right upper arm
        glPopMatrix();

            glColor3f(1,0,0);///red
            glutSolidTeapot( 0.2 );///right upper arm
        glPopMatrix();
    glPopMatrix();


        glPushMatrix();///right Arm
            glTranslatef(-0.18, 0, 0);///(3)掛到肩上
            glRotatef(angle[1], 0,0,1);///(2)轉動 ///NOW
            glTranslatef(-0.18, 0, 0);///(1)改變旋轉中心,放到中心

            glPushMatrix();///right Arm
            glTranslatef(-0.18, 0, 0);///(3)掛到肩上
            glRotatef(angle[1], 0,0,1);///(2)轉動 ///NOW
            glTranslatef(-0.18, 0, 0);///(1)改變旋轉中心,放到中心

            glColor3f(1,0,0);///red
            glutSolidTeapot( 0.2 );///right upper arm
        glPopMatrix();

            glColor3f(1,0,0);///red
            glutSolidTeapot( 0.2 );///right upper arm
        glPopMatrix();
    glPopMatrix();


    glutSwapBuffers();
}
int oldX;///NOW
void mouse(int button, int state, int x, int y)///NOW
{
    oldX = x;///NOW
}
void motion(int x, int y)///NOW
{
    angle[angleID] += (x-oldX);///NOW ///NOW3
    oldX = x;///NOW
    if(fout==NULL) fout=fopen("motion.txt", "w+");///NOW4
    for(int i=0; i<20; i++){///NOW4
        printf( "%.1f ", angle[i]);///NOW4
        fprintf( fout, "%.1f ", angle[i]);///NOW4
    }
    printf("\n");///NOW4
    fprintf(fout, "\n");///NOW4
    display();///NOW
}
void keyboard(unsigned char key, int x, int y)///NOW3
{
    if(key=='1') angleID=1;///NOW3
    if(key=='2') angleID=2;///NOW3
    if(key=='3') angleID=3;///NOW3
    if(key=='4') angleID=4;///NOW3
    if(key=='w' || key=='W'){///NOW4 小寫的 w
        if(fout==NULL) fout=fopen("motion.txt", "w+");///NOW4
        for(int i=0; i<20; i++){///NOW4
            printf( "%.1f ", angle[i]);///NOW4
            fprintf( fout, "%.1f ", angle[i]);///NOW4
        }
        printf("\n");///NOW4
        fprintf(fout, "\n");///NOW4
    }
    if(key=='r'){///NOW5
        if(fin==NULL) fin = fopen("motion.txt", "r");///NOW5
        for(int i=0; i<20;i++){///NOW5
            fscanf(fin, "%f", &angle[i]);///NOW5
        }///NOW5
    }
    glutPostRedisplay();///和 display()很像,但更好 ///NOW5
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(600,600);///我們可以開很大的視窗
    glutCreateWindow("week 13 motion TRT angle file");
    glutKeyboardFunc(keyboard);///NOW3
    glutMouseFunc(mouse);///NOW
    glutMotionFunc(motion);///NOW
    glutDisplayFunc(display);
    glutMainLoop();
}
藍色表示滑鼠移動==NOW。
紅色表示右手臂。
深紅表示右前臂。
橙色表示左手臂。
淺橙色表示左前臂。
紫底表示視窗大小。
NOW3在使用鍵盤來換數字,來控制不同的手臂。
天藍色的表示NOW4在說明你按按鍵W可以存檔。
NOW5是在做載入已存檔的檔案,將手臂放置到存檔的位置。
黑色表示原本白色茶壺所需東西。

2019年5月10日 星期五

瑋的日常筆記Week12

今天5/10號
天氣晴
今天教如何放入音檔:))
自然的音檔(閃電等等)
今天是先開這個檔案
下圖檔


#include <windows.h>
#include <mmsystem.h>
int main()
{
    PlaySoundA("C:\\Users\\user\\Downloads\\thunder_clap.wav",NULL,SND_SYNC);
    ///上面播放音檔,並且去找出位置拉進來,即可,但目前還不能播放。
    ///關鍵二,需要去PROJECT BULID OPTIONS裡面的第二個LINKER SETTING
    ///加入mmwin即可播放音檔
    ///上面就是放入的程式碼記得綠色部分是位置
    return 0;
}
^程式碼
然後
這邊是裡面的程式碼
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
int a;
float b;
char c;
double d;
如果要播MP3需要上面的程式碼

#include <mmsystem.h>
static void key(unsigned char key, int x, int y)
{
        if(key=='1')PlaySoundA("C:\\Users\\user\\Downloads\\do.wav",NULL,SND_ASYNC);
        if(key=='2')PlaySoundA("C:\\Users\\user\\Downloads\\re.wav",NULL,SND_ASYNC);
        if(key=='3')PlaySoundA("C:\\Users\\user\\Downloads\\mi.wav",NULL,SND_ASYNC);
        if(key=='4')PlaySoundA("C:\\Users\\user\\Downloads\\fa.wav",NULL,SND_ASYNC);
        if(key=='5')PlaySoundA("C:\\Users\\user\\Downloads\\so.wav",NULL,SND_ASYNC);
}
上面是用按鍵來發音

#include <stdio.h>
#include <mmsystem.h>
int main(int argc, char *argv[])
{
    myMP3.Load("C:\\Users\\user\\Downloads\\music.mp3");
    myMP3.Play();
播放MP3黨
    //PlaySoundA("C:\\Users\\user\\Downloads\\thunder_clap.wav",NULL,SND_ASYNC);
上面那個是播放原本的自然音檔
    printf("播放聲音,繼續下面開視窗\n");
}
上面是播放MP3


2019年5月3日 星期五

瑋的日常筆記week11

今日教學T-R-T

置頂GLUT&DATA>>>資料放置處
今日的程式碼
#include <GL/glut.h>
float angle=0;///NOW
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3f(255,255,255);///白色的
    glutSolidTeapot( 0.3 );///身體
    glPushMatrix();///右邊手臂
        glTranslatef(0.3, 0, 0);///(3) 掛在身體的右肩
        glRotatef(angle, 0,0,1);///(2) 旋轉
        glTranslatef(0.15, 0,0);///(1) 把茶壼柄,移動到畫面的中心,當旋轉軸

        glColor3f(1,0,0);///紅色的
        glutSolidTeapot( 0.15 );///右手臂
    glPopMatrix();

    glutSwapBuffers();
    angle++;///NOW
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH );
    glutCreateWindow("week11 TRT");
    glutIdleFunc(display);///NOW
    glutDisplayFunc(display);

    glutMainLoop();
}
深藍色的字是主要的重點,對於關節的運轉以及使用
對於第一個關節的使用,然後上面得數值以及對應到的點
來去做轉動
附圖

加上第二組程式碼

#include <GL/glut.h>
float angle=0;///NOW
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3f(255,255,255);///白色的
    glutSolidTeapot( 0.3 );///身體
    glPushMatrix();///右邊手臂
        glTranslatef(0.2, 0, 0);///(3) 掛在身體的右肩
        glRotatef(angle, 0,0,1);///(2) 旋轉
        glTranslatef(0.15, 0,0);///(1) 把茶壼柄,移動到畫面的中心,當旋轉軸

        glColor3f(1,0,0);///紅色的
        glutSolidTeapot( 0.15 );///右手臂

        glPushMatrix();///NOW2
            glTranslatef(0.2, 0, 0);///(3) 掛在身體的右肘///NOW2
            glRotatef(angle, 0,0,1);///(2) 旋轉///NOW2
            glTranslatef(0.15, 0,0);///(1) 把茶壼柄,移動到畫面的中心,當旋轉軸///NOW2

            glColor3f(1,0,0);///紅色的///NOW2
            glutSolidTeapot( 0.15 );///右下手臂///NOW2
        glPopMatrix();///NOW2

    glPopMatrix();

    glutSwapBuffers();
    angle++;///NOW
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH );
    glutCreateWindow("week11 TRT");
    glutIdleFunc(display);///NOW
    glutDisplayFunc(display);

    glutMainLoop();
}
附圖

上面是連接兩個茶壺將第二個茶壺黏在第一個茶壺上面
讓他有手臂的感覺去做動作



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~分隔線~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include <GL/glut.h>
float angle=0;///NOW
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3f(255,255,255);///白色的
    glutSolidTeapot( 0.3 );///身體

    glPushMatrix();///右邊手臂
        glTranslatef(0.2, 0, 0);///(3) 掛在身體的右肩
        glRotatef(angle, 0,0,1);///(2) 旋轉
        glTranslatef(0.15, 0,0);///(1) 把茶壼柄,移動到畫面的中心,當旋轉軸

        glColor3f(1,0,0);///紅色的
        glutSolidTeapot( 0.15 );///右手臂

        glPushMatrix();///NOW2
            glTranslatef(0.2, 0, 0);///(3) 掛在身體的右肘///NOW2
            glRotatef(angle, 0,0,1);///(2) 旋轉///NOW2
            glTranslatef(0.15, 0,0);///(1) 把茶壼柄,移動到畫面的中心,當旋轉軸///NOW2

            glColor3f(1,0,0);///紅色的///NOW2
            glutSolidTeapot( 0.15 );///右下手臂///NOW2
        glPopMatrix();///NOW2
    glPopMatrix();

    glPushMatrix();///右邊手臂
        glTranslatef(-0.2, 0, 0);///(3) 掛在身體的右肩
        glRotatef(angle, 0,0,1);///(2) 旋轉
        glTranslatef(-0.15, 0,0);///(1) 把茶壼柄,移動到畫面的中心,當旋轉軸

        glColor3f(1,0,0);///紅色的
        glutSolidTeapot( 0.15 );///右手臂

        glPushMatrix();///NOW2
            glTranslatef(-0.2, 0, 0);///(3) 掛在身體的右肘///NOW2
            glRotatef(angle, 0,0,1);///(2) 旋轉///NOW2
            glTranslatef(-0.15, 0,0);///(1) 把茶壼柄,移動到畫面的中心,當旋轉軸///NOW2

            glColor3f(1,0,0);///紅色的///NOW2
            glutSolidTeapot( 0.15 );///右下手臂///NOW2
        glPopMatrix();///NOW2
    glPopMatrix();

    glutSwapBuffers();
    ///angle++;///NOW
}
void motion(int x,int y)
{
    angle=x;
    display();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH );
    glutCreateWindow("week11 TRT");
    glutIdleFunc(display);///NOW
    glutDisplayFunc(display);
    glutMotionFunc(motion);

    glutMainLoop();

}
黑色都是舊的
紅色的是讓滑鼠去操控內容物
粉紫色是將右手的手臂做些角度的調整讓他變成左手臂
天藍色是變成負號讓他變到左邊,以致於成為左左手臂!!
因此做出了左右手臂的動作
附圖

步驟4
附圖

int oldX, oldY;///NOW5
void motion(int x, int y)///NOW3 用滑鼠mouse來控制angle
{
    angle += (x-oldX);///NOW3 用滑鼠mouse來控制angle
    oldX=x;///NOW5
    display();///NOW3 用滑鼠mouse來控制angle
}
void mouse(int button, int state, int x, int y)///NOW5 要知道mouse的按鍵狀況
{///NOW5 要知道mouse的按鍵狀況
    oldX = x; oldY = y;///NOW5 要知道mouse的按鍵狀況, 按下去時,就記得 oldX
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH );
    glutCreateWindow("week11 TRT");

    glutIdleFunc(display);///NOW
    glutDisplayFunc(display);
    glutMotionFunc(motion);///NOW3 用滑鼠mouse來控制angle
    glutMouseFunc(mouse);///NOW5 要知道mouse的按鍵狀況

    glutMainLoop();
}
上面紅色的程式碼,要是將你舊的點記住並存起來
並記錄角度,將角度記住


float angle1=0, angle2=0, angle3=0, angle4=0;///NOW ///NOW6 配合鍵盤

int jointID=1;///NOW6 配合鍵盤

關於鍵盤程式碼的部分,並將關節可以各自轉動



-----------------------------------------------分隔線-----------------------------------------------------------
下面是完整程式碼
#include <GL/glut.h>
float angle1=0, angle2=0, angle3=0, angle4=0;///NOW ///NOW6 配合鍵盤
int jointID=1;///NOW6 配合鍵盤
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3f(255,255,255);///白色的
    glutSolidTeapot( 0.3 );///身體

    glPushMatrix();///右邊手臂
        glTranslatef(0.2, 0, 0);///(3) 掛在身體的右肩
        glRotatef(angle1, 0,0,1);///(2) 旋轉 ///NOW6 配合鍵盤
        glTranslatef(0.15, 0,0);///(1) 把茶壼柄,移動到畫面的中心,當旋轉軸

        glColor3f(1,0,0);///紅色的
        glutSolidTeapot( 0.15 );///右手臂

        glPushMatrix();///NOW2
            glTranslatef(0.2, 0, 0);///(3) 掛在身體的右肘///NOW2
            glRotatef(angle2, 0,0,1);///(2) 旋轉///NOW2 ///NOW6 配合鍵盤
            glTranslatef(0.15, 0,0);///(1) 把茶壼柄,移動到畫面的中心,當旋轉軸///NOW2

            glColor3f(1,0,0);///紅色的///NOW2
            glutSolidTeapot( 0.15 );///右下手臂///NOW2
        glPopMatrix();///NOW2

    glPopMatrix();

    glPushMatrix();///左邊手臂  ///NOW4 複製左半邊
        glTranslatef(-0.2, 0, 0);///(3) 掛在身體的左肩 ///NOW4 複製左半邊
        glRotatef(-angle3, 0,0,1);///(2) 旋轉 ///NOW4 複製左半邊 ///NOW5 angle變負的
        glTranslatef(-0.15, 0,0);///(1) 把茶壼柄,移動到畫面的中心,當旋轉軸 ///NOW4 複製左半邊

        glColor3f(1,0,0);///紅色的 ///NOW4 複製左半邊
        glutSolidTeapot( 0.15 );///左手臂 ///NOW4 複製左半邊

        glPushMatrix();///NOW2 ///NOW4 複製左半邊
            glTranslatef(-0.2, 0, 0);///(3) 掛在身體的左肘///NOW2 ///NOW4 複製左半邊
            glRotatef(-angle4, 0,0,1);///(2) 旋轉///NOW2 ///NOW4 複製左半邊 ///NOW5 angle變負的
            glTranslatef(-0.15, 0,0);///(1) 把茶壼柄,移動到畫面的中心,當旋轉軸///NOW2 ///NOW4 複製左半邊

            glColor3f(1,0,0);///紅色的///NOW2 ///NOW4 複製左半邊
            glutSolidTeapot( 0.15 );///左下手臂///NOW2 ///NOW4 複製左半邊
        glPopMatrix();///NOW2

    glPopMatrix();

    glutSwapBuffers();
    ///angle++;///NOW ///NOW3
}
int oldX, oldY;///NOW5
void motion(int x, int y)///NOW3 用滑鼠mouse來控制angle
{
    if(jointID==1) angle1 += (x-oldX);///NOW3 用滑鼠mouse來控制angle ///NOW6 配合鍵盤
    if(jointID==2) angle2 += (x-oldX);///NOW3 用滑鼠mouse來控制angle ///NOW6 配合鍵盤
    if(jointID==3) angle3 += (x-oldX);///NOW3 用滑鼠mouse來控制angle ///NOW6 配合鍵盤
    if(jointID==4) angle4 += (x-oldX);///NOW3 用滑鼠mouse來控制angle ///NOW6 配合鍵盤
    oldX=x;///NOW5
    display();///NOW3 用滑鼠mouse來控制angle
}
void mouse(int button, int state, int x, int y)///NOW5 要知道mouse的按鍵狀況
{///NOW5 要知道mouse的按鍵狀況
    oldX = x; oldY = y;///NOW5 要知道mouse的按鍵狀況, 按下去時,就記得 oldX
}
void keyboard(unsigned char key, int x, int y)///NOW6 配合鍵盤
{
    if(key=='1') jointID=1;///NOW6 配合鍵盤
    if(key=='2') jointID=2;///NOW6 配合鍵盤
    if(key=='3') jointID=3;///NOW6 配合鍵盤
    if(key=='4') jointID=4;///NOW6 配合鍵盤
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH );
    glutCreateWindow("week11 TRT");

    glutIdleFunc(display);///NOW
    glutDisplayFunc(display);
    glutMotionFunc(motion);///NOW3 用滑鼠mouse來控制angle
    glutMouseFunc(mouse);///NOW5 要知道mouse的按鍵狀況
    glutKeyboardFunc(keyboard);///NOW6 配合鍵盤

    glutMainLoop();

}

2019年4月26日 星期五

瑋的日常筆記Week10




今日所上內容
#include <GL/glut.h>
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslatef(0,0.5,0);
        glutWireTeapot(0.3);
    glPopMatrix();
    glPushMatrix();
        glTranslatef(0.51,0.63,0);
        glRotatef(angle,0,0,1);
        glTranslatef(0.6,0,0);

        glRotatef(-90,0,1,0);
        glutWireCone(0.1,0.6,10,10);
    glPopMatrix();
    glutSwapBuffers();
}
void motion(int x,int y)
{
    angle=x;
    display();
}
int main(int argc,char** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("06160291");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}
------------------------------------我是分隔線---------------------------------


2019年4月12日 星期五

瑋的日常筆記 week08

freeglut的網址點這個取的資料
小葉的壓縮檔資料放置壓縮檔得地方


第一段程式碼
#include <opencv/highgui.h>///使用open CV的HIGH GUI 介面
int main()
{
    IplImage * img=cvLoadImage("image.jpg");///讀圖檔
    cvShowImage("opencv Window", img);///秀圖
    cvWaitKey(0);///等你按鍵

}

這是用不同的專案要將圖放入專案資料夾
第二段程式碼
#include <GL/glut.h>
#include <opencv/highgui.h>
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glutSolidTeapot(0.3);
    glutSwapBuffers();
}
int main(int argc, char**argv)
{
    IplImage * img=cvLoadImage("earth.jpg");///讀圖檔
    cvShowImage("opencv Window", img);///秀圖
    cvWaitKey(0);///等你按鍵

    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("Week08 texture");

    glutDisplayFunc(display);

    glutMainLoop();
}

用GLUT入圖要將圖放入freeglut裡面的bin

2019年3月29日 星期五

瑋的日常筆記week06

今天出問題
若是程式碼一直執行不起來
就rebulid這樣就可能或許能將程式碼成功打開
然後執行
^今日重點^

新增程式碼及zip
source.zip
以及加入模型= =
這次的步驟很多首先會有這些東西
一直到window前都一樣

將data解壓縮然後放入下載的freeglut裡面的bin
然後將source解壓縮裡面的glm.c

變成glm.cpp

^上面框框的
然後將他用codeblock
加入glm.cpp

然後開起來
再將這個橘色框框的東西打開

然後將裡面的程式碼複製其中一段
 if(!pmodel) {
    pmodel = glmReadOBJ("data/porsche.obj");                   //別人寫好的程式  偷來用
    if(!pmodel) exit(0);
    glmUnitize(pmodel);
    glmFacetNormals(pmodel);
    glmVertexNormals(pmodel, 90.0);
    }
    glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
^上面這一段
會變成這樣

目前就是這樣吧