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

2017年5月13日 星期六

Lars'的圖學 week11

歡迎到Lars~ 本篇標籤為 04160143_陳泓鈞(Lars)_ week11



HW一

1.下載 3D Exploration後安裝並執行


2.到http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/網站下載data.zip 解壓縮後開啟模型
3..匯出CPP(OPENGL)程式

4.用CodeBlocks開啟OpenGL專案,並將檔案放入

5.移除會發生錯誤的程式碼




2017年5月9日 星期二

Week11

本周重點:
(1)組合出機器人
(2)可轉動的關節
(3)錄製動作

一.先下載3D Exploration v1.81
二.下載


三.打開3D Exploration
四.再到http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/下載data

五.















Week11 陳冠宇

(上禮拜請假)

下載3D Ecploration

打開soccerball和soccer




使用海豚模型


將glm.h放入目錄

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

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

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

        glPushMatrix();  //第一隻
            glTranslatef(0,0,0);//移動
            glRotatef(90,0,1,0);//旋轉
            glScalef(0.8,0.8,0.8);//縮放
            glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
        glPopMatrix();

        glPushMatrix();  //第二隻
            glTranslatef(0.5,0,0);//移動
            glScalef(0.4,0.4,0.4);//縮放
            glmDraw(pmodel2, GLM_SMOOTH | GLM_MATERIAL);
        glPopMatrix();

        glPushMatrix();  //第三隻
            glTranslatef(-0.5,0,0);//移動
            glRotatef(180,0,1,0);//旋轉
            glScalef(0.4,0.4,0.4);//縮放
            glmDraw(pmodel3, 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[] = { 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 <mmsystem.h>  //(1)Multimedia system
void keyboard(unsigned char key,int x,int y)
{   //(5)Add keyboard for Do/Re/Mi/Fa/So
    if(key=='1') PlaySound("Do.wav",NULL,SND_ASYNC);
    if(key=='2') PlaySound("Re.wav",NULL,SND_ASYNC);
    if(key=='3') PlaySound("Mi.wav",NULL,SND_ASYNC);
    if(key=='4') PlaySound("Fa.wav",NULL,SND_ASYNC);
    if(key=='5') PlaySound("So.wav",NULL,SND_ASYNC);
}
void mouse(int button,int state,int x,int y)
{
    PlaySound("C:\\Users\\user\\Desktop\\myGLMsample\\data\\Shot.wav",NULL,SND_ASYNC);
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB);
    glutCreateWindow("Yes, 3D Model Here");
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);
    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_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月6日 星期六

weeek11麥

1.先去下載3D Ecploration

1.81免費試用版本(4.5MB)
解壓縮後
打開下載的data裡的 ex.soccerball


打開下載的data裡的soccer



把檔案存成OPENGL檔
再用Notepad++打開看看

Codeblock開啟OpenGL的專案
加入soccerball.cpp加入
會有以下兩行錯誤要刪除


2.3D模型開海豚


存檔時要調成visible

 讓海豚組合

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

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

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

        glPushMatrix();  //第一隻
            glTranslatef(0,0,0);//移動
            glRotatef(90,0,1,0);//旋轉
            glScalef(0.8,0.8,0.8);//縮放
            glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
        glPopMatrix();

        glPushMatrix();  //第二隻
            glTranslatef(0.5,0,0);//移動
            glScalef(0.4,0.4,0.4);//縮放
            glmDraw(pmodel2, GLM_SMOOTH | GLM_MATERIAL);
        glPopMatrix();

        glPushMatrix();  //第三隻
            glTranslatef(-0.5,0,0);//移動
            glRotatef(180,0,1,0);//旋轉
            glScalef(0.4,0.4,0.4);//縮放
            glmDraw(pmodel3, 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[] = { 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 <mmsystem.h>  //(1)Multimedia system
void keyboard(unsigned char key,int x,int y)
{   //(5)Add keyboard for Do/Re/Mi/Fa/So
    if(key=='1') PlaySound("Do.wav",NULL,SND_ASYNC);
    if(key=='2') PlaySound("Re.wav",NULL,SND_ASYNC);
    if(key=='3') PlaySound("Mi.wav",NULL,SND_ASYNC);
    if(key=='4') PlaySound("Fa.wav",NULL,SND_ASYNC);
    if(key=='5') PlaySound("So.wav",NULL,SND_ASYNC);
}
void mouse(int button,int state,int x,int y)
{  
    PlaySound("C:\\Users\\user\\Desktop\\myGLMsample\\data\\Shot.wav",NULL,SND_ASYNC);
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB);
    glutCreateWindow("Yes, 3D Model Here");
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);
    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_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月2日 星期二








Week11_










W11

 
 
 
一、下載3D Exploration 1.81V試用版
 

 
 
 
 
 

 
 
三、用3D Exploration看(二)的soccerball
 
 
用notepad++觀看soccerball.cpp
 
原本的
 
 
把原本的刪除add file加入soccerball.cpp刪除3280、3281的程式碼
 
 
 
0
 
 
 
 
 
 

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