SlideServe
Menu
Préférences
© SlideServe · v2026

3D Game Programming Lab2-2D game example

ziazan avatar
20 diapositives · 534 Views · Oct 20, 2014

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

3D Game Programming Lab2-2D game example - slide 1
01 / 203D Game Programming Lab2-2D game example
1 / 17

Télécharger la présentation

3D Game Programming Lab2-2D game example
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  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