2017年5月2日 星期二

week11太會睡啦~~

1)首先下載3D檔案總管(3d exploration)免費試用版(學校安裝)


2)並在jsyeh.org/3dcg10下載data.zip並解壓縮在桌面

3)使用3d exploration去看data中的3D模型

匯出足球:

1)save as...檔案為.cpp檔

2)並選擇為Sample app type

開啟code blocks
開啟openGL專案

刪掉原本的main.c

在把新的cpp檔放進專案資料夾中

並將他開啟



註解掉那2個讀不了的程式碼

完成


匯出海豚:


依序將海豚匯出成obj檔(要記得選在Visible區域)

FB下載freeglut的檔案
還有老師有給myGLMsample檔案匯入codeblocks
將三隻海豚的檔案放進myGLMsample的data裡
更改檔案讀取部分程式碼就可以秀出模型
要同時做出第二個模型
請複製貼上並更改紅框區域再新增需要的程式碼
2隻完成
再做成3隻
隨意縮放旋轉



#include <string.h>
#include <stdlib.h>
#include <GL/glut.h>
#include "glm.h"
GLMmodel* pmodel = NULL;
GLMmodel* pmodel2 = NULL;
GLMmodel* pmodel3 = NULL;
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        angle++;
        glRotatef(angle, 0,1,0);
        if (!pmodel) {
        pmodel = glmReadOBJ("data/dolphins1.obj");
        if (!pmodel) exit(0);
        glmUnitize(pmodel);
        glmFacetNormals(pmodel);
        glmVertexNormals(pmodel, 90.0);
        }

        glmDraw(pmodel,GLM_SMOOTH | GLM_MATERIAL);

        if (!pmodel2) {
        pmodel2 = glmReadOBJ("data/dolphins2.obj");
        if (!pmodel2) exit(0);
        glmUnitize(pmodel2);
        glmFacetNormals(pmodel2);
        glmVertexNormals(pmodel2, 90.0);
        }
        glmDraw(pmodel2, GLM_SMOOTH | GLM_MATERIAL);

        if (!pmodel3) {
        pmodel3 = glmReadOBJ("data/dolphins3.obj");
        if (!pmodel3) exit(0);
        glmUnitize(pmodel3);
        glmFacetNormals(pmodel3);
        glmVertexNormals(pmodel3, 90.0);
        }
        glmDraw(pmodel3, GLM_SMOOTH | GLM_MATERIAL);

    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 main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB);
    glutCreateWindow("Yes, 3D Model Here");

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

沒有留言:

張貼留言