

static void MapDraw_Dreamcast_DrawMesh(WORLD_MESH_INSTANCE *instance, int depthscaler, TDCWorldMesh *dcMesh)
{
	float	mapmin;
#ifdef MAPDRAW_USE_MAXZCHECK
	float	mapmax;
#endif
	float	x0, x1, x2, x3;
	float	y0, y1, y2, y3;
	float	z0, z1, z2, z3;

	// calculate polygon maximum and minimum z depths
	mapmin = MIN_MAP_DEPTH - ((float)instance->sort_depth);
	mapmin = MAX(mapmin, 1.0f);
#ifdef MAPDRAW_USE_MAXZCHECK
	mapmax = MAX_MAP_DEPTH - ((float)instance->sort_depth);
	mapmax = MIN(mapmax, (1024.0f - ((float)instance->sort_depth)));
#endif

	// transform this meshes vertices
	{
		float meshOffs[4];
		meshOffs[0] = instance->posx - mycamera.vpx;
		meshOffs[1] = instance->posy - mycamera.vpy;
		meshOffs[2] = instance->posz - mycamera.vpz;
		meshOffs[3] = (float)depthbump;
		SH4XD_TransformVertices(dcMesh->vertices, alignedTransformedVertices, dcMesh->noofVerts, meshOffs);
	}

	...........
	...........
	...........
	...........

}


/* ---------------------------------------------------------
   Function : SH4XD_TransformVertices
   Purpose : Transform vertices with the 
   Parameters : input verts, output verts, number of verts, mesh instance-camera position offset xyz and 2d depth bump
   Returns : 
   Info : Because of the way this function performs two transforms per pass we need to allow extra
		: data at the end of the input vertices loop to prevent possible memory leaks
*/

void SH4XD_TransformVertices(TDCVector4 *verts, TDCTransVector *transVerts, int noof, float *offsets)
{
	// stack these common vars for speed
	float			_fGShHalf = fGShHalf, _fGShLimit = fGShLimit, _fGSh = fGSh;
	float			rcp = 1.0f;

	register float	_fGSx = fGSx, _fGSy = fGSy;
	register float	ox = *offsets++, oy = *offsets++, oz = *offsets++, x1,y1,z1,z2, s;

	register float	*vsin, *vsinNext, *vsout, *vsoutEnd;

	float			o2dz = *offset;

	TDCVector4		vi, vo;


	// vertices in
	vsin = (float *)verts;
	prefetch(vsin);
	vsinNext = vsin + 8;

	// vetices out
	vsout = (float *)transVerts;
	vsoutEnd = vsout + noof*4;

	// transform all vertices
	while (vsout < vsoutEnd)
	{
		// prefetch the next vertex pair
		prefetch(vsinNext);
		vsinNext += 8;


		// ** Transform vertex0

		// load vertex from the mesh + offset
		vi.x = *vsin++ + ox;
		vi.y = *vsin++ + oy;
		vi.z = *vsin++ + oz;
		vi.w = *vsin++;

		// transform the vertex into view space
		ftrv((float *)&vi, (float *)&vo);

		// project the first vertex
		z1 = vo.z;
		y1 = vo.y;
		x1 = vo.x;

		// limit projection
		if (z1 >= _fGShHalf)
			s = _fGSh / z1;
		else
			s = _fGShLimit;

		// offset z with the 2d depth bump
		z1 += o2dz;

		// get 1/z
		z2 = rcp / z1;

		// project
		x1 *= s;
		x1 += _fGSx;
		y1 *= s;
		y1 += _fGSy;

		// save the first vertex
		*vsout++ = z1;
		*vsout++ = x1;
		*vsout++ = y1;
		*vsout++ = z2;


		// ** Transform vertex1

		// load vertex from the mesh + offset
		vi.x = *vsin++ + ox;
		vi.y = *vsin++ + oy;
		vi.z = *vsin++ + oz;
		vi.w = *vsin++;

		// transform the vertex into view space
		ftrv((float *)&vi, (float *)&vo);

		// project the first vertex
		z1 = vo.z;
		y1 = vo.y;
		x1 = vo.x;

		// limit projection
		if (z1 >= _fGShHalf)
			s = _fGSh / z1;
		else
			s = _fGShLimit;

		// offset z with the 2d depth bump
		z1 += o2dz;

		// get 1/z
		z2 = rcp / z1;

		// project
		x1 *= s;
		x1 += _fGSx;
		y1 *= s;
		y1 += _fGSy;

		// save the first vertex
		*vsout++ = z1;
		*vsout++ = x1;
		*vsout++ = y1;
		*vsout++ = z2;
	}
}
