Esempio n. 1
0
/*
================
idSaveGame::WriteBounds
================
*/
void idSaveGame::WriteWinding(const idWinding &w)
{
	int i, num;
	num = w.GetNumPoints();
	file->WriteInt(num);

	for (i = 0; i < num; i++) {
		idVec5 v = w[i];
		LittleRevBytes(&v, sizeof(float), sizeof(v)/sizeof(float));
		file->Write(&v, sizeof(v));
	}
}
Esempio n. 2
0
/*
=================
idRenderModelDecal::CreateDecalFromWinding
=================
*/
void idRenderModelDecal::CreateDecalFromWinding( const idWinding &w, const idMaterial *decalMaterial, const idPlane fadePlanes[2], float fadeDepth, int startTime ) {
	// Often we are appending a new triangle to an existing decal, so merge with the previous decal if possible
	int decalIndex = ( nextDecal - 1 ) & ( MAX_DECALS - 1 );
	if ( decalIndex >= 0
		&& decals[decalIndex].material == decalMaterial
		&& decals[decalIndex].startTime == startTime
		&& decals[decalIndex].numVerts + w.GetNumPoints() <= MAX_DECAL_VERTS
		&& decals[decalIndex].numIndexes + 3 * ( w.GetNumPoints() - 2 ) <= MAX_DECAL_INDEXES ) {
	} else {
		decalIndex = nextDecal++ & ( MAX_DECALS - 1 );
		decals[decalIndex].material = decalMaterial;
		decals[decalIndex].startTime = startTime;
		decals[decalIndex].numVerts = 0;
		decals[decalIndex].numIndexes = 0;
		assert( w.GetNumPoints() <= MAX_DECAL_VERTS );
		if ( nextDecal - firstDecal > MAX_DECALS ) {
			firstDecal = nextDecal - MAX_DECALS;
		}
	}

	decal_t & decal = decals[decalIndex];

	const float invFadeDepth = -1.0f / fadeDepth;

	int firstVert = decal.numVerts;

	// create the vertices
	for ( int i = 0; i < w.GetNumPoints(); i++ ) {
		float depthFade = fadePlanes[0].Distance( w[i].ToVec3() ) * invFadeDepth;
		if ( depthFade < 0.0f ) {
			depthFade = fadePlanes[1].Distance( w[i].ToVec3() ) * invFadeDepth;
		}
		if ( depthFade < 0.0f ) {
			depthFade = 0.0f;
		} else if ( depthFade > 0.99f ) {
			depthFade = 1.0f;
		}
		decal.vertDepthFade[decal.numVerts] = 1.0f - depthFade;
		decal.verts[decal.numVerts].Clear();
		decal.verts[decal.numVerts].xyz = w[i].ToVec3();
		decal.verts[decal.numVerts].SetTexCoord( w[i].s, w[i].t );
		decal.numVerts++;
	}

	// create the indexes
	for ( int i = 2; i < w.GetNumPoints(); i++ ) {
		assert( decal.numIndexes + 3 <= MAX_DECAL_INDEXES );
		decal.indexes[decal.numIndexes + 0] = firstVert;
		decal.indexes[decal.numIndexes + 1] = firstVert + i - 1;
		decal.indexes[decal.numIndexes + 2] = firstVert + i;
		decal.numIndexes += 3;
	}

	// add degenerate triangles until the index size is a multiple of 16 bytes
	for ( ; ( ( ( decal.numIndexes * sizeof( triIndex_t ) ) & 15 ) != 0 ); decal.numIndexes += 3 ) {
		assert( decal.numIndexes + 3 <= MAX_DECAL_INDEXES );
		decal.indexes[decal.numIndexes + 0] = 0;
		decal.indexes[decal.numIndexes + 1] = 0;
		decal.indexes[decal.numIndexes + 2] = 0;
	}
}