Advertisement
xerpi

Wii widescreen borders

Apr 15th, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.80 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. #include "utils.hpp"
  9. #include <sys/time.h>
  10. #include <ogc/lwp_watchdog.h>
  11. #include <fat.h>
  12. extern u32 gettick();
  13.  
  14.  
  15. int run = 1;
  16. void WiiResetPressed();
  17. void WiiPowerPressed();
  18.  
  19. int main( int argc, char **argv )
  20. {
  21.     SYS_SetResetCallback(WiiResetPressed);
  22.     SYS_SetPowerCallback(WiiPowerPressed);
  23.     WPAD_Init();
  24.     initGX();
  25.  
  26.     Mtx view;
  27.     Mtx44 perspective, orthographic;
  28.     Mtx model, modelview;
  29.  
  30.     guVector Yaxis = {0, 1, 0};
  31.     guVector Xaxis = {1, 0, 0};
  32.    
  33.     // setup our camera at the origin
  34.     // looking down the -z axis with y up
  35.     guVector cam  = {0.0f, 0.0f,  0.0f},
  36.              up   = {0.0f, 1.0f,  0.0f},
  37.              look = {0.0f, 0.0f, -1.0f};
  38.     guLookAt(view, &cam, &up, &look);
  39.  
  40.  
  41.     guPerspective(perspective, 45, screenW/screenH, 0.1f, 300.0f);
  42.     #define W screenW
  43.     #define H screenH
  44.     guOrtho(orthographic, 0.0f, H, 0.0f, W, 0.0f, 1.0f);
  45.    
  46.     float rtri = 0.0f , rquad = 0.0f;
  47.     u32 frame = 0;
  48.     u64 last_time = ticks_to_millisecs(gettick());
  49.     float delta_time = 0.0;
  50.     float fps = 0.0f;
  51.    
  52.     while (run) {
  53.  
  54.         WPAD_ScanPads();
  55.         if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) run = 0;
  56.         initDrawing();
  57.        
  58.         //2D
  59.         GX_LoadProjectionMtx(orthographic, GX_ORTHOGRAPHIC);
  60.         guMtxIdentity(modelview);
  61.         GX_LoadPosMtxImm(modelview, GX_PNMTX0);
  62.  
  63.         GX_Begin(GX_LINESTRIP, GX_VTXFMT0, 5);
  64.             GX_Position3f32(0.0f, 0.0f, 0.0f);
  65.                 GX_Color3f32(1.0f,0.0f,0.0f);
  66.             GX_Position3f32(W,0.0f, 0.0f);
  67.                 GX_Color3f32(0.0f,1.0f,0.0f);
  68.             GX_Position3f32(W,H, 0.0f);
  69.                 GX_Color3f32(0.0f,0.0f,1.0f);
  70.             GX_Position3f32(0.0f,H, 0.0f);
  71.                 GX_Color3f32(1.0f,0.0f,1.0f);
  72.             GX_Position3f32(0.0f, 0.0f, 0.0f);
  73.                 GX_Color3f32(1.0f,0.0f,0.0f);
  74.         GX_End();
  75.         GX_Begin(GX_LINES, GX_VTXFMT0, 4);
  76.             GX_Position3f32(0.0f, 0.0f, 0.0f);
  77.                 GX_Color3f32(W,0.0f,0.0f);
  78.             GX_Position3f32(W,H, 0.0f);
  79.                 GX_Color3f32(0.0f,H,0.0f);
  80.                
  81.             GX_Position3f32(0.0f,H, 0.0f);
  82.                 GX_Color3f32(0.0f,0.0f,1.0f);
  83.             GX_Position3f32(W,0.0f, 0.0f);
  84.                 GX_Color3f32(1.0f,0.0f,1.0f);
  85.         GX_End();
  86.        
  87.         //3D
  88.         GX_LoadProjectionMtx(perspective, GX_PERSPECTIVE);
  89.  
  90.         guMtxIdentity(model);
  91.         guMtxRotAxisDeg(model, &Yaxis, rtri);
  92.         guMtxTransApply(model, model, -1.5f,0.0f,-6.0f);
  93.         guMtxConcat(view,model,modelview);
  94.         // load the modelview matrix into matrix memory
  95.         GX_LoadPosMtxImm(modelview, GX_PNMTX0);
  96.  
  97.         GX_Begin(GX_TRIANGLES, GX_VTXFMT0, 3);
  98.             GX_Position3f32( 0.0f, 1.0f, 0.0f);     // Top
  99.             GX_Color3f32(1.0f,0.0f,0.0f);           // Set The Color To Red
  100.             GX_Position3f32(-1.0f,-1.0f, 0.0f); // Bottom Left
  101.             GX_Color3f32(0.0f,1.0f,0.0f);           // Set The Color To Green
  102.             GX_Position3f32( 1.0f,-1.0f, 0.0f); // Bottom Right
  103.             GX_Color3f32(0.0f,0.0f,1.0f);           // Set The Color To Blue
  104.         GX_End();
  105.  
  106.         guMtxIdentity(model);
  107.         guMtxRotAxisDeg(model, &Xaxis, rquad);
  108.         guMtxTransApply(model, model, 1.5f,0.0f,-6.0f);
  109.         guMtxConcat(view,model,modelview);
  110.         // load the modelview matrix into matrix memory
  111.         GX_LoadPosMtxImm(modelview, GX_PNMTX0);
  112.  
  113.         GX_Begin(GX_QUADS, GX_VTXFMT0, 4);          // Draw A Quad
  114.             GX_Position3f32(-1.0f, 1.0f, 0.0f); // Top Left
  115.             GX_Color3f32(1.0f,0.0f,0.0f);           // Set The Color To Blue
  116.             GX_Position3f32( 1.0f, 1.0f, 0.0f);     // Top Right
  117.             GX_Color3f32(0.0f,1.0f,0.0f);           // Set The Color To Blue
  118.             GX_Position3f32( 1.0f,-1.0f, 0.0f); // Bottom Right
  119.             GX_Color3f32(0.0f,0.0f,1.0f);           // Set The Color To Blue
  120.             GX_Position3f32(-1.0f,-1.0f, 0.0f); // Bottom Left
  121.             GX_Color3f32(1.0f,1.0f,0.0f);           // Set The Color To Blue
  122.         GX_End();                                   // Done Drawing The Quad
  123.        
  124.         flipBuffers();
  125.  
  126.         rtri  += 2.0f;              // Increase The Rotation Variable For The Triangle ( NEW )
  127.         rquad -= 1.5f;          // Decrease The Rotation Variable For The Quad     ( NEW )
  128.        
  129.         ++frame;
  130.         delta_time = (ticks_to_millisecs(gettick()) - last_time)/1000.0f;
  131.         if (delta_time >= 1.0f) {
  132.             fps = frame/delta_time;
  133.             frame = 0;
  134.             last_time = ticks_to_millisecs(gettick());
  135.         }
  136.     }
  137.     exitGX();
  138.     exit(0);
  139.     return 0;
  140. }
  141.  
  142.  
  143. void WiiResetPressed()
  144. {
  145.     run = 0;
  146. }
  147.  
  148. void WiiPowerPressed()
  149. {
  150.     run = 0;
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement