1 / 20

3D Game Programming Lab2-2D game example

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 (); 方法 二 :

ziazan
Download Presentation

3D Game Programming Lab2-2D game example

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 3D Game ProgrammingLab2-2D game example

  2. Goal • Familiar with GLUT game process • Load images • I/O control • Animation

  3. Image examples

  4. Read Image • RGBApixmappic; • pic.readBMPFile(“filename.bmp");

  5. Draw image (set position) • In display() 方法一: glRasterPos2i(x, y); pic.blend(); 方法二: pic.blendTex(x, y);

  6. Draw image (scale) void blendTex(intx, inty, float scalex=1.0f, float scaley=1.0f); • pic.blendTex(picX, picY, 2.5, 1);

  7. Draw image (scale) void blendTex(intx, inty, float scalex=1.0f, float scaley=1.0f); • pic.blendTex(picX, picY, -1, 1);

  8. Draw image (scale) void blendTex(intx, inty, float scalex=1.0f, float scaley=1.0f); • pic.blendTex(picX+ pic.w(), picY, -1, 1);

  9. 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,所以為垂直螢幕向外射出:

  10. Draw image (rotate) void blendTexRotate (intx, inty, float scalex=1.0f, float scaley=1.0f, float angle=0.0f) • pic.blendTexRotate(x, y, 1, 1, 90); 以圖片中心點 做旋轉

  11. Change State

  12. Change State void SpecialKeys(intkey, 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為軸翻轉影像 } … }

  13. Time Function • void glutTimerFunc(unsigned int msecs, void (*func)(int value), int value); 時間間隔 (milliseconds) 要呼叫的函式名稱 要傳入函式的變數

  14. Time Function 使用時呼叫 jump(0) • glutTimerFunc( A, B, C ); • A = 時間間隔 (milliseconds) • B= 要呼叫的Function • C= 要傳入的變數 • GLUT每隔A毫秒 就會呼叫一次B(C)函式 • 以jump function為例: • glutTimerFunc(100,jump,i); • 表示每隔100單位時間,呼叫一次 jump (i)

  15. Practice • Back and Forth n/2 steps n steps change DirectState n/2 steps

  16. Challenge • Fly y = H * sin (x) H W

  17. Super Challenge • Fly Randomly y = 50 * sin (x) + (rand() % maxChange)

  18. 將指定的顏色變為透明色去除圖片的背景

  19. 去背製作範例 • 首先找一張將背景透明的圖片(檔案格式為 .gif 或 .png),接著用Photoshop等繪圖軟體把該圖片與我們選的特定顏色之背景做結合,以下我們用淡藍色(232, 248, 248)舉例:

  20. Q&A

More Related