Path: chuka.playstation.co.uk!news From: "Matthew Hardingham" Newsgroups: scee.yaroze.programming.3d_graphics Subject: Problem somewhere ? Date: Thu, 2 Mar 2000 11:33:14 -0000 Organization: PlayStation Net Yaroze (SCEE) Lines: 443 Message-ID: <89ljon$6j4@chuka.playstation.co.uk> NNTP-Posting-Host: modem-66.euthyrox.dialup.pol.co.uk X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2014.211 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211 Hola, Here we go folks, here's something for you all to have a glance at and pick at. It's the "psx" part of my LOD program, I've taken out the main LOD stuff becasue that all seems to be working, well a appropriate polygon list is being generated anyway !. Somewhere below is a possible error/s can you find it/them ? The problem is that nothing is being displayed. It's being moved about because I've played about with the FntPrint statements. If you need any more info mail me at - MatthewHardingham@RebelwareInteractive.freeserve.co.uk Cheers thanks and b-y-e Matt /*************************************************************************** / /* Main Program */ /*************************************************************************** / int main() { SetupSystem(); /* Get active buffer */ Buffer = GsGetActiveBuff(); printf("\n Go "); while(! Quit) { HandleController(); FntPrint("Trans x:(%d) Rot x:(%d) \n", Terrain.Coord.coord.t[0], Rotate.vx); FntPrint("Trans y:(%d) Rot y:(%d) \n", Terrain.Coord.coord.t[1], Rotate.vy); FntPrint("Trans z:(%d) Rot z:(%d) ", Terrain.Coord.coord.t[2], Rotate.vz); /* Set the psx work area */ GsSetWorkBase((PACKET *) PacketArea[Buffer]); /* Clear the order table */ GsClearOt(0, 0, &Ot[Buffer]); /* Set the current view */ GsSetRefView2(&ViewSys.Camera); UpDateCoordinates(&Terrain.Coord, &Translate, &Rotate); /* Calculate ls/lw matrices */ GsGetLws(&Terrain.Coord, &ViewSys.WorldCoordSys, &ViewSys.ScreenCoordSys); /* Set light matrix */ GsSetLightMatrix(&ViewSys.WorldCoordSys); /* Set GTE perspective etc */ GsSetLsMatrix(&ViewSys.ScreenCoordSys); /* Sort the object onto the table */ GsSortObject4(&Terrain.Obj, &Ot[Buffer], 14-OT_LENGTH, getScratchAddr(0)); /* Wait for current drawing to finish */ DrawSync(0); /* Wait for v-sync */ VSync(0); /* Swap the buffers */ GsSwapDispBuff(); /* Clear */ GsSortClear(0, 0, 0, &Ot[Buffer]); /* Draw */ GsDrawOt(&Ot[Buffer]); FntFlush(-1); Buffer ^= 1; } ResetGraph(1); return(0); } void HandleController(void) { Pad = PadRead(); if(Pad & PADstart) { Quit = TRUE; } /* Rot x */ if(Pad & PADLright) { Rotate.vx += 10; } if(Pad & PADLleft) { Rotate.vx -= 10; } /* Rot y */ if(Pad & PADLup) { Rotate.vy += 10; } if(Pad & PADLdown) { Rotate.vy -= 10; } /* Rot z */ if(Pad & PADL1) { Rotate.vz += 10; } if(Pad & PADL2) { Rotate.vz -= 10; } /* Trans x */ if(Pad & PADRright) { Translate.vx += 10; } if(Pad & PADRleft) { Translate.vx -= 10; } /* Trans y */ if(Pad & PADRup) { Translate.vy += 10; } if(Pad & PADRdown) { Translate.vy -= 10; } /* Trans z */ if(Pad & PADR1) { Translate.vz += 10; } if(Pad & PADR2) { Translate.vz -= 10; } } /* Setup The System */ void SetupSystem(void) { /* Memory */ /* Heap starts after the main program on a 16-byte boundary */ unsigned long lclHeapStart = (_end & 0xFFFFFFF0L) + 0x10; /* Heap extends to the bottom of the stack */ unsigned long lclHeapSize = ((_stack_addr - (_stack_size<<10)) & 0xFFFFFFF0L) - lclHeapStart; unsigned short i=0; /* Reset the system */ ResetGraph(0); /* Setup Video */ GsInitGraph(SCREEN_WIDTH, SCREEN_HEIGHT, MODE, 1, 0); GsDefDispBuff(0, 0, 0, SCREEN_HEIGHT); GsInit3D(); SetVideoMode(VIDEO_MODE); /* Setup Order Tables */ for(i=0; i<2; i++) { Ot[i].length = OT_LENGTH; Ot[i].org = OtTag[i]; Ot[i].offset = 0; Ot[i].point = 0; Ot[i].tag = OtTag[i]; GsClearOt(0, 0, &Ot[i]); } FntLoad(960,256); FntOpen(15-(SCREEN_WIDTH/2),5-(SCREEN_HEIGHT/2), SCREEN_WIDTH, SCREEN_HEIGHT, 0, 512); /* Init memory etc */ InitHeap((unsigned long *)lclHeapStart, lclHeapSize); printf("\n Heap OK "); /* Setup Controller */ GetPadBuf(&bb0, &bb1); printf("\n IO OK "); /* Setup terrain/environment */ SetupTerrain(); printf("\n Setup terrain OK "); BuildTerrain(); printf("\n Build terrain OK "); SetupModel((unsigned long *)TERRAIN_MODEL_ADDRESS, &Terrain); /* Setup the scene lighting */ SetupLighting(); printf("\n Lights OK "); /* Set the camera data */ ViewSys.Position.vx = 0; ViewSys.Position.vy = 0; ViewSys.Position.vz = -2500; ViewSys.Interest.vx = 0; ViewSys.Interest.vy = 0; ViewSys.Interest.vz = 0; ViewSys.ProjectDist = 512; ViewSys.Twist = 0; SetupViewPoint(&ViewSys); printf("\n Camera OK "); } /* Setup The Model Address */ void SetupModel(unsigned long *ModelAddr, OBJECT *Object) { ModelAddr++; GsMapModelingData(ModelAddr); ModelAddr++; ModelAddr++; GsLinkObject4((unsigned long) ModelAddr, &Object->Obj, 0); GsInitCoordinate2(WORLD, &Terrain.Coord); Terrain.Obj.attribute = 0; Terrain.Coord.coord.t[0] = 0; Terrain.Coord.coord.t[1] = 0; Terrain.Coord.coord.t[2] = 0; Terrain.Obj.coord2 = &Object->Coord; Terrain.Coord.flg = 0; } /* Setup The Lighting */ void SetupLighting(void) { /* Setup Lighting */ Light[0].vx = ONE; Light[0].vy = 0; Light[0].vz = 0; Light[0].r = 128; Light[0].g = 0; Light[0].b = 0; GsSetFlatLight(0, &Light[0]); Light[1].vx = 0; Light[1].vy = ONE; Light[1].vz = 0; Light[1].r = 0; Light[1].g = 128; Light[1].b = 0; GsSetFlatLight(1, &Light[1]); Light[2].vx = 0; Light[2].vy = 0; Light[2].vz = ONE; Light[2].r = 0; Light[2].g = 0; Light[2].b = 128; GsSetFlatLight(2, &Light[2]); GsSetLightMode(0); } /* Setup The View Point */ void SetupViewPoint(VIEW_SYSTEM *View) { GsSetProjection(View->ProjectDist); View->Camera.vpx = View->Position.vx; View->Camera.vpy = View->Position.vy; View->Camera.vpz = View->Position.vz; View->Camera.vrx = View->Interest.vx; View->Camera.vry = View->Interest.vx; View->Camera.vrz = View->Interest.vx; View->Camera.rz = View->Twist; View->Camera.super = WORLD; GsSetRefView2(&View->Camera); } void UpDateCoordinates(GsCOORDINATE2 *TmpCoord, VECTOR *Translate, SVECTOR *Rotate) { MATRIX Tmp; RotMatrix(Rotate, &Tmp); MatrixIdentity(TmpCoord->coord.m); TmpCoord->coord = Tmp; TmpCoord->coord.t[0] = Translate->vx; TmpCoord->coord.t[1] = Translate->vy; TmpCoord->coord.t[2] = Translate->vz; TmpCoord->flg = 0; } /* Read The Controller */ unsigned long PadRead(void) { return(~(*(bb0+3) | *(bb0+2) << 8 | *(bb1+3) << 16 | *(bb1+2) << 24)); } void MatrixIdentity(short Mat[3][3]) { Mat[0][0] = ONE; Mat[0][1] = 0; Mat[0][2] = 0; Mat[1][0] = 0; Mat[1][1] = ONE; Mat[1][2] = 0; Mat[2][0] = 0; Mat[2][1] = 0; Mat[2][2] = ONE; } /******************************* LOD STUFF BELOW **************************/ /*************************************************************************** * Function Name - BuildTerrainModel. * Parameters Passed - Memory address of the TMD model. * Parameters Returned - N/A. * Comments - Generate a TMD model. * ***************************************************************************/ void BuildTerrainModel(unsigned long *ModelAddr) { /* Indexes */ /* Normal */ unsigned int NormIdx0 = 0; /* Vertices */ unsigned int VertIdx0 = 0; unsigned int VertIdx1 = 1; unsigned int VertIdx2 = 2; /* Counters */ unsigned int VertCount = 0; unsigned int NormCount = 0; unsigned int PrimCount = 0; /* Pointer to the object table */ TMD_OBJ *ObjTable = NULL; /* Pointer to the vertex, normal and primative table */ unsigned long *VertTable = NULL; unsigned long *NormTable = NULL; unsigned long *PrimTable = NULL; /* Setup the TMD header */ setTMD_HDR((TMD_HDR *)ModelAddr, 0x00000041, 1,1 ); ModelAddr = (unsigned long *)((TMD_HDR *)ModelAddr + 1); /* skip object table, values setup later */ ObjTable = (TMD_OBJ *)ModelAddr; ModelAddr = (unsigned long *)((TMD_OBJ *)ModelAddr + 1); /* Primative table */ PrimTable = ModelAddr; /* Setup the primitive data */ CurrentPoly = StartPoly; do { CurrentPoly = CurrentPoly->Next; setPRIM_HDR((PRIM_HDR *)ModelAddr, F_3, 0, 3, 4); ModelAddr = (unsigned long *)((PRIM_HDR *)ModelAddr + 1); setTMD_F_3((TMD_F_3 *)ModelAddr, CurrentPoly->Colour.r, CurrentPoly->Colour.g, CurrentPoly->Colour.b, NormIdx0, VertIdx0, VertIdx1, VertIdx2); ModelAddr = (unsigned long *)((TMD_F_3 *)ModelAddr + 1); PrimCount++; NormIdx0++; VertIdx0 += 3; VertIdx1 += 3; VertIdx2 += 3; }while(CurrentPoly->Next != NULL); /* Vertices table */ VertTable = ModelAddr; /* Set polygon data */ CurrentPoly = StartPoly; do { CurrentPoly = CurrentPoly->Next; /* Set V0 */ setTMD_VERT((TMD_VERT *)ModelAddr, CurrentPoly->V0->vx, CurrentPoly->V0->vy, CurrentPoly->V0->vz); ModelAddr = (unsigned long *)((TMD_VERT *)ModelAddr + 1); VertCount++; /* Set V1 */ setTMD_VERT((TMD_VERT *)ModelAddr, CurrentPoly->V1->vx, CurrentPoly->V1->vy, CurrentPoly->V1->vz); ModelAddr = (unsigned long *)((TMD_VERT *)ModelAddr + 1); VertCount++; /* Set V2 */ setTMD_VERT((TMD_VERT *)ModelAddr, CurrentPoly->V2->vx, CurrentPoly->V2->vy, CurrentPoly->V2->vz); ModelAddr = (unsigned long *)((TMD_VERT *)ModelAddr + 1); VertCount++; }while(CurrentPoly->Next != NULL); /* Set the normal */ NormTable = ModelAddr; /* Set the normal data */ CurrentPoly = StartPoly; do { CurrentPoly = CurrentPoly->Next; setTMD_NORM((TMD_NORM *)ModelAddr, CurrentPoly->Norm.vx, CurrentPoly->Norm.vy, CurrentPoly->Norm.vz); ModelAddr = (unsigned long *)((TMD_NORM *)ModelAddr + 1); NormCount++; }while(CurrentPoly->Next != NULL); setTMD_OBJ(ObjTable, VertTable, VertCount, NormTable, NormCount, PrimTable, PrimCount, 0); printf("VertCount - %d NormCount - %d PrimCount - %d", VertCount, NormCount, PrimCount); }