/* ========================================= Anolog TMD By Eddie Harrison a big thanks to anyones source who helped me do this (mainly peter passmore) ========================================= ============== INCLUDES ============== */ #include "libps.h" #include "pad.h" /* ============= DEFINES ============= */ #define CUBE_ADDR 0x80090000 #define OT_LENGTH 10 #define SCREENW 640 // Screen height #define SCREENH 511 // Screen width /* ============= GLOBALS ============= */ GsOT OT_header[2]; // two Ordering Table headers GsOT_TAG OT_array[2][1< 80) tRotation.vz = 1; if (left_y > 10) tRotation.vz = 2; else tRotation.vz = 5; } if (left_y > 143) { if (left_y < 190) tRotation.vz = -1; if (left_y < 245) tRotation.vz = -2; else tRotation.vz = -5; } if (left_x < 113) { if (left_x > 80) tRotation.vy = -5; if (left_x > 10) tRotation.vy = -11; else tRotation.vy = -15; } if (left_x > 143) { if (left_x < 190) tRotation.vy = 5; if (left_x < 245) tRotation.vy = 11; else tRotation.vy = 15; } if (right_y < 113) { if (right_y > 80) tRotation.vx = -5; if (right_y > 10) tRotation.vx = -11; else tRotation.vx = -15; } if (right_y > 143) { if (right_y < 190) tRotation.vx = 5; if (right_y < 245) tRotation.vx = 11; else tRotation.vx = 15; } if (right_x < 113) { if (right_x > 80) tRotation.vy = -5; if (right_x > 10) tRotation.vy = -11; else tRotation.vy = -15; } if (right_x > 143) { if (right_x < 190) tRotation.vy = 5; if (right_x < 245) tRotation.vy = 11; else tRotation.vy = 15; } RotMatrix(&tRotation, &tMatrix); MulMatrix0(&tObject->coord.coord, &tMatrix, &tObject->coord.coord); tObject->coord.flg = 0; // signify object has changed } /* ============== DRAW TMD ============== */ void draw_TMD (CRAFT *tObject, GsOT *tOTable) { MATRIX LocalWorld, LocalScreen; // create two MATRIX structures GsGetLws(tObject->handler.coord2, &LocalWorld, &LocalScreen); // get the local world and screen matrices. Needed for lightsourcing GsSetLightMatrix(&LocalWorld); // Set local world matrix for lighting GsSetLsMatrix(&LocalScreen); // Set local screen matrix for perspective GsSortObject4( &tObject->handler, tOTable, 4, (u_long*)getScratchAddr(0)); // Put object in OTable ready for drawing }; /* ==================== d r a w w o r l d ==================== */ void draw_world () { DrawSync(0); hsyncs = VSync(0); GsSwapDispBuff(); // swap the display buffers GsSortClear(0,0,0,&OT_header[activebuff]); GsDrawOt(&OT_header[activebuff]); // draw to the ordering table FntFlush(-1); padstatus = padread(); // get status from control pad activebuff = GsGetActiveBuff(); // find out which buffer to draw on GsSetWorkBase((PACKET *)Packet[activebuff]); // set the packet work base GsClearOt(0, 0, &OT_header[activebuff]); // clear the ordering table } /* ===================== I N I T I A L I S E G R A P H I C S ===================== */ void init_graphics() { int i; SetVideoMode(MODE_PAL); // set graphics mode to PAL 320x256 GsInitGraph(SCREENW, SCREENH, 4, 0, 0); // set resolution and mode GsDefDispBuff(0, 0, 0, 0); // set position of the 2 display buffers GsInit3D(); // initialise 3D graphics system whithin the libary for (i=0; i<2; i++) // initialise and clear the ordering tables { OT_header[i].length = OT_LENGTH; OT_header[i].org = OT_array[i]; GsClearOt(0, 0, &OT_header[i]); } FntLoad(960, 256); // loads the debug font into frame buffer FntOpen(8, 10, SCREENH, SCREENW, 0, 512); // font printing location padinit (); // set up control pads init_TMD (&craft, 0, 100, 100, (long *)CUBE_ADDR); init_view (); init_light(&lightsource[0], 0, -1, -1, -1, 255, 255, 255); init_light(&lightsource[1], 1, 1, 1, 1, 255, 255, 255); init_light(&lightsource[2], 2, -1, -2, 1, 255, 255, 200); GsSetAmbient(0,0,0); // set ambient light in the scene GsSetLightMode(0); // set scene to lighting without fog activebuff = GsGetActiveBuff(); // find out which buffer to draw on GsSetWorkBase((PACKET *)Packet[activebuff]); // set the packet work base GsClearOt(0, 0, &OT_header[activebuff]); // clear the ordering table } /* ==================== i n i t v i e w ==================== */ void init_view (void) { GsSetProjection(1000); view.vpx = 0; view.vpy = 0; view.vpz = -2000; view.vrx = 0; view.vry = 0; view.vrz = 0; view.rz=0; view.super = WORLD; GsSetRefView2(&view); } /* ===================== i n i t l i g h t s ===================== */ void init_light (GsF_LIGHT *Light, int L_ID, int LvX, int LvY, int LvZ, int LR, int LG, int LB) { Light->vx = LvX; Light->vy = LvY; Light->vz = LvZ; // define vector for light from source Light->r = LR; Light->g = LG; Light->b = LB; // define RGB values for the light GsSetFlatLight(L_ID, Light); // initialise lights and asign a ID number }; /* =================== INTIALISE TMD =================== */ void init_TMD (CRAFT *tObject, int tX, int tY, int tZ, u_long *tMemAddress) { tMemAddress++; // move pointer past model Id GsMapModelingData(tMemAddress); GsInitCoordinate2(WORLD, &tObject->coord); tMemAddress += 2; GsLinkObject4((u_long)tMemAddress, &tObject->handler, 0); tObject->handler.coord2 = &tObject->coord; tObject->coord.coord.t[0] = tX; tObject->coord.coord.t[1] = tY; tObject->coord.coord.t[2] = tZ; tObject->coord.flg = 0; } /* ==================== P A D I N I T ==================== */ void padinit () { GetPadBuf(&bb0, &bb1); } /* ==================== P A D R E A D ==================== */ u_long padread () { right_x = *(bb0+4); right_y = *(bb0+5); left_x = *(bb0+6); left_y = *(bb0+7); return(~(*(bb0+3) | *(bb0+2) << 8 | *(bb1+3) << 16 | *(bb1+2) << 24)); }