All pastes #968097 Raw Edit

Terrain patch rendering code

public c v1 · immutable
·published 2008-04-02 20:33 UTC
rendered paste body
void RB_SurfaceTerrainPatch(srfTerrainPatch_t *surf) {	int			x, y;	vec3_t		v;	int			ndx, Wombat, Hippy, vertID;	// screw that, let's do simple quad rendering to debug positioning and texture coordinates	Wombat = tess.numIndexes;	tess.numIndexes += 6;	Hippy = tess.numVertexes;	tess.numVertexes += 4;	// vertices	for (ndx = Hippy, x = 0; x < 2; x++) {		for (y = 0; y < 2; y++, ndx++) {			if (tess.shader->needsNormal)				// TODO				VectorSet(tess.normal[ndx], 0.f, 0.f, 1.f);	// placeholder horizontal normal			VectorCopy(surf->patch->origin, v);			v[0] += x * 512.f;			v[1] += y * 512.f;			v[2] += surf->patch->heightmap[y * 8][x * 8] + 256.f;			VectorCopy(v, tess.xyz[ndx]);			vertID = x % 2;			tess.texCoords[ndx][0][0] = surf->patch->texCoords[vertID][0][0];			tess.texCoords[ndx][0][1] = surf->patch->texCoords[vertID][0][1];			tess.texCoords[ndx][1][0] = surf->patch->texCoords[vertID][1][0];			tess.texCoords[ndx][1][1] = surf->patch->texCoords[vertID][1][1];		}	}	// triangles	tess.indexes[ndx + 0] = Hippy + 3;	tess.indexes[ndx + 1] = Hippy + 0;	tess.indexes[ndx + 2] = Hippy + 1;	tess.indexes[ndx + 3] = Hippy + 3;	tess.indexes[ndx + 4] = Hippy + 2;	tess.indexes[ndx + 5] = Hippy + 0;}