2018年4月16日 星期一

week08 矮矮的筆記

來源 : http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/

1.下載 data
2.下載 win32 並解壓縮(放到你想放的地方
3.下載 glut32.dll 並複製到與win32同一個地方
4.解data壓縮至與win32同一個地方
5.執行Light Material.exe


調整材質  觀察變化 可發現material的值會有變化

二 、用codeblocks執行
1.打開codeblocks
2.按create a new project
3.選擇GLUT project
4.go→next
5.建立檔名為05163012_01_2glut
6.選擇儲存位置
7.next
8.選擇freeglut資料夾
9.next→finish
10.打開sources
11.把程式碼改成與螢光筆處相同



1.把source資料夾打開
2.把glm.c改成glm.cpp 
3.把transformation.c改成transformation.cpp
4.匯入 glm.cpp, t
5.因為是舊程式碼,需先更改code:blocks設定( 螢光筆處取消∨ )

                                         

三、自己跑車車
1.從transformation.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);
)


2.加上黃色部分的程式碼(開外掛)







四、手動轉的立體車車
完整程式碼
#include "glm.h"
GLMmodel * pmodel = NULL ;
float angle = 0 ;
void motion(int x , int y )
{
    angle = x ;
    glutPostRedisplay();
}
static void display(void)
{

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


    glPushMatrix();
        glRotatef(angle, 0,1,0);

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

    glutSwapBuffers();
}
///設定陣列 ,要給OpenGL打光用的

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

/* Program entry point */

int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("GLUT Shapes");
    glutDisplayFunc(display);
    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();

    return EXIT_SUCCESS;
}

沒有留言:

張貼留言