最後一周 期末作品展示
心得
這一學期匆忙且忙碌的過去了,在這最後的期末作品中雖然跟一些同學相比實在是相當的簡陋,不過在當下那個焦頭爛額的場合也算是煞費了一番苦心才做出成果,整體而言也算是滿意了,也感謝老師這一學期的教導。
2017電腦圖學 Computer Graphics 授課教師: 葉正聖 銘傳大學資訊傳播工程系 每週主題: 程式環境、點線面顏色、移動/旋轉/縮放與矩陣(Matrix)、階層性關節轉動(T-R-T)、做出機器人、打光、貼圖、glu/glut函式、鍵盤、滑鼠、計時器(timer)、讀入3D模型、粒子系統、聲音、特效、投影矩陣、攝影機與運鏡、機器人2.0、期末作品
2017年6月29日 星期四
2017年6月12日 星期一
week 14 楊語琛的上課筆記 レ(゚∀゚;)ヘ=З=З=З
一 程式 示範背景
1 myEarth.zip變背景貼圖
freeglut裝桌面\freeglut\include\lib\bin
OpenCV2.1裝C:\OpenCV2.1\include\lib\bin
把display裡///畫地球
glTexCoord2f(1,0);glVertex3f(+1,+1,0);
glTexCoord2f(1,1);glVertex3f(+1,-1,0);
glTexCoord2f(0,1);glVertex3f(-1,-1,0);
glEnd();
1 myEarth.zip變背景貼圖
freeglut裝桌面\freeglut\include\lib\bin
OpenCV2.1裝C:\OpenCV2.1\include\lib\bin
把display裡///畫地球
2 程式部分
glBegin(GL_POLYGON);///開始要畫背景
glTexCoord2f(0,0);glVertex3f(-1,+1,0);glTexCoord2f(1,0);glVertex3f(+1,+1,0);
glTexCoord2f(1,1);glVertex3f(+1,-1,0);
glTexCoord2f(0,1);glVertex3f(-1,-1,0);
glEnd();
解釋: 如以前考試內容一樣
glTexCoord2f(a,b); 代表貼圖的座標
glVertex3f(a,b,c); 代表3D的頂點位置

#附註 今天有介紹直播內容
2017年6月5日 星期一
week 13 楊語琛的上課筆記 レ(゚∀゚;)ヘ=З=З=З
一 內差公式
1 Excel的公式應用

例: 薪水就是角度
公式:Alpha*NewAngle+(1-Alpha)*OldAngle
FILE*font=NULL;//檔案指標
if(key=='s' || key='S')
{
if(fout==NULL)
fout=fopen("file.txt", "w+");
}
1 Excel的公式應用

例: 薪水就是角度
公式:Alpha*NewAngle+(1-Alpha)*OldAngle
2 解壓老師的專案以及把freeglut的壓縮檔案拉到桌面並且開啟專案,加入內插公式
應用上周的內容加入Timer使機器人會動

3 寫檔案
#include<stdio.h>FILE*font=NULL;//檔案指標
if(key=='s' || key='S')
{
if(fout==NULL)
fout=fopen("file.txt", "w+");
}

2017年5月22日 星期一
week 12 楊語琛的上課筆記 レ(゚∀゚;)ヘ=З=З=З
一 旋轉模型
先建出自己想要使用的模型
上面先設float angle=0;
float++;
glPushMatrix();
glRotatef(angle, 0,1,0);
中間放入自己想使之旋轉的部件
glPopMatrix();
二 加入時間流逝,配合Timer旋轉
#include <stdio.h>
void timer(int t)///計時器叫的時候, 要做什麼呢?
{
glutTimerFunc(100, timer, t+1);///先撥下一個鬧鐘
angle++;///做了要做的事
printf("現在時間是 %d, 我起床了, 等一下鬧鐘會再叫一下哦 ", t);
glutPostRedisplay();///提醒電腦,有空要畫一下畫面哦
printf("... 然後我就又睡了....\n");
}///再度沈睡

2017年5月15日 星期一
week 11 楊語琛的上課筆記 レ(゚∀゚;)ヘ=З=З=З
一 小考內容示範
glRotatef(30 , 0 , 0.1);///20%,對Z軸作angle旋轉角度
glTranslatef(0.5 , 0.3 , 0);///20%,把旋轉中心點,放到畫面的中間
drawArm();20%///畫一個手腕
glPopMatrix();10%
\bin\很多dll檔
F9執行
glPushMatrix();10%
glTranslatef(0.4 , 0.5 , 0);///20%,再把會旋轉的手腕,放在(0.4 , 0.5 , 0)glRotatef(30 , 0 , 0.1);///20%,對Z軸作angle旋轉角度
glTranslatef(0.5 , 0.3 , 0);///20%,把旋轉中心點,放到畫面的中間
drawArm();20%///畫一個手腕
glPopMatrix();10%

二 OpenCV開圖
1 安裝opencv-2.1.0-vs2008.exe
確認c:\OpenCV2.1\include\opcncv\很多.h檔
\lib\很多lib檔\bin\很多dll檔
2 新增貝殼專案,File-New-Project,右上角Console App
解壓縮myEarth.zip
freeglut到c:\users\user\Desktop\freeglut{include、lib、bin}
myEarth專案檔,開起來F9執行

2017年5月8日 星期一
week 10 楊語琛的上課筆記 レ(゚∀゚;)ヘ=З=З=З
一 本周重點
攝影機運鏡
會動的機器人
glut32.dll
glRotatef();
glTranslatef();
glPopMatrix();

3DTRT轉動
矩陣、投影矩陣攝影機運鏡
會動的機器人
二 內容
1 先下載
data.zip
windows.zipglut32.dll
2
gluLookAt(eyeX,eyeY,eyeZ(修改、攝影機),centerX,centerY,centerZ,upX,upY,upZ);
其中
eye-表示攝影機視角
center-表示中央位置
up-表示俯視視角
3
開啟04160011_hw1_projection.zip
更改glutLookAt的eyeX、eyeY、eyeZ

4
修改視野角度gluPerspective(fovy,1(xy比例),Near,Far)
5
新增程式碼
glPushMatrix();
glTranlatef();glRotatef();
glTranslatef();
glPopMatrix();
便可得到有手的茶壺

2017年5月1日 星期一
week 09 楊語琛的上課筆記 レ(゚∀゚;)ヘ=З=З=З
一 重點
(1) 組合出機器人
(2) 做出可轉動的關節
(3) 錄製動作
(4) 回家作業:機器人
二 過程
上網搜尋google:3D Exploration
3D Exploration 1.81(橘色、免費試用版本)
下載data.zip
接著用3D Exploration開啟,將其另存為cpp檔案,File-Save As,選Cpp Open GL...,在某目錄(桌面)下來,勾匯出Export Dialog,出現框框,選Sample App

CodeBlocks,File-New-Project,OpenGL專案
(把main.c移除,換soccerball.cpp)-
刪掉兩行程式碼
使用data.zip、source.zip、freeglut.zip、myGLMsample.zip
使用CodeBlock開啟myGLMsample資料夾的cpb檔案
修改程式後即可印出2隻調整過位置跟大小的海豚
利用3D Exploration將海豚分開儲存成3隻obj、mlt檔案
放進myGLMsample資料夾裡面的data資料夾

2017年4月24日 星期一
week 08 楊語琛的上課筆記 レ(゚∀゚;)ヘ=З=З=З
一 試玩射擊遊戲
Visual c++的範例
解壓縮桌面\Lesson32\lesson32.exe
{
PlaySound("C:\\Users\\user\\Desktop\\lesson32/Data/shot.wav",NULL,SND_ASYNC);
}
glutMouseFunc(mouse);
if(key=='1') PlaySound("MachineGun.wav",NULL,SND_ASYNC);
if(key=='2') PlaySound("xm1014-1.wav",NULL,SND_ASYNC);
if(key=='3') PlaySound("UZI",NULL,SND_ASYNC);
}
glutKeyboardFunc(keyboard);修改成設定的keyboard
下載的wav檔案,要放進freeglut內的bin資料夾內
#include <mmsystem.h>
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
myMP3.Load("C:\\Users\\user\\Desktop\\yukai.mp3"); /// "C:/dropbox/yukai.mp3"
myMP3.Play();
Google:NeHe Lesson32
下載Lesson32最下面Visual c++的範例
解壓縮桌面\Lesson32\lesson32.exe

二 嵌入自己的程式碼
1
#include <mmsystem.h>//多媒體系統
void mouse(int button, int state, int x, int y){
PlaySound("C:\\Users\\user\\Desktop\\lesson32/Data/shot.wav",NULL,SND_ASYNC);
}
glutMouseFunc(mouse);
2
void keyboard(unsigned char key, int x, int y)
{if(key=='1') PlaySound("MachineGun.wav",NULL,SND_ASYNC);
if(key=='2') PlaySound("xm1014-1.wav",NULL,SND_ASYNC);
if(key=='3') PlaySound("UZI",NULL,SND_ASYNC);
}
glutKeyboardFunc(keyboard);修改成設定的keyboard
下載的wav檔案,要放進freeglut內的bin資料夾內
3
去FB社團內載CMP3_MCI.h檔案並放進codeblacks的專案裡
程式碼:#include <mmsystem.h>
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
myMP3.Load("C:\\Users\\user\\Desktop\\yukai.mp3"); /// "C:/dropbox/yukai.mp3"
myMP3.Play();
2017年4月17日 星期一
week 07 楊語琛的上課筆記 レ(゚∀゚;)ヘ=З=З=З
一 期中考
二 TRT介紹
三 讀入3D模型
下載檔案
source.zip(glm.h,glm.cpp)
windows.zip
data.zip
glut32.dll
並且將data,source,2個壓縮檔案解壓到windows內,glut32.dll也放進去
vn開頭→vertex normal
vt開頭→vertex texture coordinate
f開頭→face 臉、面
二 TRT介紹
三 讀入3D模型
下載檔案
source.zip(glm.h,glm.cpp)
windows.zip
data.zip
glut32.dll
並且將data,source,2個壓縮檔案解壓到windows內,glut32.dll也放進去
1. 切換模型
2. 開啟soccerball.obj(mlt)---Notepad++開啟
v開頭→vertexvn開頭→vertex normal
vt開頭→vertex texture coordinate
f開頭→face 臉、面
2017年4月10日 星期一
week 06 楊語琛的上課筆記 レ(゚∀゚;)ヘ=З=З=З
1.期中模擬考+複習考試內容:
glTranslatef(x,y,z);//移動
glScalef(x,y,z);//縮放
glBegin(GL_POLYGON);//開始畫
glNormal3f(nx.ny.nz);打光的法向量
glTexCoord2f(tx,ty);//貼圖的座標
glColor3f(r,g,b)//顏色
glVertex3f(x,y,z);//頂點
glEnd();//結束畫
glPopMatrix();//還原矩陣
2.茶壺打光
先畫一個茶壺,後續要新增功能
一 先打光

二 調整GLfloat light_position(打光數值)

三 讓茶壺旋轉

四 使他自動旋轉

(自動旋轉的程式碼為glutIdleFunc(display);)
glPushMatrix()://備份矩陣
glRotatef(angle, x, y, z);//旋轉glTranslatef(x,y,z);//移動
glScalef(x,y,z);//縮放
glBegin(GL_POLYGON);//開始畫
glNormal3f(nx.ny.nz);打光的法向量
glTexCoord2f(tx,ty);//貼圖的座標
glColor3f(r,g,b)//顏色
glVertex3f(x,y,z);//頂點
glEnd();//結束畫
glPopMatrix();//還原矩陣
2.茶壺打光
先畫一個茶壺,後續要新增功能
一 先打光

二 調整GLfloat light_position(打光數值)

三 讓茶壺旋轉

四 使他自動旋轉

(自動旋轉的程式碼為glutIdleFunc(display);)
week 05 楊語琛的上課筆記 レ(゚∀゚;)ヘ=З=З=З
1.說明期中考內容
大小寫要正確
glPushMatrix();//備份矩陣 10% (stack push)
glRotatef(angle, x, y, z);//旋轉 30%
glTranslatef(x,y,z);/移動 40%
glScalef(x,y,z);//縮放 50%
glBegin(GL_POLYGON);//開始畫 60%
glNormal3f(nx,ny,ny);//打光的法向量 90%
glTexCoord2f(tx,ty);//貼圖的座標 100%
glColor3f(r,g,b);// 顏色 70%
glVertex3f(x,y,z);//頂點 80%
glEnd();//結束畫(與開始畫共同算分)
glPopMatrix();//還原矩陣 20% (stack pop)
2.
下載win32、data、glut32.dll
開啟windows資料夾下的Transform
利用 glTranslatef()控制移動
利用 glScalef()控制大小
大小寫要正確
glPushMatrix();//備份矩陣 10% (stack push)
glRotatef(angle, x, y, z);//旋轉 30%
glTranslatef(x,y,z);/移動 40%
glScalef(x,y,z);//縮放 50%
glBegin(GL_POLYGON);//開始畫 60%
glNormal3f(nx,ny,ny);//打光的法向量 90%
glTexCoord2f(tx,ty);//貼圖的座標 100%
glColor3f(r,g,b);// 顏色 70%
glVertex3f(x,y,z);//頂點 80%
glEnd();//結束畫(與開始畫共同算分)
glPopMatrix();//還原矩陣 20% (stack pop)
2.
下載win32、data、glut32.dll
開啟windows資料夾下的Transform
利用 glTranslatef()控制移動
利用 glScalef()控制大小
2017年3月20日 星期一
week 04 楊語琛的上課筆記 レ(゚∀゚;)ヘ=З=З=З
1. 首先打開之前的網址(jsyeh.org/3dcg10)
下載下 "data" "win32" "glut32.dll" 三個檔案
在把下載下來的win32選擇解壓縮到win32資料夾
之後再把data解壓縮進win32資料夾
最後再把glut32.dll也丟進去
之後開啟資料夾內的Transformation檔案即可得到下圖
2.打開CodeBlocks 並打出上周的程式碼
#include<GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT |Transformation GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(0.5,0,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("04162470 Translate Rotate Scale");
glutDisplayFunc(display);
///glutMouseFunc(mouse);
///glutMotionFunc(motion);
glutMainLoop();
}
如下圖
3.加入mouse程式碼並修改一下變更成
#include<GL/glut.h>
float mouseX=0, mouseY=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(mouseX,mouseY,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int x, int y)
{
mouseX=(x-150)/150.0;
mouseY=-(y-150)/150.0;
glutPostRedisplay();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("04162470 Translate Rotate Scale");
glutDisplayFunc(display);
///glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
即可隨滑鼠移動了
4.若把上面加註那行
glTranslatef(mouseX,mouseY,0);
改成
glScale(mouseX,mouseY,0);
則可達成隨滑鼠放大縮小的功能
下載下 "data" "win32" "glut32.dll" 三個檔案
在把下載下來的win32選擇解壓縮到win32資料夾
之後再把data解壓縮進win32資料夾
最後再把glut32.dll也丟進去
之後開啟資料夾內的Transformation檔案即可得到下圖
#include<GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT |Transformation GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(0.5,0,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("04162470 Translate Rotate Scale");
glutDisplayFunc(display);
///glutMouseFunc(mouse);
///glutMotionFunc(motion);
glutMainLoop();
}
如下圖
3.加入mouse程式碼並修改一下變更成
#include<GL/glut.h>
float mouseX=0, mouseY=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(mouseX,mouseY,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int x, int y)
{
mouseX=(x-150)/150.0;
mouseY=-(y-150)/150.0;
glutPostRedisplay();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("04162470 Translate Rotate Scale");
glutDisplayFunc(display);
///glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
即可隨滑鼠移動了
4.若把上面加註那行
glTranslatef(mouseX,mouseY,0);
改成
glScale(mouseX,mouseY,0);
則可達成隨滑鼠放大縮小的功能
2017年3月13日 星期一
week 03 楊語琛的上課筆記 レ(゚∀゚;)ヘ=З=З=З
1.
複習上周的作業1,2
做出茶壺,如下圖
並加入-
glutMouseFunc(mouse);
glutMotionFunc(motion);
兩行
這兩行是本周的重點_關於滑鼠的應用
滑鼠拆解動作,分隔成按下與放開
先加入兩行
#include<math.h>
#include <stdio.h>
在進入本周的重頭戲 關於滑鼠的參數
void mouse(int button, int state, int x, int y)
{
printf("%d %d %d %d\n",button, state, x, y);
}
這一組涵式便可以印出我們滑鼠所案的位置所含的座標數字並印出來 完成作業1
2.
在上面的涵式中,增加兩行程式碼
glColor3f( 1 , x/300.0 , y/300.0);
glutPostRedisplay();
以控制茶壺的顏色
可是控制RGB的3個參數並不能靠XY的兩個座標替代,所以先用1來代替
加入一個motion涵式void motion(int x, int y)
並把上面的
glColor3f( 1 , x/500.0 , y/500.0);
glutPostRedisplay();
移下來
最後再把下面那行剛剛還沒用到的
glutMotionFunc(motion);打上來
便可完成隨著滑鼠移動同時變色的程式了
3.
刪除剛剛茶壺的程式碼
glutSolidTeapot(0.3);
再加入glclear(GL_COLORBUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glBegin(GL_POLYGON);
for(float angle=0;angle<3.1415926*2;angle+=0.001)
{
glVertex2f(cos(angle),sin(angle));
}
glEnd();
glutSwapBuffers();
即可畫出圓形
複習上周的作業1,2
做出茶壺,如下圖
並加入-
glutMouseFunc(mouse);
glutMotionFunc(motion);
兩行
這兩行是本周的重點_關於滑鼠的應用
滑鼠拆解動作,分隔成按下與放開
先加入兩行
#include<math.h>
#include <stdio.h>
在進入本周的重頭戲 關於滑鼠的參數
void mouse(int button, int state, int x, int y)
{
printf("%d %d %d %d\n",button, state, x, y);
}
這一組涵式便可以印出我們滑鼠所案的位置所含的座標數字並印出來 完成作業1
2.
在上面的涵式中,增加兩行程式碼
glColor3f( 1 , x/300.0 , y/300.0);
glutPostRedisplay();
以控制茶壺的顏色
可是控制RGB的3個參數並不能靠XY的兩個座標替代,所以先用1來代替
加入一個motion涵式void motion(int x, int y)
並把上面的
glColor3f( 1 , x/500.0 , y/500.0);
glutPostRedisplay();
移下來
最後再把下面那行剛剛還沒用到的
glutMotionFunc(motion);打上來
便可完成隨著滑鼠移動同時變色的程式了
3.
刪除剛剛茶壺的程式碼
glutSolidTeapot(0.3);
再加入glclear(GL_COLORBUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glBegin(GL_POLYGON);
for(float angle=0;angle<3.1415926*2;angle+=0.001)
{
glVertex2f(cos(angle),sin(angle));
}
glEnd();
glutSwapBuffers();
即可畫出圓形
2017年3月6日 星期一
week 02 楊語琛的上課筆記 レ(゚∀゚;)ヘ=З=З=З
HW01
首先打開上次的作業2跟作業3檔案
刪減作業3的程式碼 化簡為10行
註解如圖
逐得到解答__茶壺
增加一行設定顏色的部分如下圖(分別設定RGB)
最後在主程式中加入一段程式碼
分別代表著更改三角形的位置(座標) 顏色
2017年2月20日 星期一
week 01 楊語琛的上課筆記 レ(゚∀゚;)ヘ=З=З=З
HW01:
HW02:
開啟CodeBlocks
新增檔案選擇New->Project
選擇OpenGL project
HW03:
開啟CodeBlocks並開啟新檔選擇New->project
選擇GLUT
開啟老師給的檔案
最後執行程式碼得到結果
訂閱:
文章 (Atom)


























