//------------------------------------ // Cunning system of creating a level // based on a mesh. Prevents ANY tile // ripping in map and changing one // vertex updates all patches using // it. (C) Tom Madams //------------------------------------ #include #include "tmd.h" //------------------------------------ // Globals //------------------------------------ VERTEX *VERTEX_LUT; COLOUR *COLOUR_LUT; TEXTURE *TEXTURE_LUT; //------------------------------------ // Function definitions //------------------------------------ // Prepare for the creation of a new tmd void PrepareTMD(u_long address, VERTEX *vertex, COLOUR *colour, TEXTURE *texture) { VERTEX_LUT = vertex; COLOUR_LUT = colour; TEXTURE_LUT = texture; } // Add a textured-gradiated-tinted quad to tmd void SetTX_NS_FP_TRI(TX_NS_FP_TRI_FACE *newPoly, u_short v0, u_short v1, u_short v2, u_long c0, u_long t0, u_short uv0, u_short uv1, u_short uv2) { SetPrimitiveHeader(newPoly, TX_NS_FP_TRI, 1, 6, 7); newPoly->vert0 = v0; newPoly->vert1 = v1; newPoly->vert2 = v2; SetColour0(); SetTextureTri((TX_NS_FP_TRI_FACE *)newPoly, t0, uv0, uv1, uv2); } // Set texture information for a tri void SetTextureTri(TX_NS_FP_TRI_FACE *newPoly, u_long textureNum, u_short uv0, u_short uv1, u_short uv2) { TEXTURE *texture = TEXTURE_LUT + textureNum; u_short tPage; int tPageX = 1024, tPageY = 512; if (tPageX > (texture->x[uv0])) tPageX = texture->x[uv0]; if (tPageY > (texture->y[uv0])) tPageY = texture->y[uv0]; if (tPageX > (texture->x[uv1])) tPageX = texture->x[uv1]; if (tPageY > (texture->y[uv1])) tPageY = texture->y[uv1]; if (tPageX > (texture->x[uv2])) tPageX = texture->x[uv2]; if (tPageY > (texture->y[uv2])) tPageY = texture->y[uv2]; tPageX = tPageX>>6; tPageX = tPageX<<6; tPageY = tPageY>>8; tPageY = tPageY<<8; tPage = GetTPage((int )texture->pmode, 0, tPageX, tPageY); newPoly->u0 = (u_char )(texture->x[uv0] - tPageX); newPoly->v0 = (u_char )(texture->y[uv0] - tPageY); newPoly->u1 = (u_char )(texture->x[uv1] - tPageX); newPoly->v1 = (u_char )(texture->y[uv1] - tPageY); newPoly->u2 = (u_char )(texture->x[uv2] - tPageX); newPoly->v2 = (u_char )(texture->y[uv2] - tPageY); newPoly->tsb = (u_short )tPage; newPoly->cba = ((texture->cx)>>4) + ((texture->cy)<<6); }