Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.47 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <malloc.h>
  5. #include <math.h>
  6. #include <gccore.h>
  7. #include <wiiuse/wpad.h>
  8.  
  9. #define DEFAULT_FIFO_SIZE (256 * 1024)
  10. #define POINTS_SIZE 1000
  11.  
  12. static void *frameBuffer[2] = {NULL, NULL};
  13. static bool map[POINTS_SIZE];
  14. static ir_t points[POINTS_SIZE];
  15. static int liveCounter[POINTS_SIZE];
  16.  
  17. static int lastPointIndex = 0;
  18.  
  19. // Przechowuje wysokość i szerokość tworzonego okna
  20. GXRModeObj *rmode;
  21.  
  22.  
  23. // ---------------------------------------------------
  24.  
  25. // Zmienna przechowująca dane kontrolera
  26. ir_t ir;
  27.  
  28.  
  29. void wpad_initialize(GXRModeObj *rmode)
  30. {
  31. WPAD_Init();
  32. // Rozpoczęcie skanowania położenia kontrolerów
  33. WPAD_SetVRes(WPAD_CHAN_ALL, rmode->fbWidth, rmode->xfbHeight);
  34. WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
  35. }
  36.  
  37. void drawQuad(int x, int y, int width, int height)
  38. {
  39. GX_Begin(GX_QUADS, GX_VTXFMT0, 4); // Rozpoczęcie rysowania kwadratu
  40. GX_Position3f32(x, y, 0.0f); // Pozycja lewego górnego narożnika kwadratu na scenie
  41. GX_Position3f32(x + width - 1, y, 0.0f); // Pozycja prawego górnego narożnika kwadratu na scenie
  42. GX_Position3f32(x + width - 1, y + height - 1, 0.0f); // Prawy dół
  43. GX_Position3f32(x, y + height - 1, 0.0f); // Lewy dół
  44. GX_End(); // Zakończenie rysowania kwadratu
  45. }
  46.  
  47. // ---------------------------------------------------
  48.  
  49.  
  50. int main(int argc, char **argv)
  51. {
  52. f32 yscale;
  53. u32 xfbHeight;
  54. Mtx view;
  55. Mtx44 perspective;
  56. Mtx model, modelview;
  57. u32 fb = 0; // początkowy indeks bufora ramki
  58. void *gp_fifo = NULL;
  59. // Kolor tła
  60. GXColor background = {0, 0, 0, 0xff};
  61.  
  62. // Inicjalizacja wyświetlacza
  63. VIDEO_Init();
  64.  
  65.  
  66. // stworzenie domyślnego modu wideo
  67. rmode = VIDEO_GetPreferredMode(NULL);
  68.  
  69. // stworzenie 2 buforów sceny
  70. frameBuffer[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
  71. frameBuffer[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
  72.  
  73. // ustwienie konfiguracji
  74. VIDEO_Configure(rmode);
  75.  
  76. // ustawienie wyswietlanego bufora sceny na ekranie
  77. VIDEO_SetNextFramebuffer(frameBuffer[fb]);
  78.  
  79. // Wyłączenie czarnego obrazu sceny
  80. VIDEO_SetBlack(FALSE);
  81.  
  82. // Wyswietlenie bufora sceny na ekranie
  83. VIDEO_Flush();
  84.  
  85. // Oczekiwanie na synchronizację
  86. VIDEO_WaitVSync();
  87. if (rmode->viTVMode & VI_NON_INTERLACE)
  88. {
  89. VIDEO_WaitVSync();
  90. }
  91.  
  92.  
  93. gp_fifo = memalign(32, DEFAULT_FIFO_SIZE);
  94. memset(gp_fifo, 0, DEFAULT_FIFO_SIZE);
  95. GX_Init(gp_fifo, DEFAULT_FIFO_SIZE);
  96.  
  97. // resetuje bg do koloru
  98. GX_SetCopyClear(background, 0x00ffffff);
  99.  
  100. //GX_SetViewport(0, 0, rmode->fbWidth, rmode->efbHeight, 0, 1);
  101. yscale = GX_GetYScaleFactor(rmode->efbHeight, rmode->xfbHeight);
  102. xfbHeight = GX_SetDispCopyYScale(yscale);
  103. GX_SetScissor(0, 0, rmode->fbWidth, rmode->efbHeight);
  104. GX_SetDispCopySrc(0, 0, rmode->fbWidth, rmode->efbHeight);
  105. GX_SetDispCopyDst(rmode->fbWidth, xfbHeight);
  106. GX_SetCopyFilter(rmode->aa, rmode->sample_pattern, GX_TRUE, rmode->vfilter);
  107. GX_SetFieldMode(rmode->field_rendering, ((rmode->viHeight == 2 * rmode->xfbHeight) ? GX_ENABLE : GX_DISABLE));
  108.  
  109.  
  110. GX_SetCullMode(GX_CULL_NONE);
  111. GX_CopyDisp(frameBuffer[fb], GX_TRUE);
  112. GX_SetDispCopyGamma(GX_GM_1_0);
  113.  
  114. GX_ClearVtxDesc();
  115. GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
  116.  
  117. // setup the vertex descriptor
  118. // tells the flipper to expect direct data
  119. GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
  120.  
  121. GX_SetNumChans(1);
  122. GX_SetNumTexGens(0);
  123.  
  124.  
  125. GX_SetTevOp(GX_TEVSTAGE0, GX_REPLACE);
  126. GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0);
  127.  
  128. GX_InvalidateTexAll();
  129.  
  130. guVector cam = {0.0F, 0.0F, 0.0F},
  131. up = {0.0F, 1.0F, 0.0F},
  132. look = {0.0F, 0.0F, -1.0F};
  133. guLookAt(view, &cam, &up, &look);
  134. guOrtho(perspective, 0, rmode->fbWidth -1, 0, rmode->efbHeight - 1, 0, 300);
  135. GX_LoadProjectionMtx(perspective, GX_ORTHOGRAPHIC);
  136.  
  137.  
  138.  
  139.  
  140. // ---------------------------------------------------
  141.  
  142. wpad_initialize(rmode);
  143.  
  144.  
  145.  
  146. while (1)
  147. {
  148. GX_SetViewport(0, 0, rmode->fbWidth, rmode->efbHeight, 0, 1);
  149. GX_InvVtxCache();
  150. GX_ClearVtxDesc();
  151. GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
  152. guMtxIdentity(model);
  153. guMtxTransApply(model, model, 0.0f, 0.0f, -5.0f);
  154. guMtxConcat(view, model, modelview);
  155. GX_LoadPosMtxImm(modelview, GX_PNMTX0);
  156.  
  157.  
  158. // ---------------------------------------------------
  159. // Rozpoczęcie skanowania położenia kontrolerów
  160. WPAD_ScanPads();
  161.  
  162. // IR Movement
  163. WPAD_IR(0, &ir);
  164.  
  165. if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME)
  166. {
  167. exit(0);
  168. }
  169.  
  170.  
  171.  
  172. lastPointIndex++;
  173. if (lastPointIndex >= POINTS_SIZE)
  174. {
  175. lastPointIndex = 0;
  176. }
  177. points[lastPointIndex].x = ir.x;
  178. points[lastPointIndex].y = ir.y;
  179. map[lastPointIndex] = true;
  180.  
  181. liveCounter[lastPointIndex] = 30;
  182.  
  183. for (int i = 0; i < POINTS_SIZE; i++)
  184. {
  185. if (map[i] )
  186. {
  187. drawQuad(points[i].x, points[i].y, 3, 3);
  188. liveCounter[i] -= 1;
  189.  
  190. if(liveCounter[i] <= 0){
  191. map[i] = false;
  192. }
  193. }
  194. }
  195. //drawQuad(ir.x, ir.y, 3, 3);
  196.  
  197.  
  198. // ---------------------------------------------------
  199.  
  200.  
  201. // Wyświetlanie obrazu na scenie
  202. GX_DrawDone();
  203. GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE);
  204. GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR);
  205. GX_SetAlphaUpdate(GX_TRUE);
  206. GX_SetColorUpdate(GX_TRUE);
  207. GX_CopyDisp(frameBuffer[fb], GX_TRUE);
  208. VIDEO_SetNextFramebuffer(frameBuffer[fb]);
  209. VIDEO_Flush();
  210. VIDEO_WaitVSync();
  211.  
  212. // zmiana bufora
  213. fb ^= 1;
  214. }
  215.  
  216.  
  217.  
  218. return 0;
  219. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement