/********************** height.c **********************/ #include "addrs.h" #include "height.h" #include #include #include "arctan.h" #include "tmd.h" #define setVector(v,x,y,z) (v)->vx = (x), (v)->vy = (y), (v)->vz = (z) #define setNormal(n,x,y,z) (n)->nx = (x), (n)->ny = (y), (n)->nz = (z) #define setColor(c,_r,_g,_b) (c)->r = (_r), (c)->g = (_g), (c)->b = (_b) #define copyVector(v0,v1) (v1)->vx = (v0)->vx, (v1)->vy = (v0)->vy, (v1)->vz = (v0)->vz #define addVector(v0,v1) (v0)->vx += (v1)->vx, (v0)->vy += (v1)->vy, (v0)->vz += (v1)->vz #define subVector(v0,v1) (v0)->vx -= (v1)->vx, (v0)->vy -= (v1)->vy, (v0)->vz -= (v1)->vz #define applyVector(v,x,y,z,op) (v)->vx op x, (v)->vy op y, (v)->vz op z #define dotProduct(v1,v2) ((v1)->vx * (v2)->vx / 4096 + (v1)->vy * (v2)->vy / 4096 + (v1)->vz * (v2)->vz / 4096) // Returns the Vector Normal of two vectors. // Speed not important as this function is used only at the // begining of the program. VECTOR VectorNormal(long x1,long y1,long z1,long x2,long y2,long z2,long x3 ,long y3,long z3) { VECTOR returnValue; long length; //Vector Coefficients returnValue.vx = (y1*(z2-z3)) + (y2*(z3-z1)) + (y3*(z1-z2)); returnValue.vy = (z1*(x2-x3)) + (z2*(x3-x1)) + (z3*(x1-x2)); returnValue.vz = (x1*(y2-y2)) + (x2*(y3-y1)) + (x3*(y1-y2)); //Normalization ///Oops stuck cant use float numbers length = (sqrt(((returnValue.vx*returnValue.vx)+ (returnValue.vy*returnValue.vy))+ (returnValue.vz*returnValue.vz))); printf("length = %d *-* ",length); if(length !=0) { returnValue.vx = (returnValue.vx / length); returnValue.vy = (returnValue.vy / length); returnValue.vz = (returnValue.vz / length); } printf("Coefficents = A= %d B= %d C= %d\n",returnValue.vx,returnValue.vy,returnValue.vz); return(returnValue); } void InitialiseMapModel(MapObject *theModel, int nX, int nY, int nZ, unsigned long *lModelAddress) { //increment the pointer to past the model id. lModelAddress++; // map tmd data to its actual address GsMapModelingData(lModelAddress); // initialise the players coordinate system - set to be that of the //world GsInitCoordinate2(WORLD, &theModel->Object_Coord); // increment pointer twice more - to point to top of model data lModelAddress++; lModelAddress++; // link the model (tmd) with the players object handler GsLinkObject4((u_long)lModelAddress, &theModel->Object_Handler,0); // Assign the coordinates of the object model to the Object Handler theModel->Object_Handler.coord2 = &theModel->Object_Coord; // Set Model sub-division. //theModel->Object_Handler.attribute |= GsDIV1; // Set the initial position of the object theModel->Object_Coord.coord.t[0]=nX; // X theModel->Object_Coord.coord.t[1]=nY; // Y theModel->Object_Coord.coord.t[2]=nZ; // Z // setting the players Object_Coord.flg to 0 indicates it is to be // drawn theModel->Object_Coord.flg = 0; } // create a dynamic TMD for a tile/cell. u_long * CreateTileTMD(u_long * myTMD,long texture1,long texture2,long texture3,long texture4, long h1, long h2, long h3, long h4,long h5,long h6, long h7, long h8,long h9) { u_long * returnValue; TMD_start(myTMD); TMD_addPolyGT3(); TMD_addPolyGT3(); TMD_addPolyGT3(); TMD_addPolyGT3(); TMD_addPolyGT3(); TMD_addPolyGT3(); TMD_addPolyGT3(); TMD_addPolyGT3(); TMD_end(); switch(texture1) { case 0: TMD_setUV3(myTMD,0,0,0,64,0,0,64); TMD_setClut(myTMD,0,GetClut(320,456)); TMD_setTPage(myTMD,0,GetTPage(1,1,896,0)); break; case 1: TMD_setUV3(myTMD,0,0,64,64,64,0,128); TMD_setClut(myTMD,0,GetClut(320,264)); TMD_setTPage(myTMD,0,GetTPage(0,0,896,0)); break; case 2: TMD_setUV3(myTMD,0,64,192,0,128,0,192); TMD_setClut(myTMD,0,GetClut(320,272)); TMD_setTPage(myTMD,0,GetTPage(0,0,896,0)); break; case 3: TMD_setUV3(myTMD,0,64,0,0,64,0,0); TMD_setClut(myTMD,0,GetClut(320,274)); TMD_setTPage(myTMD,0,GetTPage(0,0,896,256)); break; case 4: TMD_setUV3(myTMD,0,0,128,64,64,0,64); TMD_setClut(myTMD,0,GetClut(320,276)); TMD_setTPage(myTMD,0,GetTPage(0,0,896,256)); break; case 5: TMD_setUV3(myTMD,0,0,192,64,128,0,128); TMD_setClut(myTMD,0,GetClut(320,278)); TMD_setTPage(myTMD,0,GetTPage(0,0,896,256)); break; case 6: TMD_setUV3(myTMD,0,64,0,0,64,0,0); TMD_setClut(myTMD,0,GetClut(320,280)); TMD_setTPage(myTMD,0,GetTPage(0,0,832,256)); break; case 7: TMD_setUV3(myTMD,0,64,128,0,64,0,128); TMD_setClut(myTMD,0,GetClut(320,282)); TMD_setTPage(myTMD,0,GetTPage(0,0,832,256)); break; case 8: TMD_setUV3(myTMD,0,0,192,64,128,0,128); TMD_setClut(myTMD,0,GetClut(320,284)); TMD_setTPage(myTMD,0,GetTPage(0,0,832,256)); break; case 9: TMD_setUV3(myTMD,0,0,64,64,0,0,0); TMD_setClut(myTMD,0,GetClut(320,286)); TMD_setTPage(myTMD,0,GetTPage(0,0,768,256)); break; } TMD_setVert0(myTMD,0,0,h5,0); TMD_setVert1(myTMD,0, 0, h2, -TILE_WIDTH<<1); TMD_setVert2(myTMD,0, -TILE_LENGTH<<1, h1, -TILE_WIDTH<<1); TMD_setNorm0(myTMD,0,4096,4096,4096); TMD_setNorm1(myTMD,0,4096,4096,4096); TMD_setNorm2(myTMD,0,4096,4096,4096); switch(texture1) { case 0: TMD_setUV3(myTMD,1,64,0,0,64,64,64); TMD_setClut(myTMD,1,GetClut(320,456)); TMD_setTPage(myTMD,1,GetTPage(1,1,896,0)); break; case 1: TMD_setUV3(myTMD,1,64,64,0,128,64,128); TMD_setClut(myTMD,1,GetClut(320,264)); TMD_setTPage(myTMD,1,GetTPage(0,0,896,0)); break; case 2: TMD_setUV3(myTMD,1,64,128,0,192,64,192); TMD_setClut(myTMD,1,GetClut(320,272)); TMD_setTPage(myTMD,1,GetTPage(0,0,896,0)); break; case 3: TMD_setUV3(myTMD,1,64,0,0,64,64,64); TMD_setClut(myTMD,1,GetClut(320,274)); TMD_setTPage(myTMD,1,GetTPage(0,0,896,256)); break; case 4: TMD_setUV3(myTMD,1,0,128,64,64,64,128); TMD_setClut(myTMD,1,GetClut(320,276)); TMD_setTPage(myTMD,1,GetTPage(0,0,896,256)); break; case 5: TMD_setUV3(myTMD,1,0,192,64,128,64,192); TMD_setClut(myTMD,1,GetClut(320,278)); TMD_setTPage(myTMD,1,GetTPage(0,0,896,256)); break; case 6: TMD_setUV3(myTMD,1,64,0,0,64,64,64); TMD_setClut(myTMD,1,GetClut(320,280)); TMD_setTPage(myTMD,1,GetTPage(0,0,832,256)); break; case 7: TMD_setUV3(myTMD,1,64,64,0,64,0,128); TMD_setClut(myTMD,1,GetClut(320,282)); TMD_setTPage(myTMD,1,GetTPage(0,0,832,256)); break; case 8: TMD_setUV3(myTMD,1,0,192,64,192,0,128); TMD_setClut(myTMD,1,GetClut(320,284)); TMD_setTPage(myTMD,1,GetTPage(0,0,832,256)); break; case 9: TMD_setUV3(myTMD,1,0,64,64,0,64,64); TMD_setClut(myTMD,1,GetClut(320,286)); TMD_setTPage(myTMD,1,GetTPage(0,0,768,256)); break; } TMD_setVert0(myTMD,1, 0, h5,0); TMD_setVert1(myTMD,1, -TILE_LENGTH<<1, h1, -TILE_WIDTH<<1); TMD_setVert2(myTMD,1,-TILE_LENGTH<<1, h4, 0); TMD_setNorm0(myTMD,1,4096,4096,4096); TMD_setNorm1(myTMD,1,4096,4096,4096); TMD_setNorm2(myTMD,1,4096,4096,4096); switch(texture2) { case 0: TMD_setUV3(myTMD,2,0,0,64,0,0,64); TMD_setClut(myTMD,2,GetClut(320,456)); TMD_setTPage(myTMD,2,GetTPage(1,1,896,0)); break; case 1: TMD_setUV3(myTMD,2,0,64,64,64,0,128); TMD_setClut(myTMD,2,GetClut(320,264)); TMD_setTPage(myTMD,2,GetTPage(0,0,896,0)); break; case 2: TMD_setUV3(myTMD,2,64,192,0,128,0,192); TMD_setClut(myTMD,2,GetClut(320,272)); TMD_setTPage(myTMD,2,GetTPage(0,0,896,0)); break; case 3: TMD_setUV3(myTMD,2,64,0,0,64,0,0); TMD_setClut(myTMD,2,GetClut(320,274)); TMD_setTPage(myTMD,2,GetTPage(0,0,896,256)); break; case 4: TMD_setUV3(myTMD,2,0,128,64,64,0,64); TMD_setClut(myTMD,2,GetClut(320,276)); TMD_setTPage(myTMD,2,GetTPage(0,0,896,256)); break; case 5: TMD_setUV3(myTMD,2,0,192,64,128,0,128); TMD_setClut(myTMD,2,GetClut(320,278)); TMD_setTPage(myTMD,2,GetTPage(0,0,896,256)); break; case 6: TMD_setUV3(myTMD,2,64,0,0,64,0,0); TMD_setClut(myTMD,2,GetClut(320,280)); TMD_setTPage(myTMD,2,GetTPage(0,0,832,256)); break; case 7: TMD_setUV3(myTMD,2,0,128,64,64,0,64); TMD_setClut(myTMD,2,GetClut(320,282)); TMD_setTPage(myTMD,2,GetTPage(0,0,832,256)); break; case 8: TMD_setUV3(myTMD,2,0,192,64,128,0,128); TMD_setClut(myTMD,2,GetClut(320,284)); TMD_setTPage(myTMD,2,GetTPage(0,0,832,256)); break; case 9: TMD_setUV3(myTMD,2,0,64,64,0,0,0); TMD_setClut(myTMD,2,GetClut(320,286)); TMD_setTPage(myTMD,2,GetTPage(0,0,768,256)); break; } TMD_setVert0(myTMD,2,TILE_LENGTH<<1, h6,0); TMD_setVert1(myTMD,2, TILE_LENGTH<<1, h3,-TILE_WIDTH<<1); TMD_setVert2(myTMD,2, 0, h2, -TILE_WIDTH<<1); TMD_setNorm0(myTMD,2,4096,4096,4096); TMD_setNorm1(myTMD,2,4096,4096,4096); TMD_setNorm2(myTMD,2,4096,4096,4096); switch(texture2) { case 0: TMD_setUV3(myTMD,3,64,0,0,64,64,64); TMD_setClut(myTMD,3,GetClut(320,456)); TMD_setTPage(myTMD,3,GetTPage(1,1,896,0)); break; case 1: TMD_setUV3(myTMD,3,64,64,0,128,64,128); TMD_setClut(myTMD,3,GetClut(320,264)); TMD_setTPage(myTMD,3,GetTPage(0,0,896,0)); break; case 2: TMD_setUV3(myTMD,3,64,128,0,192,64,192); TMD_setClut(myTMD,3,GetClut(320,272)); TMD_setTPage(myTMD,3,GetTPage(0,0,896,0)); break; case 3: TMD_setUV3(myTMD,3,64,0,0,64,64,64); TMD_setClut(myTMD,3,GetClut(320,274)); TMD_setTPage(myTMD,3,GetTPage(0,0,896,256)); break; case 4: TMD_setUV3(myTMD,3,0,128,64,64,64,128); TMD_setClut(myTMD,3,GetClut(320,276)); TMD_setTPage(myTMD,3,GetTPage(0,0,896,256)); break; case 5: TMD_setUV3(myTMD,3,0,192,64,128,64,192); TMD_setClut(myTMD,3,GetClut(320,278)); TMD_setTPage(myTMD,3,GetTPage(0,0,896,256)); break; case 6: TMD_setUV3(myTMD,3,64,0,0,64,64,64); TMD_setClut(myTMD,3,GetClut(320,280)); TMD_setTPage(myTMD,3,GetTPage(0,0,832,256)); break; case 7: TMD_setUV3(myTMD,3,0,128,64,64,64,128); TMD_setClut(myTMD,3,GetClut(320,282)); TMD_setTPage(myTMD,3,GetTPage(0,0,832,256)); break; case 8: TMD_setUV3(myTMD,3,0,192,64,192,0,128); TMD_setClut(myTMD,3,GetClut(320,284)); TMD_setTPage(myTMD,3,GetTPage(0,0,832,256)); break; case 9: TMD_setUV3(myTMD,3,0,64,64,0,64,64); TMD_setClut(myTMD,3,GetClut(320,286)); TMD_setTPage(myTMD,3,GetTPage(0,0,768,256)); break; } TMD_setVert0(myTMD,3, TILE_LENGTH<<1, h6, 0); TMD_setVert1(myTMD,3, 0, h2,-TILE_WIDTH<<1); TMD_setVert2(myTMD,3, 0, h5, 0); TMD_setNorm0(myTMD,3,4096,4096,4096); TMD_setNorm1(myTMD,3,4096,4096,4096); TMD_setNorm2(myTMD,3,4096,4096,4096); switch(texture3) { case 0: TMD_setUV3(myTMD,4,0,0,64,0,0,64); TMD_setClut(myTMD,4,GetClut(320,456)); TMD_setTPage(myTMD,4,GetTPage(1,1,896,0)); break; case 1: TMD_setUV3(myTMD,4,0,64,64,64,0,128); TMD_setClut(myTMD,4,GetClut(320,264)); TMD_setTPage(myTMD,4,GetTPage(0,0,896,0)); break; case 2: TMD_setUV3(myTMD,4,64,192,0,128,0,192); TMD_setClut(myTMD,4,GetClut(320,272)); TMD_setTPage(myTMD,4,GetTPage(0,0,896,0)); break; case 3: TMD_setUV3(myTMD,4,64,0,0,64,0,0); TMD_setClut(myTMD,4,GetClut(320,274)); TMD_setTPage(myTMD,4,GetTPage(0,0,896,256)); break; case 4: TMD_setUV3(myTMD,4,0,128,64,64,0,64); TMD_setClut(myTMD,4,GetClut(320,276)); TMD_setTPage(myTMD,4,GetTPage(0,0,896,256)); break; case 5: TMD_setUV3(myTMD,4,0,192,64,128,0,128); TMD_setClut(myTMD,4,GetClut(320,278)); TMD_setTPage(myTMD,4,GetTPage(0,0,896,256)); break; case 6: TMD_setUV3(myTMD,4,64,0,0,64,0,0); TMD_setClut(myTMD,4,GetClut(320,280)); TMD_setTPage(myTMD,4,GetTPage(0,0,832,256)); break; case 7: TMD_setUV3(myTMD,4,0,128,64,64,0,64); TMD_setClut(myTMD,4,GetClut(320,282)); TMD_setTPage(myTMD,4,GetTPage(0,0,832,256)); break; case 8: TMD_setUV3(myTMD,4,0,192,64,128,0,128); TMD_setClut(myTMD,4,GetClut(320,284)); TMD_setTPage(myTMD,4,GetTPage(0,0,832,256)); break; case 9: TMD_setUV3(myTMD,4,0,64,64,0,0,0); TMD_setClut(myTMD,4,GetClut(320,286)); TMD_setTPage(myTMD,4,GetTPage(0,0,768,256)); break; } TMD_setVert0(myTMD,4,0, h8, TILE_WIDTH<<1); TMD_setVert1(myTMD,4, 0, h5,0); TMD_setVert2(myTMD,4, -TILE_LENGTH<<1, h4,0); TMD_setNorm0(myTMD,4,4096,4096,4096); TMD_setNorm1(myTMD,4,4096,4096,4096); TMD_setNorm2(myTMD,4,4096,4096,4096); switch(texture3) { case 0: TMD_setUV3(myTMD,5,64,0,0,64,64,64); TMD_setClut(myTMD,5,GetClut(320,456)); TMD_setTPage(myTMD,5,GetTPage(1,1,896,0)); break; case 1: TMD_setUV3(myTMD,5,64,64,0,128,64,128); TMD_setClut(myTMD,5,GetClut(320,264)); TMD_setTPage(myTMD,5,GetTPage(0,0,896,0)); break; case 2: TMD_setUV3(myTMD,5,64,128,0,192,64,192); TMD_setClut(myTMD,5,GetClut(320,272)); TMD_setTPage(myTMD,5,GetTPage(0,0,896,0)); break; case 3: TMD_setUV3(myTMD,5,64,0,0,64,64,64); TMD_setClut(myTMD,5,GetClut(320,274)); TMD_setTPage(myTMD,5,GetTPage(0,0,896,256)); break; case 4: TMD_setUV3(myTMD,5,0,128,64,64,64,128); TMD_setClut(myTMD,5,GetClut(320,276)); TMD_setTPage(myTMD,5,GetTPage(0,0,896,256)); break; case 5: TMD_setUV3(myTMD,5,0,192,64,128,64,192); TMD_setClut(myTMD,5,GetClut(320,278)); TMD_setTPage(myTMD,5,GetTPage(0,0,896,256)); break; case 6: TMD_setUV3(myTMD,5,64,0,0,64,64,64); TMD_setClut(myTMD,5,GetClut(320,280)); TMD_setTPage(myTMD,5,GetTPage(0,0,832,256)); break; case 7: TMD_setUV3(myTMD,5,0,128,64,64,64,128); TMD_setClut(myTMD,5,GetClut(320,282)); TMD_setTPage(myTMD,5,GetTPage(0,0,832,256)); break; case 8: TMD_setUV3(myTMD,5,0,192,64,192,0,128); TMD_setClut(myTMD,5,GetClut(320,284)); TMD_setTPage(myTMD,5,GetTPage(0,0,832,256)); break; case 9: TMD_setUV3(myTMD,5,0,64,64,0,64,64); TMD_setClut(myTMD,5,GetClut(320,286)); TMD_setTPage(myTMD,5,GetTPage(0,0,768,256)); break; } TMD_setVert0(myTMD,5, 0, h8, TILE_WIDTH<<1); TMD_setVert1(myTMD,5, -TILE_LENGTH<<1, h4,0); TMD_setVert2(myTMD,5, -TILE_LENGTH<<1, h7,TILE_WIDTH<<1); TMD_setNorm0(myTMD,5,4096,4096,4096); TMD_setNorm1(myTMD,5,4096,4096,4096); TMD_setNorm2(myTMD,5,4096,4096,4096); switch(texture4) { case 0: TMD_setUV3(myTMD,6,0,0,64,0,0,64); TMD_setClut(myTMD,6,GetClut(320,456)); TMD_setTPage(myTMD,6,GetTPage(1,1,896,0)); break; case 1: TMD_setUV3(myTMD,6,0,64,64,64,0,128); TMD_setClut(myTMD,6,GetClut(320,264)); TMD_setTPage(myTMD,6,GetTPage(0,0,896,0)); break; case 2: TMD_setUV3(myTMD,6,64,192,0,128,0,192); TMD_setClut(myTMD,6,GetClut(320,272)); TMD_setTPage(myTMD,6,GetTPage(0,0,896,0)); break; case 3: TMD_setUV3(myTMD,6,64,0,0,64,0,0); TMD_setClut(myTMD,6,GetClut(320,274)); TMD_setTPage(myTMD,6,GetTPage(0,0,896,256)); break; case 4: TMD_setUV3(myTMD,6,0,128,64,64,0,64); TMD_setClut(myTMD,6,GetClut(320,276)); TMD_setTPage(myTMD,6,GetTPage(0,0,896,256)); break; case 5: TMD_setUV3(myTMD,6,0,192,64,128,0,128); TMD_setClut(myTMD,6,GetClut(320,278)); TMD_setTPage(myTMD,6,GetTPage(0,0,896,256)); break; case 6: TMD_setUV3(myTMD,6,0,128,64,64,0,64); TMD_setClut(myTMD,6,GetClut(320,280)); TMD_setTPage(myTMD,6,GetTPage(0,0,832,256)); break; case 7: TMD_setUV3(myTMD,6,0,64,64,64,0,128); TMD_setClut(myTMD,6,GetClut(320,282)); TMD_setTPage(myTMD,6,GetTPage(0,0,832,256)); break; case 8: TMD_setUV3(myTMD,6,0,192,64,128,0,128); TMD_setClut(myTMD,6,GetClut(320,284)); TMD_setTPage(myTMD,6,GetTPage(0,0,832,256)); break; case 9: TMD_setUV3(myTMD,6,0,64,64,0,0,0); TMD_setClut(myTMD,6,GetClut(320,286)); TMD_setTPage(myTMD,6,GetTPage(0,0,768,256)); break; } TMD_setVert0(myTMD,6, TILE_LENGTH<<1, h9, TILE_WIDTH<<1); TMD_setVert1(myTMD,6, TILE_LENGTH<<1, h6, 0); TMD_setVert2(myTMD,6, 0, h5,0); TMD_setNorm0(myTMD,6,4096,4096,4096); TMD_setNorm1(myTMD,6,4096,4096,4096); TMD_setNorm2(myTMD,6,4096,4096,4096); switch(texture4) { case 0: TMD_setUV3(myTMD,7,64,0,0,64,64,64); TMD_setClut(myTMD,7,GetClut(320,456)); TMD_setTPage(myTMD,7,GetTPage(1,1,896,0)); break; case 1: TMD_setUV3(myTMD,7,64,64,0,128,64,128); TMD_setClut(myTMD,7,GetClut(320,264)); TMD_setTPage(myTMD,7,GetTPage(0,0,896,0)); break; case 2: TMD_setUV3(myTMD,7,64,128,0,192,64,192); TMD_setClut(myTMD,7,GetClut(320,272)); TMD_setTPage(myTMD,7,GetTPage(0,0,896,0)); break; case 3: TMD_setUV3(myTMD,7,64,0,0,64,64,64); TMD_setClut(myTMD,7,GetClut(320,274)); TMD_setTPage(myTMD,7,GetTPage(0,0,896,256)); break; case 4: TMD_setUV3(myTMD,7,0,128,64,64,64,128); TMD_setClut(myTMD,7,GetClut(320,276)); TMD_setTPage(myTMD,7,GetTPage(0,0,896,256)); break; case 5: TMD_setUV3(myTMD,7,0,192,64,128,64,192); TMD_setClut(myTMD,7,GetClut(320,278)); TMD_setTPage(myTMD,7,GetTPage(0,0,896,256)); break; case 6: TMD_setUV3(myTMD,7,64,0,0,64,64,64); TMD_setClut(myTMD,7,GetClut(320,280)); TMD_setTPage(myTMD,7,GetTPage(0,0,832,256)); break; case 7: TMD_setUV3(myTMD,7,0,128,64,64,64,128); TMD_setClut(myTMD,7,GetClut(320,282)); TMD_setTPage(myTMD,7,GetTPage(0,0,832,256)); break; case 8: TMD_setUV3(myTMD,7,0,192,64,192,0,128); TMD_setClut(myTMD,7,GetClut(320,284)); TMD_setTPage(myTMD,7,GetTPage(0,0,832,256)); break; case 9: TMD_setUV3(myTMD,7,0,64,64,0,64,64); TMD_setClut(myTMD,7,GetClut(320,286)); TMD_setTPage(myTMD,7,GetTPage(0,0,768,256)); break; } TMD_setVert0(myTMD,7, 0, h5, 0); TMD_setVert1(myTMD,7, 0, h8, TILE_WIDTH<<1); TMD_setVert2(myTMD,7, TILE_LENGTH<<1, h9, TILE_WIDTH<<1); TMD_setNorm0(myTMD,7,4096,4096,4096); TMD_setNorm1(myTMD,7,4096,4096,4096); TMD_setNorm2(myTMD,7,4096,4096,4096); printf("TMD Address = %X",myTMD); // return value possible error cause returnValue = myTMD+sizeof(TMD_HDR)+(8*sizeof(TMD_GT3)); printf(" - %X \n",returnValue); return(returnValue); } // Creates a model for a TMD. void CreateTileModels() { long index,x=0,z=0; printf("\nCreateTile Called\n"); for(index = 0; index < currentMap->MapArea>>2; index++) { InitialiseMapModel(¤tMap->tileModel[index],x*(TILE_LENGTH<<1),0, z*(TILE_WIDTH<<1),currentMap->DYNAMIC_TMD[index]); // Use first TMDS co-ordinate system. if(index !=0)currentMap->tileModel[index].Object_Coord.super = ¤tMap->tileModel[0].Object_Coord; x+=2; if(x >= currentMap->MapLength){ z+=2; x=0; } } } // setup map by creating a TMD and a height field entry // for each and every tile/cell. void SetupMap() { long index,x=0,z=0; printf("\nSetup called\n"); currentMap->DYNAMIC_TMD[0] = (u_long *)FREE_MEM; //create TMDs for(index=0; index < currentMap->MapArea>>2; index++) { currentMap->DYNAMIC_TMD[index+1] = (u_long*) CreateTileTMD(currentMap->DYNAMIC_TMD[index], currentMap->texturePosition[x][z], currentMap->texturePosition[x+1][z], currentMap->texturePosition[x][z+1], currentMap->texturePosition[x+1][z+1], currentMap->heightFields[x][z], currentMap->heightFields[x+1][z], currentMap->heightFields[x+2][z], currentMap->heightFields[x][z+1], currentMap->heightFields[x+1][z+1], currentMap->heightFields[x+2][z+1], currentMap->heightFields[x][z+2], currentMap->heightFields[x+1][z+2], currentMap->heightFields[x+2][z+2]); x+=2; if(x >= currentMap->MapLength){ z+=2; x=0; } } // setup models CreateTileModels(); } //Rotate the whole map around cell 0,0. void RotateMap(long x, long y, long z) { // RotateModelMatrix(¤tMap->tileModel[0],x,y,z); } // Draw the height field map. clipping according // to position of camera. void DrawMap(GsCOORDINATE2 coordinate) { long index; long offset,position,tempx,tempz; // Calculate offset position to start from. // Get actual car position within TMD Grid tempx = (long)(coordinate.coord.t[0]) / (TILE_LENGTH<<2)-(CLIP_LENGTH>>1); tempz = (long)(coordinate.coord.t[2]) / (TILE_WIDTH<<2)-(CLIP_WIDTH>>1); // make sure position is within the array. if(tempx < 0) tempx = 0; if(tempz < 0) tempz = 0; if(tempx > (currentMap->MapLength>>1)-CLIP_LENGTH) tempx=(currentMap->MapLength>>1)-CLIP_LENGTH; if(tempz > (currentMap->MapWidth>>1)-CLIP_WIDTH) tempz=(currentMap->MapWidth>>1)-CLIP_WIDTH; //printf("\nafter clip x= %d z= %d",(int)tempx,(int)tempz); offset = (tempz * (currentMap->MapWidth>>1)) + tempx; //printf("\noffset = %d",offset); // Draw A small clipped region of the Map. position = offset; for(index=0; index < CLIP_AREA; index++) { DrawMapTile(¤tMap->tileModel[position],4); if(++position >= (offset+CLIP_LENGTH)) position = offset += currentMap->MapLength>>1; } } void DrawMapTile(MapObject *theModel,u_long bitShift) { MATRIX tmpls, tmplw; //Get the local world and screen coordinates, needed for light // calculations GsGetLws(theModel->Object_Handler.coord2, &tmplw, &tmpls); // Set the resulting light source matrix GsSetLightMatrix(&tmplw); // Set the local screen matrix for the GTE (so it works out // perspective etc) GsSetLsMatrix(&tmpls); // Send Object To Ordering Table GsSortObject4(&theModel->Object_Handler,&OTable_Header[CurrentBuffer],bitShift, (u_long*)getScratchAddr(0)); } // Find a height from world co-ordinates by translating them // to cell co-ordinates. long FindHeight(long rx,long rz) { long h1,h2,h3,h4,cellx,cellz; long offsetX,offsetZ; long height1; long height2; long heightTotal; // calculate cell position from actual positon here // so its not calulated more then once. cellx = (rx+(TILE_LENGTH<<1)) / (TILE_LENGTH<<1); cellz = (rz+(TILE_WIDTH<<1)) / (TILE_WIDTH<<1); // derefernce heights to be used. h1 = currentMap->heightFields[cellx][cellz]; h2 = currentMap->heightFields[cellx+1][cellz]; h3 = currentMap->heightFields[cellx][cellz+1]; h4 = currentMap->heightFields[cellx+1][cellz+1]; // calculate offset of position (same as cells, done here // to reduce calculations). offsetX = (rx+(TILE_LENGTH<<1)) % (TILE_LENGTH<<1); offsetZ = (rz+(TILE_WIDTH<<1)) % (TILE_WIDTH<<1); // calculate X heights height1=(long)((h1*((TILE_LENGTH<<1)-offsetX)) + (h2 * offsetX))/(TILE_LENGTH<<1); height2=(long)((h3*((TILE_LENGTH<<1)-offsetX)) + (h4 * offsetX))/(TILE_LENGTH<<1); // calculate Z height heightTotal=(long)((height1 * ((TILE_WIDTH<<1)-offsetZ)) + (height2 * offsetZ))/(TILE_WIDTH<<1); return (heightTotal); } // Rotation between to heights. // Specify two heights and the length between them. // The function then calculates their Tan. // *Bug warning. If length is to small strange angles // will be returned. long FindRotation(long height1, long height2, long length) { register int delta, delta2; // If heights the same exit as there is no slope if(height1==height2) return(0); // If front higher then the back if(height1 > height2) { // first delta is the difference between the heights. delta= (height1 - height2); //uses advanced atan function which is very fast delta2=rinvtan(length, delta); return ((long)(delta2 & 4095)); } // If the front is lower then the back else { delta= (height2 - height1); delta2=rinvtan(length, delta); return ((long)4096-(delta2 & 4095)); } } // Sets the current Map pointer. void SetCurrentMap(MAPStruct *theMap) { currentMap = theMap; } // set up world constraints void SetAttributes(MAPStruct * theMap,long grav,long fric, long wind) { theMap->GRAVITY = grav; theMap->FRICTION = fric; theMap->WIND = wind; } // Accessor functions, Oh er object orientty long getWind() {return currentMap->WIND;} long getFriction() {return currentMap->FRICTION;} long getGravity() {return currentMap->GRAVITY;} void RotateModelMatrixMap (MapObject *theModel, int nRX, int nRY, int nRZ) { MATRIX matTmp; SVECTOR svRotate; VECTOR startVector; // This is the vector describing the rotation svRotate.vx = nRX; svRotate.vy = nRY; svRotate.vz = nRZ; // RotMatrix sets up the matrix coefficients for rotation RotMatrix(&svRotate, &matTmp); // Concatenate the existing objects matrix with the // rotation matrix MulMatrix0(&theModel->Object_Coord.coord, &matTmp,&theModel->Object_Coord.coord); // set the flag to redraw the object AdjustCoordinate2(&theModel->Object_Coord); theModel->Object_Coord.flg = 0; } void DrawMapObjects(GsCOORDINATE2 coordinate) { u_long index; long tempx, tempz, difference; difference = CLIP_LENGTH * TILE_LENGTH; for(index=0; index < 35; index++) { tempx = coordinate.coord.t[0] - Level1Objects[index].Object_Coord.coord.t[0]; tempz = coordinate.coord.t[2] - Level1Objects[index].Object_Coord.coord.t[2]; if((tempx < difference) && (tempx > -difference)) if((tempz < difference) && (tempz > -difference)) DrawMapTile(&Level1Objects[index],4); } } void InitMapObject(MapObject *theModel, int nX, int nY, int nZ, unsigned long *lModelAddress) { //increment the pointer to past the model id. lModelAddress++; // map tmd data to its actual address GsMapModelingData(lModelAddress); // initialise the players coordinate system - set to be that of the //world GsInitCoordinate2(WORLD, &theModel->Object_Coord); // increment pointer twice more - to point to top of model data lModelAddress++; lModelAddress++; // link the model (tmd) with the players object handler GsLinkObject4((u_long)lModelAddress, &theModel->Object_Handler,0); // Assign the coordinates of the object model to the Object Handler theModel->Object_Handler.coord2 = &theModel->Object_Coord; // Set the initial position of the object theModel->Object_Coord.coord.t[0]=nX; // X theModel->Object_Coord.coord.t[1]=nY; // Y theModel->Object_Coord.coord.t[2]=nZ; // Z // setting the players Object_Coord.flg to 0 indicates it is to be // drawn theModel->Object_Coord.flg = 0; } void GetBeacon(u_long number,VECTOR *vect1, VECTOR *vect2) { vect1->vx = currentMap->Beacons[number][0].vx; vect2->vx = currentMap->Beacons[number][1].vx; vect1->vy = currentMap->Beacons[number][0].vy; vect2->vy = currentMap->Beacons[number][1].vy; vect1->vz = currentMap->Beacons[number][0].vz; vect2->vz = currentMap->Beacons[number][1].vz; } #include "maps.c"