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電腦圖學 Computer Graphics 授課教師: 葉正聖 銘傳大學資訊傳播工程系 每週主題: 程式環境、點線面顏色、移動/旋轉/縮放與矩陣(Matrix)、階層性關節轉動(T-R-T)、做出機器人、打光、貼圖、glu/glut函式、鍵盤、滑鼠、計時器(timer)、讀入3D模型、粒子系統、聲音、特效、投影矩陣、攝影機與運鏡、機器人2.0、期末作品
1.安裝3DEXPLOR181
2.開啟3DEXPLOR181
3.將鋼彈模型匯入
4.將鋼彈模型匯出成cpp檔
5.開啟glut專案
6.把main.cpp改成鋼彈的程式碼並按照下面兩張圖做新增&修改
7.把匯出鋼彈模型的bmp檔放在C:\Users\Administrator\Desktop\freeglut\bin
8.程式運行長這樣(會旋轉跳動)
9.把旋轉和縮放註解掉
10.切割模型的練習
11.把老師給的程式碼貼上去執行就行了
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裡的程式碼刪掉至剩下
並且從GitHub裡下載並複製
void display()以及int main()
修改成以下
8.程式碼執行如下
9.加入打光程式碼兩段並翻轉模型
加在void display()以及int main()之間
加在int main()裡的glutDisplayFunc(display);以及glutCreateWindow(" ");之間
加上這段已翻轉模型
10.程式碼執行如下
11.安裝OpenCV並重開(教學在week08)
12.開啟老師給的gundam中的cbp檔並執行
上一周期中考啦哈哈
------------------------------------------------------------------------------------------
這周教添加音樂
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.修改程式碼為以下
這樣就解決每次都要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();
}
這樣就能在有背景音樂的狀態下邊彈鋼琴邊用三種武器射擊
1.考期中考(只有80QAQ)
2.複習week07教了些啥子
3.把week-7教的先做一遍(安裝設定啥鬼的)
4.
------------------------------------------------------------------------------------------
練習貼兩張圖
1.開啟GLUT專案
2.將程式碼貼上
3.成果展示
------------------------------------------------------------------------------------------
練習打光
1.(接續上面的程式碼)把下面這段貼到main()上
2.把下面這段貼到main()裡面Loop上
貼圖教學
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源碼)
#include "glm.h" GLMmodel* pmodel = NULL; void drawmodel(void) { if (!pmodel) { pmodel = glmReadOBJ("data/porsche.obj...