#include #include #include #include #include #include #include #include "utils.hpp" #include #include #include extern u32 gettick(); int run = 1; void WiiResetPressed(); void WiiPowerPressed(); int main( int argc, char **argv ) { SYS_SetResetCallback(WiiResetPressed); SYS_SetPowerCallback(WiiPowerPressed); WPAD_Init(); initGX(); Mtx view; Mtx44 perspective, orthographic; Mtx model, modelview; guVector Yaxis = {0, 1, 0}; guVector Xaxis = {1, 0, 0}; // setup our camera at the origin // looking down the -z axis with y up guVector cam = {0.0f, 0.0f, 0.0f}, up = {0.0f, 1.0f, 0.0f}, look = {0.0f, 0.0f, -1.0f}; guLookAt(view, &cam, &up, &look); guPerspective(perspective, 45, screenW/screenH, 0.1f, 300.0f); #define W screenW #define H screenH guOrtho(orthographic, 0.0f, H, 0.0f, W, 0.0f, 1.0f); float rtri = 0.0f , rquad = 0.0f; u32 frame = 0; u64 last_time = ticks_to_millisecs(gettick()); float delta_time = 0.0; float fps = 0.0f; while (run) { WPAD_ScanPads(); if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) run = 0; initDrawing(); //2D GX_LoadProjectionMtx(orthographic, GX_ORTHOGRAPHIC); guMtxIdentity(modelview); GX_LoadPosMtxImm(modelview, GX_PNMTX0); GX_Begin(GX_LINESTRIP, GX_VTXFMT0, 5); GX_Position3f32(0.0f, 0.0f, 0.0f); GX_Color3f32(1.0f,0.0f,0.0f); GX_Position3f32(W,0.0f, 0.0f); GX_Color3f32(0.0f,1.0f,0.0f); GX_Position3f32(W,H, 0.0f); GX_Color3f32(0.0f,0.0f,1.0f); GX_Position3f32(0.0f,H, 0.0f); GX_Color3f32(1.0f,0.0f,1.0f); GX_Position3f32(0.0f, 0.0f, 0.0f); GX_Color3f32(1.0f,0.0f,0.0f); GX_End(); GX_Begin(GX_LINES, GX_VTXFMT0, 4); GX_Position3f32(0.0f, 0.0f, 0.0f); GX_Color3f32(W,0.0f,0.0f); GX_Position3f32(W,H, 0.0f); GX_Color3f32(0.0f,H,0.0f); GX_Position3f32(0.0f,H, 0.0f); GX_Color3f32(0.0f,0.0f,1.0f); GX_Position3f32(W,0.0f, 0.0f); GX_Color3f32(1.0f,0.0f,1.0f); GX_End(); //3D GX_LoadProjectionMtx(perspective, GX_PERSPECTIVE); guMtxIdentity(model); guMtxRotAxisDeg(model, &Yaxis, rtri); guMtxTransApply(model, model, -1.5f,0.0f,-6.0f); guMtxConcat(view,model,modelview); // load the modelview matrix into matrix memory GX_LoadPosMtxImm(modelview, GX_PNMTX0); GX_Begin(GX_TRIANGLES, GX_VTXFMT0, 3); GX_Position3f32( 0.0f, 1.0f, 0.0f); // Top GX_Color3f32(1.0f,0.0f,0.0f); // Set The Color To Red GX_Position3f32(-1.0f,-1.0f, 0.0f); // Bottom Left GX_Color3f32(0.0f,1.0f,0.0f); // Set The Color To Green GX_Position3f32( 1.0f,-1.0f, 0.0f); // Bottom Right GX_Color3f32(0.0f,0.0f,1.0f); // Set The Color To Blue GX_End(); guMtxIdentity(model); guMtxRotAxisDeg(model, &Xaxis, rquad); guMtxTransApply(model, model, 1.5f,0.0f,-6.0f); guMtxConcat(view,model,modelview); // load the modelview matrix into matrix memory GX_LoadPosMtxImm(modelview, GX_PNMTX0); GX_Begin(GX_QUADS, GX_VTXFMT0, 4); // Draw A Quad GX_Position3f32(-1.0f, 1.0f, 0.0f); // Top Left GX_Color3f32(1.0f,0.0f,0.0f); // Set The Color To Blue GX_Position3f32( 1.0f, 1.0f, 0.0f); // Top Right GX_Color3f32(0.0f,1.0f,0.0f); // Set The Color To Blue GX_Position3f32( 1.0f,-1.0f, 0.0f); // Bottom Right GX_Color3f32(0.0f,0.0f,1.0f); // Set The Color To Blue GX_Position3f32(-1.0f,-1.0f, 0.0f); // Bottom Left GX_Color3f32(1.0f,1.0f,0.0f); // Set The Color To Blue GX_End(); // Done Drawing The Quad flipBuffers(); rtri += 2.0f; // Increase The Rotation Variable For The Triangle ( NEW ) rquad -= 1.5f; // Decrease The Rotation Variable For The Quad ( NEW ) ++frame; delta_time = (ticks_to_millisecs(gettick()) - last_time)/1000.0f; if (delta_time >= 1.0f) { fps = frame/delta_time; frame = 0; last_time = ticks_to_millisecs(gettick()); } } exitGX(); exit(0); return 0; } void WiiResetPressed() { run = 0; } void WiiPowerPressed() { run = 0; }