04160214_期末作品
2017電腦圖學 Computer Graphics 授課教師: 葉正聖 銘傳大學資訊傳播工程系 每週主題: 程式環境、點線面顏色、移動/旋轉/縮放與矩陣(Matrix)、階層性關節轉動(T-R-T)、做出機器人、打光、貼圖、glu/glut函式、鍵盤、滑鼠、計時器(timer)、讀入3D模型、粒子系統、聲音、特效、投影矩陣、攝影機與運鏡、機器人2.0、期末作品
2017年6月28日 星期三
2017年6月6日 星期二
week16 上課筆記
week16
(1)下周期末作品Demo
(2)內插公式vs動作
(3)存檔 讀檔
(4)利用Timer自動內插
(5)學期複習
TODO:
用Excel試內插公式
=A2*新+(1-A2)*舊
todo:
Build範例
用notepad++改freeglut正確位址
(a) working目錄
(b)include,lib目錄
TODO:
做動作並存檔
///hw1_動作存檔_mouse_keyboard.cpp
///目標: angle[] 存起來, file.txt
#include <stdio.h> ///存檔的步驟1: #include <stdio.h> 裡面有 printf, scanf, fprintf, fscanf
FILE * fout=NULL;///存檔的步驟2, 宣告一個檔案的指標, (一開始是空的NULL)
void keyboard(unsigned char key,int x,int y)
{
printf("%c\n", key);///你按了什麼鍵,印出來,方便了解老師按了什麼鍵
if(key=='s'){///存檔的步驟3, 在按下 's' 鍵 save存檔
if(fout == NULL){/// (一開始是空的NULL)
fout = fopen("file.txt", "w+");///開啟檔案,檔名準備好, 並且是用 write加 模式
printf("現在開啟一個檔案file.txt, w+模式\n");
}
printf("想要寫這些數值到檔案%f %f %f %f %f %f %f %f %f\n", angle[0], angle[1], angle[2], angle[3], angle[4], angle[5], angle[6], angle[7], angle[8]);
fprintf( fout, "%f %f %f %f %f %f %f %f %f\n", angle[0], angle[1], angle[2], angle[3], angle[4], angle[5], angle[6], angle[7], angle[8]);
}
TODO:
讀檔案
FILE * fin=NULL;///讀檔的步驟1, 宣告一個檔案的指標, (一開始是空的NULL)
if(key=='r'){///讀檔的步驟2, 按下 'r' 去read
if(fin == NULL){
fin = fopen("file.txt", "r");///讀檔的步驟3,檔名準備好, 並且是用 read 模式
printf("Now open file.txt for read Mode\n");
}
fscanf(fin, "%f %f %f %f %f %f %f %f %f", &angle[0], &angle[1], &angle[2], &angle[3], &angle[4], &angle[5], &angle[6], &angle[7], &angle[8]);
printf("Now read angle[] Pa Pa Pa\n"); ///讀檔的步驟 fscanf()讀進來
glutPostRedisplay();///重製畫面
}
TODO:
動作存檔加讀檔加內插
float alpha=0.0;///現在要改成交叉相乘的內插方式算角度: alpha
float oldAngle[20]={};///現在要改成交叉相乘的內插方式算角度: oldAngle
float newAngle[20]={};///現在要改成交叉相乘的內插方式算角度: newAngle
float angle[20]={};///現在要改成交叉相乘的內插方式算角度: 我們要用來畫的 angle 的陣列
int now=0;
if(key=='r'){///讀檔的步驟2, 按下 'r' 去read, ///現在要改成交叉相乘的內插方式算角度
if(fin == NULL){
fin = fopen("file.txt", "r");///讀檔的步驟3,檔名準備好, 並且是用 read 模式
printf("Now open file.txt for read Mode\n");
fscanf(fin, "%f %f %f %f %f %f %f %f %f", &newAngle[0], &newAngle[1], &newAngle[2], &newAngle[3], &newAngle[4], &newAngle[5], &newAngle[6], &newAngle[7], &newAngle[8]);
}
if(alpha >= 1.0){///如果讀太多,alpha超過了, 就要再讀新的angle, 而且要把原來新的,先變舊的
/// oldAngle = newAngle
for(int i=0;i<9;i++) oldAngle[i] = newAngle[i];
/// read newAngle
fscanf(fin, "%f %f %f %f %f %f %f %f %f", &newAngle[0], &newAngle[1], &newAngle[2], &newAngle[3], &newAngle[4], &newAngle[5], &newAngle[6], &newAngle[7], &newAngle[8]);
printf("Now read angle[] Pa Pa Pa\n"); ///讀檔的步驟 fscanf()讀進來
alpha=0.0;
}
///angle = alpha * newAngle + (1-alpha)* oldAngle;
for(int i=0;i<9;i++){///小心, 角度不見得只有9個,可能更多哦! 要調好,有更多,就要內插更多 ex. 20個
angle[i]=alpha*newAngle[i] + (1-alpha)*oldAngle[i];///現在要改成交叉相乘的內插方式算角度
}
alpha += 0.1;///現在要改成交叉相乘的內插方式算角度, 每次加一點點alpha
glutPostRedisplay();
}
(1)下周期末作品Demo
(2)內插公式vs動作
(3)存檔 讀檔
(4)利用Timer自動內插
(5)學期複習
TODO:
用Excel試內插公式
=A2*新+(1-A2)*舊
todo:
Build範例
用notepad++改freeglut正確位址
(a) working目錄
(b)include,lib目錄
TODO:
做動作並存檔
///hw1_動作存檔_mouse_keyboard.cpp
///目標: angle[] 存起來, file.txt
#include <stdio.h> ///存檔的步驟1: #include <stdio.h> 裡面有 printf, scanf, fprintf, fscanf
FILE * fout=NULL;///存檔的步驟2, 宣告一個檔案的指標, (一開始是空的NULL)
void keyboard(unsigned char key,int x,int y)
{
printf("%c\n", key);///你按了什麼鍵,印出來,方便了解老師按了什麼鍵
if(key=='s'){///存檔的步驟3, 在按下 's' 鍵 save存檔
if(fout == NULL){/// (一開始是空的NULL)
fout = fopen("file.txt", "w+");///開啟檔案,檔名準備好, 並且是用 write加 模式
printf("現在開啟一個檔案file.txt, w+模式\n");
}
printf("想要寫這些數值到檔案%f %f %f %f %f %f %f %f %f\n", angle[0], angle[1], angle[2], angle[3], angle[4], angle[5], angle[6], angle[7], angle[8]);
fprintf( fout, "%f %f %f %f %f %f %f %f %f\n", angle[0], angle[1], angle[2], angle[3], angle[4], angle[5], angle[6], angle[7], angle[8]);
}
TODO:
讀檔案
FILE * fin=NULL;///讀檔的步驟1, 宣告一個檔案的指標, (一開始是空的NULL)
if(key=='r'){///讀檔的步驟2, 按下 'r' 去read
if(fin == NULL){
fin = fopen("file.txt", "r");///讀檔的步驟3,檔名準備好, 並且是用 read 模式
printf("Now open file.txt for read Mode\n");
}
fscanf(fin, "%f %f %f %f %f %f %f %f %f", &angle[0], &angle[1], &angle[2], &angle[3], &angle[4], &angle[5], &angle[6], &angle[7], &angle[8]);
printf("Now read angle[] Pa Pa Pa\n"); ///讀檔的步驟 fscanf()讀進來
glutPostRedisplay();///重製畫面
}
TODO:
動作存檔加讀檔加內插
float alpha=0.0;///現在要改成交叉相乘的內插方式算角度: alpha
float oldAngle[20]={};///現在要改成交叉相乘的內插方式算角度: oldAngle
float newAngle[20]={};///現在要改成交叉相乘的內插方式算角度: newAngle
float angle[20]={};///現在要改成交叉相乘的內插方式算角度: 我們要用來畫的 angle 的陣列
int now=0;
if(key=='r'){///讀檔的步驟2, 按下 'r' 去read, ///現在要改成交叉相乘的內插方式算角度
if(fin == NULL){
fin = fopen("file.txt", "r");///讀檔的步驟3,檔名準備好, 並且是用 read 模式
printf("Now open file.txt for read Mode\n");
fscanf(fin, "%f %f %f %f %f %f %f %f %f", &newAngle[0], &newAngle[1], &newAngle[2], &newAngle[3], &newAngle[4], &newAngle[5], &newAngle[6], &newAngle[7], &newAngle[8]);
}
if(alpha >= 1.0){///如果讀太多,alpha超過了, 就要再讀新的angle, 而且要把原來新的,先變舊的
/// oldAngle = newAngle
for(int i=0;i<9;i++) oldAngle[i] = newAngle[i];
/// read newAngle
fscanf(fin, "%f %f %f %f %f %f %f %f %f", &newAngle[0], &newAngle[1], &newAngle[2], &newAngle[3], &newAngle[4], &newAngle[5], &newAngle[6], &newAngle[7], &newAngle[8]);
printf("Now read angle[] Pa Pa Pa\n"); ///讀檔的步驟 fscanf()讀進來
alpha=0.0;
}
///angle = alpha * newAngle + (1-alpha)* oldAngle;
for(int i=0;i<9;i++){///小心, 角度不見得只有9個,可能更多哦! 要調好,有更多,就要內插更多 ex. 20個
angle[i]=alpha*newAngle[i] + (1-alpha)*oldAngle[i];///現在要改成交叉相乘的內插方式算角度
}
alpha += 0.1;///現在要改成交叉相乘的內插方式算角度, 每次加一點點alpha
glutPostRedisplay();
}
2017年5月23日 星期二
第十四周電腦圖學筆記
(一) 上周作業
(二)讓機器人動
(三)Timer計時器
(四)鍵盤滑鼠控制
(五)機器人2.0
TODO:用同學範例
(1).cbp檔用notepad++開啟,include目錄,lib目錄設對
working目錄設"."
(2) Build &Run
Timer計時器:
#include <stdio.h>
void timer(int t)
{
printf("現在我起床了, t是%d...", t);
glutTimerFunc(100, timer, t+1);
printf("我撥了一個新的timer....");
angle+=3;
glutPostRedisplay();
printf("記得重畫畫面哦! 我睡了, bye\n");
}
(二)讓機器人動
(三)Timer計時器
(四)鍵盤滑鼠控制
(五)機器人2.0
TODO:用同學範例
(1).cbp檔用notepad++開啟,include目錄,lib目錄設對
working目錄設"."
(2) Build &Run
Timer計時器:
#include <stdio.h>
void timer(int t)
{
printf("現在我起床了, t是%d...", t);
glutTimerFunc(100, timer, t+1);
printf("我撥了一個新的timer....");
angle+=3;
glutPostRedisplay();
printf("記得重畫畫面哦! 我睡了, bye\n");
}
int main(int argc, char**argv)裡面+
glutTimerFunc(2000,timer,0);
2000=秒數,timer呼叫函式,0=參數
旋轉手臂
先把手臂位子放到函式裡
void drawArm0()
{
....;
}
先把手臂位子放到函式裡
void drawArm0()
{
....;
}
在召喚左手臂回來
glPushMatrix();
//drawBody();
//glutSolidTeapot(0.03);
glPushMatrix();///Left Part
glTranslatef(-0.22, +0.35, 0);///(3) 最後,把它掛在對的位置
glRotatef(-angle, 0,0,1); ///(1) 先轉動
glTranslatef(0.22, -0.35, 0);///(2) move the rotate center to center
drawArm0();//先搞定上手臂在搞定下手臂
glTranslatef(-0.48, +0.1, 0);///(3) 最後,把它掛在對的位置
glRotatef(-angle, 0,0,1);///(1) 先轉動
glTranslatef(0.48, -0.1, 0);///(2) 接著將旋轉中心,放到真的中心, 記得把樓上先註解掉
drawArm1();
glPopMatrix();
glPopMatrix();
右手臂:
用滑鼠拖曳(用滑鼠轉角度)
用鍵盤+滑鼠控制各部位
float angle[8] = {} ;///全家都是零(看幾個關節)
int now=0;
int oldX=0, oldY=0;
void keyboard(unsigned char key, int x, int y)
{
if(key=='0')now=0;
if(key=='1')now=1;
if(key=='2')now=2;
if(key=='3')now=3;
if(key=='4')now=4;
}
void mouse(int button, int state, int x, int y)
{
oldX=x; oldY=y;
glutPostRedisplay();
}
void motion(int x, int y)
{
angle[now] += (x-oldX);
oldX=x;
glutPostRedisplay();
}
int main裡面
glutKeyboardFunc(keyboard);
2017年5月16日 星期二
第十三周隨堂筆記
(1)小考:T-R-T觀念
(2)上周範例
(3)讀圖檔
(4)貼圖設定
(5)轉動的地球
(6)回家作業:機器人
一、複習T-R-T觀念
glPushMatrix();
glTranslatef(....); 第四步:把'會照著手肘中心轉動的手'移動,掛到真的世界畫面裡
glRotatef(.....); 第三步:旋轉
glTranslatef(......); 第二步:把手肘移到畫面中心
drawHand(.....); 第一步:畫手,位置不能錯,由下往上看
glPopMatrix();
二、讀圖檔
(1)google 搜尋OpenCV2.1 download
(2) 下載第二個 path設定第三個
(3)設定專案 console application
#include <opencv/highgui.h> //opencv目錄,高級的gui使用者介面
int main()
{
IplImage * img =cvLoadImage("C:/cc303.jpg"); //讀檔案
cvShowImage("04160214",img); //視窗名,秀圖片
cvWaitKey(0); // 等一下,程式等一下再結束
}
但是會有錯,在專案按右鍵 Build optin
search directions-Compiler-c;/opencv2.1/include
search directions-Compiler-c;/opencv2.1/lib
Linker settings-新增cv210,cscore210,highgui201
(2)上周範例
(3)讀圖檔
(4)貼圖設定
(5)轉動的地球
(6)回家作業:機器人
一、複習T-R-T觀念
glPushMatrix();
glTranslatef(....); 第四步:把'會照著手肘中心轉動的手'移動,掛到真的世界畫面裡
glRotatef(.....); 第三步:旋轉
glTranslatef(......); 第二步:把手肘移到畫面中心
drawHand(.....); 第一步:畫手,位置不能錯,由下往上看
glPopMatrix();
二、讀圖檔
(1)google 搜尋OpenCV2.1 download
(2) 下載第二個 path設定第三個
(3)設定專案 console application
#include <opencv/highgui.h> //opencv目錄,高級的gui使用者介面
int main()
{
IplImage * img =cvLoadImage("C:/cc303.jpg"); //讀檔案
cvShowImage("04160214",img); //視窗名,秀圖片
cvWaitKey(0); // 等一下,程式等一下再結束
}
但是會有錯,在專案按右鍵 Build optin
search directions-Compiler-c;/opencv2.1/include
search directions-Compiler-c;/opencv2.1/lib
Linker settings-新增cv210,cscore210,highgui201
三、開起轉動地球
下載earth專案,freeglut放桌面
把圓形改成茶壺
2017年5月9日 星期二
week12 隨堂筆記
(1) 3D TRT轉動
(2) 矩陣 投影矩陣
(3) 攝影機運鏡
(4) 會動的機器
(5)補 MP3播放
mp3播放
todo:播mp3最簡單 CMP_MCI.h
#include "CMP3_MCI.h" //檔案放在目錄
CMP3_MCI myMP3; // 宣告變數
在int main()裡
int main(....)
myMP3.Load("音樂.mp3"); //Load檔案
myMP3.Play(); // play播放
若無法執行跑出CMP3_MCI.CPP
則點選專題 按右鍵 Build Option Linker setting add winmm(新增媒體播放)
float centerX=0,centerY=0,centerZ=0;
float upX=0,upY=1,upZ=0;
static void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3d(1,0,0);
glPushMatrix();
gluLookAt(eyeX,eyeY,eyeZ,
centerX,centerY,centerZ,
upX,upY,upZ);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
(2) 矩陣 投影矩陣
(3) 攝影機運鏡
(4) 會動的機器
(5)補 MP3播放
mp3播放
todo:播mp3最簡單 CMP_MCI.h
#include "CMP3_MCI.h" //檔案放在目錄
CMP3_MCI myMP3; // 宣告變數
在int main()裡
int main(....)
myMP3.Load("音樂.mp3"); //Load檔案
myMP3.Play(); // play播放
若無法執行跑出CMP3_MCI.CPP
則點選專題 按右鍵 Build Option Linker setting add winmm(新增媒體播放)
gluLookAt()應用 //調視角
float eyeX=0,eyeY=0,eyeZ=1;float centerX=0,centerY=0,centerZ=0;
float upX=0,upY=1,upZ=0;
static void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3d(1,0,0);
glPushMatrix();
gluLookAt(eyeX,eyeY,eyeZ,
centerX,centerY,centerZ,
upX,upY,upZ);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
gluPerspective.cpp
glMatrixMode(GL_PROJECTION);//臨時切換成projection矩陣
glLoadIdentity();
gluPerspective(60,1,0.001,10000);
//60=張角,1=xy比例,0.001=z的方向,10000=zfar
glMatrixMode(GL_MODELVIEW);//切回model view矩陣
TRT手臂
2017年5月2日 星期二
week11-上課筆記
(1)組合匯出機器人
(2)可轉動的關節
(3)錄製動作
(4)回家作業:機器人
TODO : google 3d exploration
1.下在1.81免費試用版
2.jsyeh.org/3dcg10下載data(裡面有3d模型)
3.用1.去看2.的模型
4.匯出(save as)cpp(OpenGL) export Dialog裡SampleAPP(才會有MAIN()函式)
5.Codeblocks→File-New-Project→OpenGL專案
偷天換日 Remove移除main.c
Add新增soccerball.cpp
f9 Build&Run有兩行錯誤.都刪掉
7.myGLMsampl當範例用
安裝freeglut在c:\users\use\Desktop\freeglut\lib
\include
\bin
把程式改成畫兩隻海豚
2017年4月25日 星期二
week10-上課筆記
hw01
(1)Maya匯出OBJ模型
(2)glm讀模型,畫
(3)WAZ音效,MP3音樂
(4)小遊戲(回家作業)
(1)
jsyeh.org/3dcg10下載
source.zip→下載\windows\glm.c
glm.h
transformation.c
Windows.zip→下載\windows\Transformation.exe
data.zip→下載\windows\data\soccerball.obj
soccerball.mtl
glut32.dll→下載\windows\glut32.dll
(2)
用右鍵Notepad++開啟 soccerball.obj
soccerball.mtl
glm讀模型,畫
解壓縮 myGLMsample.zip
裝freeglut在桌面
開啟04160011-hw1.cbp
可在
pmodel = glmReadOBJ("data/dolphins.obj"); 改MAYA圖形檔(dolphins可改其他名稱)
(3)nehe寫出小遊戲
google搜尋nehe lesson 32 解壓zip檔
執行Lesson32.exe應用程式
(4) 做出聲音
PlaySound("檔名.wav",NULL,SND_ASYNC);
(5)用滑鼠控制聲音
#include <mmsystem.h>
void mouse (int button,int state,int x,int y)
{
PlaySound("檔名.WAV",NU;;,SND_ASYNC);
}
在main()裡面 glutCreateWindow()之後
新增 glutMouseFunc(mouse);
(6)用鍵盤發出音階
void keyboard(unsigned char key,int x,int y)
{
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);
}
在main()裡面 glutCreateWindow()之後
新增 glutKeyboardFunc(keyboard);
2017年4月11日 星期二
第八周隨堂作業
hw01
打光
先建一個GLUT,在建一個茶壺(圖案)
(1)找light留8行 ( counst GLfloat 下8行)
(2)找light留8行( 從glClearColor(1,1,1,1);到glEnable(GL_LIGHTING);)
(3)找light留8行( gllightfv();4行 與glMaterialfv();4行)
(4)留display();
(5)留main();
hw02
物體自動旋轉
float angle=0;
在display()中新增
angle++;
glRotatef(angle,x,y,z); //要放在茶壺前
在main中新增
glIdleFunc(display); //在沒事作時就呼叫display();
hw03
各種形狀圖案
glutSolidCone(x,y,slice,stack); x=底的半徑,y=高,slice=直切,stack=橫切 // 實心圓錐
glutWireCone(x,y,slice,stack); x=底的半徑,y=高,slice=直切,stack=橫切 // 空心圓錐
打光
先建一個GLUT,在建一個茶壺(圖案)
(1)找light留8行 ( counst GLfloat 下8行)
(2)找light留8行( 從glClearColor(1,1,1,1);到glEnable(GL_LIGHTING);)
(3)找light留8行( gllightfv();4行 與glMaterialfv();4行)
(4)留display();
(5)留main();
hw02
物體自動旋轉
float angle=0;
在display()中新增
angle++;
glRotatef(angle,x,y,z); //要放在茶壺前
在main中新增
glIdleFunc(display); //在沒事作時就呼叫display();
各種形狀圖案
glutSolidCone(x,y,slice,stack); x=底的半徑,y=高,slice=直切,stack=橫切 // 實心圓錐
glutWireCone(x,y,slice,stack); x=底的半徑,y=高,slice=直切,stack=橫切 // 空心圓錐
2017年3月28日 星期二
第六周隨堂
練習期中考題
glPushMatrix(); //備份矩陣
glTranslatef(x,y,z); //移動
glRotatef(angle,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(); // 還原矩陣
理解旋轉原理
glTranslatef(x,y,z); glRotatef(angle,x,y,z);
glRotatef(angle,x,y,z); glTranslatef(x,y,z);
glScalef(x,y,z); glScalef(x,y,z);
glBegin(....); glBegin(....);
begin的東西 begin的東西
先換大小 先換大小
在旋轉(自轉方式) 在移動
最後在移動 最後在旋轉(公轉方式)
畫出機械手臂(連關節動)
float mouseX;
void(display)
{
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(mouseX,0,0,1);
glColor3f(1,0,0);
glutSolidTeapot(0.3);
glPushMatrix();
glTranslatef(0.5,0.4,0);
glRotatef(mouseX,0,0,1);
glTranslatef(0.41,-0.5,0);
glColor3f(1,1,0);
glSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int x,int y);
{
mouseX=x;
glutPostRedisplay();
}
int main(int argc,char * argv[])
{
....
...
glutMotionFunc(motion);
}
glPushMatrix(); //備份矩陣
glTranslatef(x,y,z); //移動
glRotatef(angle,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(); // 還原矩陣
理解旋轉原理
glTranslatef(x,y,z); glRotatef(angle,x,y,z);
glRotatef(angle,x,y,z); glTranslatef(x,y,z);
glScalef(x,y,z); glScalef(x,y,z);
glBegin(....); glBegin(....);
begin的東西 begin的東西
先換大小 先換大小
在旋轉(自轉方式) 在移動
最後在移動 最後在旋轉(公轉方式)
畫出機械手臂(連關節動)
float mouseX;
void(display)
{
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(mouseX,0,0,1);
glColor3f(1,0,0);
glutSolidTeapot(0.3);
glPushMatrix();
glTranslatef(0.5,0.4,0);
glRotatef(mouseX,0,0,1);
glTranslatef(0.41,-0.5,0);
glColor3f(1,1,0);
glSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int x,int y);
{
mouseX=x;
glutPostRedisplay();
}
int main(int argc,char * argv[])
{
....
...
glutMotionFunc(motion);
}
2017年3月21日 星期二
第五周課堂
hw01
使用glPushMatrix();//備份
glPopMatrix();//還原
glTranslatef(x,y,z);//移動位置
HW02
使用滑鼠移動物件
設float mouseX,mouseY=0;
display改
glTranslatef(mouseX,mouseY,0);
設一個移動函式
void motion(int x,int y)
{
mouseX=(x-150)/150.0;
mouseY=-(Y-150)/150.0;
glutPostRedisplay();
}
在int main()加一個
glutMotionFunc(motion);
HW03
把glTranslatef(mouseX,mouseY,0)改成glScalef(mouseX,mouseY,0)則縮放
HW04
旋轉圖案
設一個float rotX;
寫一行glRotatef(rotX,0,0,1);(旋轉角度,X,Y,Z軸)
在motion加一個 rotX=x;
使用glPushMatrix();//備份
glPopMatrix();//還原
glTranslatef(x,y,z);//移動位置
HW02
使用滑鼠移動物件
設float mouseX,mouseY=0;
display改
glTranslatef(mouseX,mouseY,0);
設一個移動函式
void motion(int x,int y)
{
mouseX=(x-150)/150.0;
mouseY=-(Y-150)/150.0;
glutPostRedisplay();
}
在int main()加一個
glutMotionFunc(motion);
HW03
把glTranslatef(mouseX,mouseY,0)改成glScalef(mouseX,mouseY,0)則縮放
HW04
旋轉圖案
設一個float rotX;
寫一行glRotatef(rotX,0,0,1);(旋轉角度,X,Y,Z軸)
在motion加一個 rotX=x;
2017年3月14日 星期二
04160214_第四周
hw01
(1)hw2.評分3個最好作品
解開壓縮 點list.html crtl+-調大小 選最好作品
hw02
畫出正圓形
圓上頂點皆為cos(x),sin(y)
#include <math.h>
static void display(void)
{
glBegin(GL_POLYGON);
{
for(float angle=0;angle<=3.1415926*2;angle+=0.1)
{
glVertex2f(cos(angle),sin(angle));
}
glEnd();
}
glutSwapBuffers();
}
hw03
用滑鼠點選換圓形顏色
#include <stdio.h>(因為有printf)
void mouse(int buttom,int state,int x,int y)
{
printf("%d %d %d %d\n",buttom,state,x,y);
glColor3f(1,x/300.0,y/300.0);
}
int main(int argc,char *argv[])
{
.....
glutMouseFunc(mouse);
}
hw04
用滑鼠拖曳變顏色
void motion(int x,int y)
{
glColor3f(1,x/300.0,y/300.0);
glutPostRedisplay();
}
int main(int argc,char *argv[])
{
glutMotionFunc(motion);
}
hw05
畫小精靈
設一個可拉的嘴巴 float mouth=0;
清掉之前的格式
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
設一個三角形組成的扇形
glBegin(GL_TRINGLE_FAN);
頂點(0,0);
float mouth=0;
static void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(0,0);
{
for(float angle=0 +mouth;angle<=3.1415926*2-mouth;angle+=3.1415926/100)
{
glVertex2f(cos(angle),sin(angle));
}
glEnd();
}
glutSwapBuffers();
}
(1)hw2.評分3個最好作品
解開壓縮 點list.html crtl+-調大小 選最好作品
hw02
畫出正圓形
圓上頂點皆為cos(x),sin(y)
#include <math.h>
static void display(void)
{
glBegin(GL_POLYGON);
{
for(float angle=0;angle<=3.1415926*2;angle+=0.1)
{
glVertex2f(cos(angle),sin(angle));
}
glEnd();
}
glutSwapBuffers();
}
hw03
用滑鼠點選換圓形顏色
#include <stdio.h>(因為有printf)
void mouse(int buttom,int state,int x,int y)
{
printf("%d %d %d %d\n",buttom,state,x,y);
glColor3f(1,x/300.0,y/300.0);
}
int main(int argc,char *argv[])
{
.....
glutMouseFunc(mouse);
}
hw04
用滑鼠拖曳變顏色
void motion(int x,int y)
{
glColor3f(1,x/300.0,y/300.0);
glutPostRedisplay();
}
int main(int argc,char *argv[])
{
glutMotionFunc(motion);
}
hw05
畫小精靈
設一個可拉的嘴巴 float mouth=0;
清掉之前的格式
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
設一個三角形組成的扇形
glBegin(GL_TRINGLE_FAN);
頂點(0,0);
float mouth=0;
static void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(0,0);
{
for(float angle=0 +mouth;angle<=3.1415926*2-mouth;angle+=3.1415926/100)
{
glVertex2f(cos(angle),sin(angle));
}
glEnd();
}
glutSwapBuffers();
}
2017年3月7日 星期二
2017年2月21日 星期二
訂閱:
文章 (Atom)
