顯示具有 Week13 標籤的文章。 顯示所有文章
顯示具有 Week13 標籤的文章。 顯示所有文章

2017年6月5日 星期一

Week 13 20170605

課堂作業一
利用以下截圖檔了解內插法的概念
解利用Timer結合角度+內插法的概念實作應用

20170605_Week13 佳諭der課堂筆記



Week 13 課堂內容筆記摘要



作業一 - 學習內插公式+交叉相乘的概念做出連續動作
1.利用以下截圖檔了解內插法的概念。






















2.觀看以下截圖程式碼了解利用Timer結合角度+內插法的概念實作應用。

截圖檔


















作業一 - 存檔與讀檔
1.利用今日所學之截圖程式碼學會如何讓動作進行存檔並且在CodeBlocks讀取動作檔案
(第一次存檔匯存到.cbp專案黨的資料夾中,成為一個記事本file檔案)

截圖檔

















week 13 楊語琛的上課筆記 レ(゚∀゚;)ヘ=З=З=З

一 內差公式

   1 Excel的公式應用
    
    例: 薪水就是角度
    公式:Alpha*NewAngle+(1-Alpha)*OldAngle
    
    2 解壓老師的專案以及把freeglut的壓縮檔案拉到桌面並且開啟專案,加入內插公式
       應用上周的內容加入Timer使機器人會動
       
      
   3 寫檔案
       #include<stdio.h>
       FILE*font=NULL;//檔案指標



       if(key=='s' || key='S')
       {
            if(fout==NULL)
                   fout=fopen("file.txt", "w+");
       }
      
     

Week13陳冠霖的上課筆記

本周進度:
內插講解
內差公式:d*新+(1-d)*舊
在之前的機器人裡加入float alpha=0.0;float oldAngle[10]={0,0,0,0,0,0,0,0,0,0};float newAngle[10]={10,20,30,40,50,60,70,80,90,100};
void interpolation(){for(int i=0;i<9;i++){angle[i]=alpha*newAngle[i]+(1-alpha)*oldAngle[i];}
    alpha+=0.1;},修改倒數器裡加入interpolation();
以下是程式碼:
#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;
int now = 0;
float angle[10]={};
float alpha=0.0;
float oldAngle[10]={0,0,0,0,0,0,0,0,0,0};
float newAngle[10]={10,20,30,40,50,60,70,80,90,100};
float anglee=0;
void interpolation()
{
    for(int i=0;i<9;i++)
    {
        angle[i]=alpha*newAngle[i]+(1-alpha)*oldAngle[i];
    }
    alpha+=0.1;
}
void display()
{

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();


        if (!pmodel1) {//head

        pmodel1 = glmReadOBJ("C:\\Users\\user\\Desktop\\hw122/head.obj");
        if (!pmodel1) exit(0);

        glmUnitize(pmodel1);
        glmFacetNormals(pmodel1);
        glmVertexNormals(pmodel1, 90.0);
        }
           if (!pmodel2) {//body

        pmodel2 = glmReadOBJ("C:\\Users\\user\\Desktop\\hw122/body.obj");
        if (!pmodel2) exit(0);

        glmUnitize(pmodel2);
        glmFacetNormals(pmodel2);
        glmVertexNormals(pmodel2, 90.0);
        }
             if (!pmodel3) {

        pmodel3 = glmReadOBJ("C:\\Users\\user\\Desktop\\hw122/up1.obj");
        if (!pmodel3) exit(0);

        glmUnitize(pmodel3);
        glmFacetNormals(pmodel3);
        glmVertexNormals(pmodel3, 90.0);
        }
             if (!pmodel4) {

        pmodel4 = glmReadOBJ("C:\\Users\\user\\Desktop\\hw122/up2.obj");
        if (!pmodel4) exit(0);

        glmUnitize(pmodel4);
        glmFacetNormals(pmodel4);
        glmVertexNormals(pmodel4, 90.0);
        }
            if (!pmodel5) {

        pmodel5 = glmReadOBJ("C:\\Users\\user\\Desktop\\hw122/hand.obj");
        if (!pmodel5) exit(0);

        glmUnitize(pmodel5);
        glmFacetNormals(pmodel5);
        glmVertexNormals(pmodel5, 90.0);
        }
            if (!pmodel6) {

        pmodel6 = glmReadOBJ("C:\\Users\\user\\Desktop\\hw122/down1.obj");
        if (!pmodel6) exit(0);

        glmUnitize(pmodel6);
        glmFacetNormals(pmodel6);
        glmVertexNormals(pmodel6, 90.0);
        }
            if (!pmodel7) {

        pmodel7 = glmReadOBJ("C:\\Users\\user\\Desktop\\hw122/down2.obj");
        if (!pmodel7) exit(0);

        glmUnitize(pmodel7);
        glmFacetNormals(pmodel7);
        glmVertexNormals(pmodel7, 90.0);
        }
            if (!pmodel8) {

        pmodel8 = glmReadOBJ("C:\\Users\\user\\Desktop\\hw122/down3.obj");
        if (!pmodel8) exit(0);

        glmUnitize(pmodel8);
        glmFacetNormals(pmodel8);
        glmVertexNormals(pmodel8, 90.0);
        }

         glPushMatrix();
            //glRotatef(anglee,0,1,0);//旋轉
            glPushMatrix();//頭
                glTranslatef(0,0.65,0);//移動
                glRotatef(90,0,1,0);//旋轉
                glScalef(0.6,0.6,0.6);//縮放
                glmDraw(pmodel1, GLM_SMOOTH | GLM_MATERIAL);
            glPopMatrix();
            glPushMatrix();  //身體
                glTranslatef(0,0.1,0);//移動
                glRotatef(90,0,1,0);//旋轉
                glScalef(0.4,0.4,0.4);//縮放
                glmDraw(pmodel2, GLM_SMOOTH | GLM_MATERIAL);
            glPopMatrix();
            glPushMatrix();//右臂
                    glTranslatef(0.43,0.3,0);
                    glRotatef(angle[0],1,0,0);
                    glTranslatef(-0.45,-0.3,0);
                glPushMatrix();
                    glTranslatef(0.45,0.3,0);
                    glRotatef(90,0,1,0);
                    glScalef(0.5,0.5,0.5);
                    glmDraw(pmodel3, GLM_SMOOTH | GLM_MATERIAL);
                glPopMatrix();
            glPushMatrix();//右籌
                    glTranslatef(0.43,0.3,0);
                    glRotatef(angle[2],0,1,0);
                    glTranslatef(-0.45,-0.3,0);
                glPushMatrix();
                    glTranslatef(0.55,0,0);
                    glRotatef(90,0,1,0);
                    glScalef(0.5,0.5,0.5);
                    glmDraw(pmodel4, GLM_SMOOTH | GLM_MATERIAL);
                glPopMatrix();
                glPushMatrix();//右長
                    glTranslatef(0.8,0,0);
                    glRotatef(270,0,1,0);
                    glScalef(0.5,0.5,0.5);
                    glmDraw(pmodel5, GLM_SMOOTH | GLM_MATERIAL);
                glPopMatrix();
            glPopMatrix();
          glPopMatrix();
            glPushMatrix();//左臂
                    glTranslatef(0.46,0.3,0);
                    glRotatef(angle[1],1,0,0);
                    glTranslatef(-0.45,-0.3,0);
                glPushMatrix();
                        glTranslatef(-0.45,0.3,0);
                        glRotatef(90,0,1,0);
                        glScalef(0.5,0.5,0.5);
                        glmDraw(pmodel3, GLM_SMOOTH | GLM_MATERIAL);
                glPopMatrix();
             glPushMatrix();//左籌
                    glTranslatef(-0.46,-0.3,0);
                    glRotatef(angle[3],0,1,0);
                    glTranslatef(0.45,0.3,0);
                glPushMatrix();
                    glTranslatef(-0.55,0,0);
                        glRotatef(90,0,1,0);
                        glScalef(0.5,0.5,0.5);
                        glmDraw(pmodel4, GLM_SMOOTH | GLM_MATERIAL);
                glPopMatrix();
                glPushMatrix();//左掌
                        glTranslatef(-0.8,0,0);
                        glRotatef(90,0,1,0);
                        glScalef(0.5,0.5,0.5);
                        glmDraw(pmodel5, GLM_SMOOTH | GLM_MATERIAL);
                glPopMatrix();
            glPopMatrix();
        glPopMatrix();
        glPushMatrix();//左大腿
            glTranslatef(-0.2,-0.35,0);
            glRotatef(angle[4],0,1,0);
            glTranslatef(0.2,0.3,0);
         glPushMatrix();
            glTranslatef(-0.2,-0.35,0);
            glRotatef(90,0,1,0);
            glScalef(0.2,0.25,0.25);
            glmDraw(pmodel6, GLM_SMOOTH | GLM_MATERIAL);
         glPopMatrix();
         glPushMatrix();//左小腿
            glTranslatef(-0.25,-0.25,0);
            glRotatef(angle[5],0,1,0);
            glTranslatef(0.25,0.3,0);
         glPushMatrix();
            glTranslatef(-0.25,-0.7,0);
            glRotatef(90,0,1,0);
            glScalef(0.5,0.4,0.5);
            glmDraw(pmodel7, GLM_SMOOTH | GLM_MATERIAL);
         glPopMatrix();
         glPushMatrix();//左掌
            glTranslatef(-0.3,-0.9,0);
            glRotatef(90,0,1,0);
            glScalef(0.5,0.5,0.5);
            glmDraw(pmodel8, GLM_SMOOTH | GLM_MATERIAL);
         glPopMatrix();
         glPopMatrix();
         glPopMatrix();
         glPushMatrix();//右大腿
            glTranslatef(0.2,0.25,0);
            glRotatef(angle[6],0,1,0);
            glTranslatef(-0.2,-0.3,0);
         glPushMatrix();
            glTranslatef(0.2,-0.35,0);
            glRotatef(270,0,1,0);
            glScalef(0.2,0.25,0.25);
            glmDraw(pmodel6, GLM_SMOOTH | GLM_MATERIAL);
         glPopMatrix();
         glPushMatrix();//右小腿
            glTranslatef(0.25,0.35,0);
            glRotatef(angle[7],0,1,0);
            glTranslatef(-0.25,-0.3,0);
        glPushMatrix();
            glTranslatef(0.25,-0.7,0);
            glRotatef(90,0,1,0);
            glScalef(0.5,0.4,0.5);
            glmDraw(pmodel7, GLM_SMOOTH | GLM_MATERIAL);
         glPopMatrix();
          glPushMatrix();//右腳掌
            glTranslatef(0.3,-0.9,0);
            glRotatef(90,0,1,0);
            glScalef(0.5,0.5,0.5);
            glmDraw(pmodel8, GLM_SMOOTH | GLM_MATERIAL);
         glPopMatrix();
         glPopMatrix();
         glPopMatrix();
    glPopMatrix();

    glPopMatrix();

    glutSwapBuffers();
}
int oldx=0,oldy=0;
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();
}

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;
}
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 };
#include <stdio.h>
void timer(int t)
{
    glutTimerFunc(10,timer,t+1);
    interpolation();
    anglee++;
    glutPostRedisplay();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB);
    glutCreateWindow("04160480");

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

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

老師講解圖:
讀檔跟存檔
新增以下程式碼:
#include <stdio.h>
FILE * fout=NULL;
FILE * fin=NULL;
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){
        fout=fopen("file.txt","w+");
        printf("產生FILE了\n");
    }
    fprintf(fout,"%.3f %.3f %.3f %.3f %.3f\n",angle[0],angle[1],angle[2],angle[3],angle[4]);
    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){
        fin=fopen("file.txt","r");
        printf("123");
    }
    fscanf(fin,"%f %f %f %f %f",&angle[0],&angle[1],angle[2],&angle[3],&angle[4]);
    glutPostRedisplay();
    }
}
老師講解圖:

Week13 20170605 芷萱的課堂筆記

作業一 :
目標 : 利用内插公式擺出各種擺出各種角度
angle=alpha*newAngle+(1-alpha)*oldAngle;
1.參考老師解說內插公式























4.存檔→將角度存在一個記事本file.txtif(key=='s'||key=='S'){        if(fout==NULL){            fout=fopen("file.txt","w+");            printf("現在我產生一個file.txt的檔案在目錄裡\n");           }        fprintf(fout,"%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f\n",angle[0],angle[1],angle[2],angle[3],angle[4],angle[5],angle[6],angle[7],angle[8]);        printf("現在我把一些數字印到檔案裡%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f\n",angle[0],angle[1],angle[2],angle[3],angle[4],angle[5],angle[6],angle[7],angle[8]);    }


if(key=='r'||key=='R'){
        if(fin==NULL){
            fin=fopen("file.txt","r");
            printf("現在我產生一個file.txt的檔案在目錄裡\n");
        }
        fscanf(fin,"%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f\n",&angle[0],&angle[1],&angle[2],&angle[3],&angle[4],&angle[5],&angle[6],&angle[7],&angle[8]);
        glutPostRedisplay();
    }


Week 13 20170605 鄭雅至的課堂筆記

Week 13


HW 1

利用 Excel 了解內插公式。




















HW 2

打開自己的模型。

增加內插公式的函式與Timer函式。

函式:
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;
}


void timer(int t)
{
    glutTimerFunc(1000,timer,t+1);
    interpolation();
    glutPostRedisplay();
}



HW 3

複習。
第一階段:

程式碼:

#include <GL/glut.h>
#include <math.h>
float eyeX=0, eyeY=0, eyeZ=2;
float centerX=0, centerY=0, centerZ=0;
float upX=0, upY=1, upZ=0;
///float angle=0, dir=1;///只有一個角度,好可憐, ///今天簡化修改掉
float angle[20]={};///今天簡化修改掉
static void display(void)
{
    glMatrixMode(GL_PROJECTION);///臨時切換成投影Projection矩陣來調整
    glLoadIdentity();
    gluPerspective(60, 1, 0.001, 10000);
    ///fov: field of view 視野的張角(y方向)
    ///aspect: xy的比例   zNear, zFar 代表
    glMatrixMode(GL_MODELVIEW);///馬上切換回去Model View矩陣

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3d(1,0,0);

 ///   angle+=dir;///今天簡化修改掉
 ///   if(angle>60)dir = -dir;///今天簡化修改掉
 ///   if(angle<0) dir = -dir;///今天簡化修改掉

    glPushMatrix();
        gluLookAt(eyeX, eyeY, eyeZ,
                  centerX, centerY, centerZ,
                  upX, upY, upZ);
        glutSolidTeapot(0.3);///head
        glPushMatrix();
            glTranslatef(0, -0.3, 0);
            glColor3f(1,1,1); glutSolidTeapot(0.3);///body

            glPushMatrix();
                glTranslatef(0.3, 0,0);///T
                glRotatef(angle[1], 0,0,1);///R///今天簡化修改掉
                glTranslatef(0.3, 0,0);///T
                glutSolidTeapot(0.3);///right upper arm
                glPushMatrix();
                    glTranslatef(0.3, 0,0);///T
                    glRotatef(angle[2], 0,0,1);///R///今天簡化修改
                    glTranslatef(0.3, 0,0);///T
                    glutSolidTeapot(0.3);///right lower arm
                glPopMatrix();
            glPopMatrix();

            glPushMatrix();
                glTranslatef(-0.3, 0,0);///T
                glRotatef(-angle[3], 0,0,1);///R///今天簡化修改
                glTranslatef(-0.3, 0,0);///T
                glutSolidTeapot(0.3);///left upper arm
                glPushMatrix();
                    glTranslatef(-0.3, 0,0);///T
                    glRotatef(-angle[4], 0,0,1);///R///今天簡化修改
                    glTranslatef(-0.3, 0,0);///T
                    glutSolidTeapot(0.3);///left lower arm
                glPopMatrix();
            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 };
int now=0;
int oldX=0, oldY=0;
#include <stdio.h>
void keyboard(unsigned char key, int x, int y)///今天簡化修改
{
    printf("%c\n", key);
    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;///今天簡化修改
}
void mouse(int button, int state, int x, int y)///今天簡化修改
{
    oldX=x;///今天簡化修改
    oldY=y;///今天簡化修改
}
void motion(int x, int y)///今天簡化修改
{
    angle[now] += x-oldX;///今天簡化修改
    oldX=x;
    glutPostRedisplay();///今天簡化修改
}
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");

    ///glutReshapeFunc(resize);
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);///今天簡化修改
    glutMouseFunc(mouse);///今天簡化修改
    glutMotionFunc(motion);///今天簡化修改
    ///glutIdleFunc(idle);
    ///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;
}




第二階段:
程式碼:

#include <GL/glut.h>
#include <math.h>
float eyeX=0, eyeY=0, eyeZ=2;
float centerX=0, centerY=0, centerZ=0;
float upX=0, upY=1, upZ=0;
///float angle=0, dir=1;///只有一個角度,好可憐, ///今天簡化修改掉
float angle[20]={};///今天簡化修改掉
static void display(void)
{
    glMatrixMode(GL_PROJECTION);///臨時切換成投影Projection矩陣來調整
    glLoadIdentity();
    gluPerspective(60, 1, 0.001, 10000);
    ///fov: field of view 視野的張角(y方向)
    ///aspect: xy的比例   zNear, zFar 代表
    glMatrixMode(GL_MODELVIEW);///馬上切換回去Model View矩陣

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3d(1,0,0);

 ///   angle+=dir;///今天簡化修改掉
 ///   if(angle>60)dir = -dir;///今天簡化修改掉
 ///   if(angle<0) dir = -dir;///今天簡化修改掉

    glPushMatrix();
        gluLookAt(eyeX, eyeY, eyeZ,
                  centerX, centerY, centerZ,
                  upX, upY, upZ);
        glutSolidTeapot(0.3);///head
        glPushMatrix();
            glTranslatef(0, -0.3, 0);
            glColor3f(1,1,1); glutSolidTeapot(0.3);///body

            glPushMatrix();
                glTranslatef(0.3, 0,0);///T
                glRotatef(angle[1], 0,0,1);///R///今天簡化修改掉
                glTranslatef(0.3, 0,0);///T
                glutSolidTeapot(0.3);///right upper arm
                glPushMatrix();
                    glTranslatef(0.3, 0,0);///T
                    glRotatef(angle[2], 0,0,1);///R///今天簡化修改
                    glTranslatef(0.3, 0,0);///T
                    glutSolidTeapot(0.3);///right lower arm
                glPopMatrix();
            glPopMatrix();

            glPushMatrix();
                glTranslatef(-0.3, 0,0);///T
                glRotatef(-angle[3], 0,0,1);///R///今天簡化修改
                glTranslatef(-0.3, 0,0);///T
                glutSolidTeapot(0.3);///left upper arm
                glPushMatrix();
                    glTranslatef(-0.3, 0,0);///T
                    glRotatef(-angle[4], 0,0,1);///R///今天簡化修改
                    glTranslatef(-0.3, 0,0);///T
                    glutSolidTeapot(0.3);///left lower arm
                glPopMatrix();
            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 };
int now=0;
int oldX=0, oldY=0;
#include <stdio.h>///寫檔案的第1行
FILE * fout=NULL;///寫檔案的第2行, 空空的
void keyboard(unsigned char key, int x, int y)///今天簡化修改
{
    printf("%c\n", key);
    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=='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]);
    }
}
void mouse(int button, int state, int x, int y)///今天簡化修改
{
    oldX=x;///今天簡化修改
    oldY=y;///今天簡化修改
}
void motion(int x, int y)///今天簡化修改
{
    angle[now] += x-oldX;///今天簡化修改
    oldX=x;
    glutPostRedisplay();///今天簡化修改
}
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");

    ///glutReshapeFunc(resize);
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);///今天簡化修改
    glutMouseFunc(mouse);///今天簡化修改
    glutMotionFunc(motion);///今天簡化修改
    ///glutIdleFunc(idle);
    ///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;
}



第三階段:

程式碼:

#include <GL/glut.h>
#include <math.h>
float eyeX=0, eyeY=0, eyeZ=2;
float centerX=0, centerY=0, centerZ=0;
float upX=0, upY=1, upZ=0;
///float angle=0, dir=1;///只有一個角度,好可憐, ///今天簡化修改掉
float angle[20]={};///今天簡化修改掉
static void display(void)
{
    glMatrixMode(GL_PROJECTION);///臨時切換成投影Projection矩陣來調整
    glLoadIdentity();
    gluPerspective(60, 1, 0.001, 10000);
    ///fov: field of view 視野的張角(y方向)
    ///aspect: xy的比例   zNear, zFar 代表
    glMatrixMode(GL_MODELVIEW);///馬上切換回去Model View矩陣

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3d(1,0,0);

 ///   angle+=dir;///今天簡化修改掉
 ///   if(angle>60)dir = -dir;///今天簡化修改掉
 ///   if(angle<0) dir = -dir;///今天簡化修改掉

    glPushMatrix();
        gluLookAt(eyeX, eyeY, eyeZ,
                  centerX, centerY, centerZ,
                  upX, upY, upZ);
        glutSolidTeapot(0.3);///head
        glPushMatrix();
            glTranslatef(0, -0.3, 0);
            glColor3f(1,1,1); glutSolidTeapot(0.3);///body

            glPushMatrix();
                glTranslatef(0.3, 0,0);///T
                glRotatef(angle[1], 0,0,1);///R///今天簡化修改掉
                glTranslatef(0.3, 0,0);///T
                glutSolidTeapot(0.3);///right upper arm
                glPushMatrix();
                    glTranslatef(0.3, 0,0);///T
                    glRotatef(angle[2], 0,0,1);///R///今天簡化修改
                    glTranslatef(0.3, 0,0);///T
                    glutSolidTeapot(0.3);///right lower arm
                glPopMatrix();
            glPopMatrix();

            glPushMatrix();
                glTranslatef(-0.3, 0,0);///T
                glRotatef(-angle[3], 0,0,1);///R///今天簡化修改
                glTranslatef(-0.3, 0,0);///T
                glutSolidTeapot(0.3);///left upper arm
                glPushMatrix();
                    glTranslatef(-0.3, 0,0);///T
                    glRotatef(-angle[4], 0,0,1);///R///今天簡化修改
                    glTranslatef(-0.3, 0,0);///T
                    glutSolidTeapot(0.3);///left lower arm
                glPopMatrix();
            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 };
int now=0;
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)///今天簡化修改
{
    printf("%c\n", key);
    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=='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;///今天簡化修改
}
void motion(int x, int y)///今天簡化修改
{
    angle[now] += x-oldX;///今天簡化修改
    oldX=x;
    glutPostRedisplay();///今天簡化修改
}
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");

    ///glutReshapeFunc(resize);
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);///今天簡化修改
    glutMouseFunc(mouse);///今天簡化修改
    glutMotionFunc(motion);///今天簡化修改
    ///glutIdleFunc(idle);
    ///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;
}






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