// *********************************************************************************** // Programs written by R.Swan - rs108@mdx.ac.uk - www.netyaroze-europe.com/~middex2 // MAIN routine // *********************************************************************************** #include "header.h" #include // for printf(); #include // for rand() //#include "scrngrab.h" #define TIM_BALL (0x80098000) #define LINE_setVERTEX(v,_x,_y,_z) \ (v)->vec.vx = (_x), \ (v)->vec.vy = (_y), \ (v)->vec.vz = (_z) #define LINE_setENDS(l,_s,_e) \ (l)->start = (_s), \ (l)->end = (_e) Model myOBJ; GsSPRITE BALL_IN_3D; typedef struct { u_long start, end; } LINE_INFO; typedef struct { VECTOR vec; short x,y,z; } VECTOR_INFO; #define NumberOfVertices (14) #define NumberOfLines (48) VECTOR_INFO Vertices[NumberOfVertices]; LINE_INFO Lines[NumberOfLines]; GsGLINE LINE_IN_3D; // **** u_long GameRunning = true; u_long Tmd_Selected = 0; u_long JustMoved = 0; u_long OVERHEAD = false; u_long DRAWFROM = 0; void funct_makePyramid(u_long index, u_long b0, u_long b1, u_long b2, u_long b3, u_long t0); // *********************************************************************************** // MAIN FUNCTION // *********************************************************************************** void main() { SCREENR = 0; SCREENG = 0; SCREENB = 0; InitialiseScreen3D(); InitialiseJoyPad(); InitTransProj(); LINE_setVERTEX(&Vertices[0], -50, -50, -50); LINE_setVERTEX(&Vertices[1], -50, -50, 50); LINE_setVERTEX(&Vertices[2], 50, -50, 50); LINE_setVERTEX(&Vertices[3], 50, -50, -50); LINE_setVERTEX(&Vertices[4], -50, 50, -50); LINE_setVERTEX(&Vertices[5], -50, 50, 50); LINE_setVERTEX(&Vertices[6], 50, 50, 50); LINE_setVERTEX(&Vertices[7], 50, 50, -50); LINE_setVERTEX(&Vertices[8], 0, -250, 0); LINE_setVERTEX(&Vertices[9], 250, 0, 0); LINE_setVERTEX(&Vertices[10], 0, 250, 0); LINE_setVERTEX(&Vertices[11], -250, 0, 0); LINE_setVERTEX(&Vertices[12], 0, 0, -250); LINE_setVERTEX(&Vertices[13], 0, 0, 250); funct_makePyramid(0, 0, 1, 2, 3, 8); funct_makePyramid(8, 1, 2, 6, 5, 13); funct_makePyramid(16, 3, 2, 6, 7, 9); funct_makePyramid(24, 0, 3, 7, 4, 12); funct_makePyramid(32, 4, 5, 6, 7, 10); funct_makePyramid(40, 0, 1, 5, 4, 11); SetModelInfo(&myOBJ,0,0,0, (u_long *) 0x80090000); SetLightDirectional(0, 1, 1, 0, 255, 255, 255); SetLightAmbient(512,512,512); TurnFoggingOff(); SetViewPoint(500, 0, 0, 0, -1024, 0, 0, 0, &myOBJ.Object_Coord); LoadTIMData(TIM_BALL); SetSpriteInfo(&BALL_IN_3D, TIM_BALL, 0, 0); while (GameRunning == true) { ProcessJoyPad(); UpdateWorld(); RenderWorld(); } ResetGraph(3); } // *********************************************************************************** // Function Definitions // *********************************************************************************** // **** Update everything in the world before drawing void UpdateWorld() { u_long tTemp1; for (tTemp1=0; tTemp1>1)); if (tTemp3>255) tTemp3=255; if (tTemp3<16) tTemp3=16; LINE_IN_3D.b0 = LINE_IN_3D.g0 = (LINE_IN_3D.r0 = (u_char) (tTemp3))>>1; tTemp3 = (256 - ((Vertices[Lines[tTemp1].end].z-768)>>1)); if (tTemp3>255) tTemp3=255; if (tTemp3<16) tTemp3=16; LINE_IN_3D.b1 = LINE_IN_3D.g1 = (LINE_IN_3D.r1 = (u_char) (tTemp3))>>1; tTemp2 = Vertices[Lines[tTemp1].start].z + Vertices[Lines[tTemp1].end].z; GsSortGLine(&LINE_IN_3D, &OTable_Header[CurrentBuffer], tTemp2>>5); } for (tTemp1=0; tTemp1>2)); if (tTemp3>127) tTemp3=127; if (tTemp3<8) tTemp3=8; BALL_IN_3D.r = BALL_IN_3D.g = (BALL_IN_3D.b = (u_char) (tTemp3))>>1; tTemp2 = Vertices[tTemp1].z; DrawSprite(&BALL_IN_3D, tTemp2>>4); } RenderFinish(); } // **** Respond to user input from joypad 1 void ProcessJoyPad() { u_long PAD = ReadJoyPad(); long MOVEAMOUNT = 5; if ((PAD& PADselect)) GameRunning = false; if (PAD& PADright) RotateModel(&myOBJ, 0, -MOVEAMOUNT, 0); if (PAD& PADleft) RotateModel(&myOBJ, 0, MOVEAMOUNT, 0); if (PAD& PADup) RotateModel(&myOBJ, -MOVEAMOUNT, 0, 0); if (PAD& PADdown) RotateModel(&myOBJ, MOVEAMOUNT, 0, 0); if (PAD& PADL1) RotateModel(&myOBJ, 0, 0, MOVEAMOUNT); if (PAD& PADR1) RotateModel(&myOBJ, 0, 0, -MOVEAMOUNT); } // *********************************************************************************** // Function Definitions // *********************************************************************************** void InitTransProj(void) { GsInitCoordinate2(WORLD, &trans); } void TransProj(VECTOR *pos, short *x, short *y, short *z) { MATRIX mat; VECTOR v; trans.coord.t[0] = pos->vx; trans.coord.t[1] = pos->vy; trans.coord.t[2] = pos->vz; trans.flg=0; GsGetLs(&trans,&mat); ApplyMatrixLV(&mat, pos, &v); if(mat.t[2]) { *x = ProjectionDistance * v.vx / mat.t[2]; *y = ProjectionDistance * v.vy / mat.t[2]; *z = mat.t[2]; } else { *x = 0; *y = 0; *z = 0; } } void funct_makePyramid(u_long index, u_long b0, u_long b1, u_long b2, u_long b3, u_long t0) { LINE_setENDS(&Lines[index], b0, t0); LINE_setENDS(&Lines[index+1], b1, t0); LINE_setENDS(&Lines[index+2], b2, t0); LINE_setENDS(&Lines[index+3], b3, t0); LINE_setENDS(&Lines[index+4], b0, b1); LINE_setENDS(&Lines[index+5], b1, b2); LINE_setENDS(&Lines[index+6], b2, b3); LINE_setENDS(&Lines[index+7], b3, b0); }