Upload
ziazan
View
146
Download
5
Embed Size (px)
DESCRIPTION
3D Game Programming Lab2-2D game example. Goal. Familiar with GLUT game process Load images I/O control Animation. Image examples. Read Image. RGBApixmap pic; pic.readBMPFile (“filename.bmp");. Draw image (set position). In display() 方法一 : glRasterPos2i(x, y); pic.blend (); 方法 二 : - PowerPoint PPT Presentation
Citation preview
3D Game ProgrammingLab2-2D game example
Goal
• Familiar with GLUT game process• Load images• I/O control• Animation
Image examples
stand walk jump sun1 sun2
flyup flydown cat1 cat2
Read Image
• RGBApixmap pic;• pic.readBMPFile(“filename.bmp");
Draw image (set position)
• In display()方法一 :
glRasterPos2i(x, y);pic.blend();
方法二 :pic.blendTex(x, y);
Draw image (scale)void blendTex(int x, int y, float scalex=1.0f, float scaley=1.0f);
• pic.blendTex(picX, picY, 2.5, 1);
Draw image (scale)void blendTex(int x, int y, float scalex=1.0f, float scaley=1.0f);
• pic.blendTex(picX, picY, -1, 1);
Draw image (scale)void blendTex(int x, int y, float scalex=1.0f, float scaley=1.0f);
• pic.blendTex(picX + pic.w(), picY, -1, 1);
Draw image (rotate)void blendTexRotate(int x, int y, float scalex=1.0f, float scaley=1.0f, float angle=0.0f)
除了最後一個參數其他都與之前相同, angle 為旋轉角度,會以圖片為中心的 z 軸作逆時針旋轉, z 軸為 x cross y ,所以為垂直螢幕向外射出 :
Draw image (rotate)void blendTexRotate(int x, int y, float scalex=1.0f, float scaley=1.0f, float angle=0.0f)
• pic.blendTexRotate(x, y, 1, 1, 90);
以圖片中心點做旋轉
Change State
Change Statevoid SpecialKeys(int key, int x, int y){ switch(key) { case GLUT_KEY_LEFT:
picX -= 5;if (whichPic==0)
whichPic=1;else
whichPic=0;DirectState=1;break;
case GLUT_KEY_RIGHT:picX += 5;if (whichPic==0)
whichPic=1;else
whichPic=0;DirectState=0;break;
}}
void display() { … if (DirectState==0) { // 向右 pic[whichPic].blendTex(picX, picY, 1, 1); } else { // 向左 int offset = pic[whichPic].nCols; // 圖的寬度 pic[whichPic].blendTex(picX+offset, picY, -1, 1); // 調整 x 位置,並以 x=0 為軸翻轉影像 } …}
Time Function• void glutTimerFunc(unsigned int msecs, void (*func)(int value), int value);
時間間隔 (milliseconds)
要呼叫的函式名稱
要傳入函式的變數
Time FunctionglutTimerFunc( A, B, C );(1)A = 時間間隔
(milliseconds)
(2)B = 要呼叫的Function
(3)C = 要傳入的變數 GLUT 每隔 A 毫秒 就會
呼叫一次 B(C) 函式
以 jump function 為例:glutTimerFunc(100,ju
mp,i); 表示每隔 100 單位時間,
呼叫一次 jump (i)
使用時呼叫 jump(0)
Practice
• Back and Forth
n steps
n/2 steps
n/2 steps changeDirectState
Challenge
• Fly
W
H
y = H * sin (x)
atvv
vtpp
at
ttt
tttt
an cceleratio force and epFor timest
Super Challenge
• Fly Randomly
y = 50 * sin (x) + (rand() % maxChange)
將指定的顏色變為透明色去除圖片的背景
去背製作範例• 首先找一張將背景透明的圖片 ( 檔案格式為 .gif
或 .png ) ,接著用 Photoshop 等繪圖軟體把該圖片與我們選的特定顏色之背景做結合,以下我們用淡藍色 (232, 248, 248) 舉例:
Q&A