Example #1
0
/*
   ================
   NumberLeafs_r
   ================
 */
void NumberLeafs_r( node_t *node ){
	portal_t    *p;

	if ( node->planenum != PLANENUM_LEAF && !node->detail_seperator ) { // decision node
		node->cluster = -99;
		NumberLeafs_r( node->children[0] );
		NumberLeafs_r( node->children[1] );
		return;
	}

	// either a leaf or a detail cluster

	if ( node->contents & CONTENTS_SOLID ) { // solid block, viewpoint never inside
		node->cluster = -1;
		return;
	}

	FillLeafNumbers_r( node, num_visclusters );
	num_visclusters++;

	// count the portals
	for ( p = node->portals ; p ; )
	{
		if ( p->nodes[0] == node ) {      // only write out from first leaf
			if ( Portal_VisFlood( p ) ) {
				num_visportals++;
			}
			p = p->next[0];
		}
		else{
			p = p->next[1];
		}
	}

}
Example #2
0
/*
=================
WritePortalFile_r
=================
*/
void WritePortalFile_r (node_t *node)
{
	int			i, s;	
	portal_t	*p;
	winding_t	*w;
	vec3_t		normal;
	vec_t		dist;

	// decision node
	if (node->planenum != PLANENUM_LEAF && !node->detail_seperator)
	{
		WritePortalFile_r (node->children[0]);
		WritePortalFile_r (node->children[1]);
		return;
	}
	
	if (node->contents & CONTENTS_SOLID)
		return;

	for (p = node->portals ; p ; p=p->next[s])
	{
		w = p->winding;
		s = (p->nodes[1] == node);
		if (w && p->nodes[0] == node)
		{
			if (!Portal_VisFlood (p))
				continue;
		// write out to the file
		
		// sometimes planes get turned around when they are very near
		// the changeover point between different axis.  interpret the
		// plane the same way vis will, and flip the side orders if needed
			// FIXME: is this still relevent?
			WindingPlane (w, normal, &dist);
			if ( DotProduct (p->plane.normal, normal) < 0.99 )
			{	// backwards...
				fprintf (pf,"%i %i %i ",w->numpoints, p->nodes[1]->cluster, p->nodes[0]->cluster);
			}
			else
				fprintf (pf,"%i %i %i ",w->numpoints, p->nodes[0]->cluster, p->nodes[1]->cluster);
			for (i=0 ; i<w->numpoints ; i++)
			{
				fprintf (pf,"(");
				WriteFloat (pf, w->p[i][0]);
				WriteFloat (pf, w->p[i][1]);
				WriteFloat (pf, w->p[i][2]);
				fprintf (pf,") ");
			}
			fprintf (pf,"\n");
		}
	}

}