顯示具有 07160325_劉瑞哲 標籤的文章。 顯示所有文章
顯示具有 07160325_劉瑞哲 標籤的文章。 顯示所有文章

2021年5月12日 星期三

小乖的圖學筆記 week12

1.安裝3DEXPLOR181

2.開啟3DEXPLOR181

3.將鋼彈模型匯入

4.將鋼彈模型匯出成cpp檔

5.開啟glut專案

6.把main.cpp改成鋼彈的程式碼並按照下面兩張圖做新增&修改

7.把匯出鋼彈模型的bmp檔放在C:\Users\Administrator\Desktop\freeglut\bin

8.程式運行長這樣(會旋轉跳動)

9.把旋轉和縮放註解掉

10.切割模型的練習

11.把老師給的程式碼貼上去執行就行了

2021年5月5日 星期三

小乖的圖學筆記 week11

 1. Moodle下載範例 source.zip windows.zip, data.zip

  windows.zip 解壓縮至 下載\windows\Transformation.exe

  data.zip 解壓縮至 下載\windows\data\模型

2.打開GLUT專案(自己去week01)

3.將glm.h和glm.c放同目錄 (week11-1專案目錄)

glm.c 改檔名成 glm.cpp

transformation.c 內容放到 main.cpp

4.把 glm.cpp 放入專案(左邊Project>Add檔案>glm.cpp加入)

5.把 data.zip 裡的檔案放入執行目錄

C:\Users\Administrator\Desktop\freeglut\bin

6.程式碼執行如下

7.將main.cpp裡的程式碼刪掉至剩下

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

並且從GitHub裡下載並複製

void display()以及int main()

修改成以下

#include <GL/glut.h>
#include "glm.h"
GLMmodel * pmodel=NULL;
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()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(180,0,1,0);
        drawmodel();
    glPopMatrix();
    glutSwapBuffers();
}
int main(int argc,char ** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GL_DEPTH_BUFFER_BIT);
    glutCreateWindow("¤p¨Äªº3D¼Ò«¬");
    glutDisplayFunc(display);
    glutMainLoop();
}

8.程式碼執行如下

9.加入打光程式碼兩段並翻轉模型

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 display()以及int main()之間

    glEnable(GL_DEPTH_TEST);
    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);

加在int main()裡的glutDisplayFunc(display);以及glutCreateWindow(" ");之間

void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
   
glPushMatrix();
        glRotatef(180,0,1,0);

        drawmodel();
    glPopMatrix();
    glutSwapBuffers();
}

加上這段已翻轉模型

10.程式碼執行如下

11.安裝OpenCV並重開(教學在week08)

12.開啟老師給的gundam中的cbp檔並執行


2021年4月28日 星期三

小乖的圖學筆記 week10

 上一周期中考啦哈哈

------------------------------------------------------------------------------------------

這周教添加音樂

0.資料夾裡先放這些檔案

0-1 路徑C:\Users\Administrator\Desktop\freeglut\bin

0-2路徑C:\Users\Administrator\Desktop\week10-1 (專案資料夾裡)


1.開啟GLUT專案

2.添加程式碼PlaySound("檔案名稱.wav(ˇ只能使用wav檔)",空指標,執行模式);

#include <windows.h>
#include <stdio.h>
int main()
{
    PlaySound("2020-12-1-14-59-3-165-nf1.wav",NULL,SND_SYNC);
}

這樣可以自動播放 2020-12-1-14-59-3-165-nf1.wav


3.添加程式碼

#include <windows.h>
#include <stdio.h>
int main()
{
    PlaySound("do.wav",NULL,SND_ASYNC);
    PlaySound("re.wav",NULL,SND_ASYNC);
    PlaySound("mi.wav",NULL,SND_ASYNC);
    PlaySound("fa.wav",NULL,SND_ASYNC);
    PlaySound("so.wav",NULL,SND_ASYNC);

}

這樣會依序播放do,re,mi.,fa,so但整個程式執行會很冗長


4.修改程式碼為以下

    while(1){
        char c=getchar();
        if(c=='z')PlaySound("do.wav",NULL,SND_ASYNC);
        if(c=='x')PlaySound("re.wav",NULL,SND_ASYNC);
        if(c=='c')PlaySound("mi.wav",NULL,SND_ASYNC);
        if(c=='v')PlaySound("fa.wav",NULL,SND_ASYNC);
        if(c=='b')PlaySound("so.wav",NULL,SND_ASYNC);
    }

這樣會按下按鍵後Enter播放對應音檔,並且後按的會蓋過前面的


俗稱鋼琴

5.修改程式碼為以下

#include <windows.h>
#include <stdio.h>
#include <GL/glut.h>
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glutSwapBuffers();
}
void keyboard(unsigned char c,int x,int y)
{
    if(c=='z') PlaySound("do.wav",NULL,SND_ASYNC);
    if(c=='x') PlaySound("re.wav",NULL,SND_ASYNC);
    if(c=='c') PlaySound("mi.wav",NULL,SND_ASYNC);
    if(c=='v') PlaySound("fa.wav",NULL,SND_ASYNC);
    if(c=='b') PlaySound("so.wav",NULL,SND_ASYNC);

}
int main(int argc,char** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("小乖的鋼琴");
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMainLoop();
}

這樣就解決每次都要Enter才會播放的問題,變成按下按鍵就會自動播放


6.修改程式碼為以下

#include <windows.h>
#include <stdio.h>
#include <GL/glut.h>
#include "CMP3_MCI.h"
CMP3_MCI mp3;

void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glutSwapBuffers();
}
void keyboard(unsigned char c,int x,int y)
{
    if(c=='z') PlaySound("do.wav",NULL,SND_ASYNC);
    if(c=='x') PlaySound("re.wav",NULL,SND_ASYNC);
    if(c=='c') PlaySound("mi.wav",NULL,SND_ASYNC);
    if(c=='v') PlaySound("fa.wav",NULL,SND_ASYNC);
    if(c=='b') PlaySound("so.wav",NULL,SND_ASYNC);
}
int main(int argc,char** argv)
{
    mp3.Load("music.mp3");
    mp3.Play();

    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("小乖的鋼琴");
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMainLoop();
}

這樣就能在有背景音樂的狀態下彈鋼琴


7.修改程式碼為以下

#include <windows.h>
#include <stdio.h>
#include <GL/glut.h>
#include "CMP3_MCI.h"
CMP3_MCI mp3;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glutSwapBuffers();
}
void keyboard(unsigned char c,int x,int y)
{
    if(c=='z') PlaySound("do.wav",NULL,SND_ASYNC);
    if(c=='x') PlaySound("re.wav",NULL,SND_ASYNC);
    if(c=='c') PlaySound("mi.wav",NULL,SND_ASYNC);
    if(c=='v') PlaySound("fa.wav",NULL,SND_ASYNC);
    if(c=='b') PlaySound("so.wav",NULL,SND_ASYNC);
}
void Mouse(int button,int state,int x,int y)
{
    if(state==GLUT_DOWN)PlaySound("shot.wav",NULL,SND_ASYNC);
}

int main(int argc,char** argv)
{
    mp3.Load("music.mp3");
    mp3.Play();
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("小乖的鋼琴");
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMouseFunc(Mouse);
    glutMainLoop();
}

這樣就能在有背景音樂的狀態下邊彈鋼琴邊射擊


8.修改程式碼為以下

#include <windows.h>
#include <stdio.h>
#include <GL/glut.h>
#include "CMP3_MCI.h"
CMP3_MCI mp3;
CMP3_MCI shot1,shot2,shot3;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glutSwapBuffers();
}
void keyboard(unsigned char c,int x,int y)
{
    if(c=='z') PlaySound("do.wav",NULL,SND_ASYNC);
    if(c=='x') PlaySound("re.wav",NULL,SND_ASYNC);
    if(c=='c') PlaySound("mi.wav",NULL,SND_ASYNC);
    if(c=='v') PlaySound("fa.wav",NULL,SND_ASYNC);
    if(c=='b') PlaySound("so.wav",NULL,SND_ASYNC);
}
void Mouse(int button,int state,int x,int y)
{
    if(state==GLUT_DOWN&&button==GLUT_LEFT_BUTTON)shot1.Play();
    if(state==GLUT_DOWN&&button==GLUT_MIDDLE_BUTTON)shot2.Play();
    if(state==GLUT_DOWN&&button==GLUT_RIGHT_BUTTON)shot3.Play();

}
int main(int argc,char** argv)
{
    shot1.Load("1.mp3");shot2.Load("2.mp3");shot3.Load("3.mp3");
    mp3.Load("music.mp3");
    mp3.Play();
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("小乖的鋼琴");
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMouseFunc(Mouse);
    glutMainLoop();
}

這樣就能在有背景音樂的狀態下邊彈鋼琴邊用三種武器射擊

2021年4月14日 星期三

小乖的圖學筆記 week08

 1.考期中考(只有80QAQ)

2.複習week07教了些啥子

3.把week-7教的先做一遍(安裝設定啥鬼的)

4.

------------------------------------------------------------------------------------------

練習貼兩張圖

1.開啟GLUT專案

2.將程式碼貼上

#include <opencv/highgui.h> ///使用 OpenCV 2.1 比較簡單, 只要用 High GUI 即可
#include <opencv/cv.h>
#include <GL/glut.h>
GLuint id1, id2; ///TODO:增加2個 貼圖ID
int myTexture(char * filename)
{
    IplImage * img = cvLoadImage(filename); ///OpenCV讀圖
    cvCvtColor(img,img, CV_BGR2RGB); ///OpenCV轉色彩 (需要cv.h)
    glEnable(GL_TEXTURE_2D); ///1. 開啟貼圖功能
    GLuint id; ///準備一個 unsigned int 整數, 叫 貼圖ID
    glGenTextures(1, &id); /// 產生Generate 貼圖ID
    glBindTexture(GL_TEXTURE_2D, id); ///綁定bind 貼圖ID
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); /// 貼圖參數, 超過包裝的範圖T, 就重覆貼圖
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); /// 貼圖參數, 超過包裝的範圖S, 就重覆貼圖
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); /// 貼圖參數, 放大時的內插, 用最近點
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); /// 貼圖參數, 縮小時的內插, 用最近點
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img->width, img->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img->imageData);
    return id;
}
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glBindTexture(GL_TEXTURE_2D, id2);
    glutSolidTeapot(0.3);
    glBindTexture(GL_TEXTURE_2D, id1);
    glBegin(GL_POLYGON);
        glTexCoord2f( 0, 0 ); glVertex2f( -1, 1 );
        glTexCoord2f( 0, 1 ); glVertex2f( -1, -1 );
        glTexCoord2f( 1, 1 ); glVertex2f( +1, -1 );
        glTexCoord2f( 1, 0 ); glVertex2f( +1, 1 );
    glEnd();
    glutSwapBuffers();
}
int main(int argc, char** argv)
{
    glutInit( &argc, argv );
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
    glutCreateWindow(" Week08 ");
    glutDisplayFunc(display);
    id1 = myTexture("puipui.jpg");
    id2 = myTexture("bg.jpg");
    glEnable(GL_DEPTH_TEST);
    glutMainLoop();
}

3.成果展示

------------------------------------------------------------------------------------------

練習打光

1.(接續上面的程式碼)把下面這段貼到main()上

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

2.把下面這段貼到main()裡面Loop上

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

3.成果展示

------------------------------------------------------------------------------------------

玩打光小程式

1.如圖所示

2021年4月7日 星期三

小乖的圖學筆記 week07

貼圖教學

1.安裝OpenCV-2.1.0-win32-vs2008

1-1至moodle下載

1-2安裝注意事項(要點第二個)

2.設定CodeBlocks

2-1 Setting>Compiler>Global compiler settings>Linker settings

新增 cv210

新增 cxcore210

新增 highgui210

2-2 Setting>Compiler>Global compiler settings>Search directories>compiler

新增 C:\OpenCV2.1\include

2-3 Setting>Compiler>Global compiler settings>Search directories>Linker

新增 C:\OpenCV2.1\lib

3.找一張圖放在 C:\Users\Administrator\Desktop\freeglut\bin 裡並重新命名

3-1

3-2

4.打開GLUT專案(自己去week01)

5.編輯程式碼

#include <opencv/highgui.h>

int main(int argc,char** argv)

{

    IplImage*img=cvLoadImage("fight.jpg");

    cvShowImage("fight photo",img);

    cvWaitKey(0);

}

------------------------------------------------------------------------------------------

幫茶壺貼圖

1.打開GLUT專案(自己去week01

2.編輯程式碼(太長了 自己去 Git Hub下載07-2)

------------------------------------------------------------------------------------------

貼圖練習

1.打開GLUT專案(自己去week01

2.編輯程式碼(太長了 自己去 Git Hub下載07-3)

------------------------------------------------------------------------------------------

做地球儀

1.到 https://hackmd.io/@jsyeh/opengl下載

2.打開GLUT專案(自己去week01

3.編輯程式碼(貼上下載來的main源碼)

距地表面160 Week11

 #include "glm.h" GLMmodel* pmodel = NULL; void drawmodel(void) {     if (!pmodel) { pmodel = glmReadOBJ("data/porsche.obj...