Ejemplo n.º 1
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
void AAS_CheckArea(tmp_area_t *tmparea)
{
	int side;
	tmp_face_t *face;
	plane_t *plane;
	vec3_t wcenter, acenter = {0, 0, 0};
	vec3_t normal;
	float n, dist;

	if (tmparea->invalid) Log_Print("AAS_CheckArea: invalid area\n");
	for (n = 0, face = tmparea->tmpfaces; face; face = face->next[side])
	{
		//side of the face the area is on
		side = face->frontarea != tmparea;
		WindingCenter(face->winding, wcenter);
		VectorAdd(acenter, wcenter, acenter);
		n++;
	} //end for
	n = 1 / n;
	VectorScale(acenter, n, acenter);
	for (face = tmparea->tmpfaces; face; face = face->next[side])
	{
		//side of the face the area is on
		side = face->frontarea != tmparea;

#ifdef L_DEBUG
		if (WindingError(face->winding))
		{
			Log_Write("AAS_CheckArea: area %d face %d: %s\r\n", tmparea->areanum,
						face->num, WindingErrorString());
		} //end if
#endif

		plane = &mapplanes[face->planenum ^ side];

		if (DotProduct(plane->normal, acenter) - plane->dist < 0)
		{
			Log_Print("AAS_CheckArea: area %d face %d is flipped\n", tmparea->areanum, face->num);
			Log_Print("AAS_CheckArea: area %d center is %f %f %f\n", tmparea->areanum, acenter[0], acenter[1], acenter[2]);
		} //end if
		//check if the winding plane is the same as the face plane
		WindingPlane(face->winding, normal, &dist);
		plane = &mapplanes[face->planenum];
#ifdef L_DEBUG
		if (fabs(dist - plane->dist) > 0.4 ||
				fabs(normal[0] - plane->normal[0]) > 0.0001 ||
				fabs(normal[1] - plane->normal[1]) > 0.0001 ||
				fabs(normal[2] - plane->normal[2]) > 0.0001)
		{
			Log_Write("AAS_CheckArea: area %d face %d winding plane unequal to face plane\r\n",
										tmparea->areanum, face->num);
		} //end if
#endif
	} //end for
} //end of the function AAS_CheckArea
Ejemplo n.º 2
0
void Sin_FixTextureReferences( void ) {
	int i, j, k, we;
	sin_dbrushside_t *brushside;
	sin_dbrush_t *brush;
	sin_dface_t *face;
	winding_t *w;

	memset( sin_dbrushsidetextured, false, SIN_MAX_MAP_BRUSHSIDES );
	//go over all the brushes
	for ( i = 0; i < sin_numbrushes; i++ )
	{
		brush = &sin_dbrushes[i];
		//hint brushes are not textured
		if ( Sin_HintSkipBrush( brush ) ) {
			continue;
		}
		//go over all the sides of the brush
		for ( j = 0; j < brush->numsides; j++ )
		{
			brushside = &sin_dbrushsides[brush->firstside + j];
			//
			w = Sin_BrushSideWinding( brush, brushside );
			if ( !w ) {
				sin_dbrushsidetextured[brush->firstside + j] = true;
				continue;
			} //end if
			else
			{
				//RemoveEqualPoints(w, 0.2);
				if ( WindingIsTiny( w ) ) {
					FreeWinding( w );
					sin_dbrushsidetextured[brush->firstside + j] = true;
					continue;
				} //end if
				else
				{
					we = WindingError( w );
					if ( we == WE_NOTENOUGHPOINTS
						 || we == WE_SMALLAREA
						 || we == WE_POINTBOGUSRANGE
//						|| we == WE_NONCONVEX
						 ) {
						FreeWinding( w );
						sin_dbrushsidetextured[brush->firstside + j] = true;
						continue;
					} //end if
				} //end else
			} //end else
			if ( WindingArea( w ) < 20 ) {
				sin_dbrushsidetextured[brush->firstside + j] = true;
			} //end if
			  //find a face for texturing this brush
			for ( k = 0; k < sin_numfaces; k++ )
			{
				face = &sin_dfaces[k];
				//if the face is in the same plane as the brush side
				if ( ( face->planenum & ~1 ) != ( brushside->planenum & ~1 ) ) {
					continue;
				}
				//if the face is partly or totally on the brush side
				if ( Sin_FaceOnWinding( face, w ) ) {
					brushside->texinfo = face->texinfo;
					sin_dbrushsidetextured[brush->firstside + j] = true;
					break;
				} //end if
			} //end for
			FreeWinding( w );
		} //end for
	} //end for
} //end of the function Sin_FixTextureReferences*/
Ejemplo n.º 3
0
void Q3_FindVisibleBrushSides(void)
{
    int i, j, k, we, numtextured, numsides;
    float dot;
    dplane_t *plane;
    dbrushside_t *brushside;
    dbrush_t *brush;
    dsurface_t *surface;
    winding_t *w;

    memset(dbrushsidetextured, false, MAX_MAP_BRUSHSIDES);
    //
    numsides = 0;
    //create planes for the planar surfaces
    Q3_CreatePlanarSurfacePlanes();
    Log_Print("searching visible brush sides...\n");
    Log_Print("%6d brush sides", numsides);
    //go over all the brushes
    for (i = 0; i < q3_numbrushes; i++)
    {
        brush = &dbrushes[i];
        //go over all the sides of the brush
        for (j = 0; j < brush->numSides; j++)
        {
            qprintf("\r%6d", numsides++);
            brushside = &dbrushsides[brush->firstSide + j];
            //
            w = Q3_BrushSideWinding(brush, brushside);
            if (!w)
            {
                dbrushsidetextured[brush->firstSide + j] = true;
                continue;
            } //end if
            else
            {
                //RemoveEqualPoints(w, 0.2);
                if (WindingIsTiny(w))
                {
                    FreeWinding(w);
                    dbrushsidetextured[brush->firstSide + j] = true;
                    continue;
                } //end if
                else
                {
                    we = WindingError(w);
                    if (we == WE_NOTENOUGHPOINTS
                            || we == WE_SMALLAREA
                            || we == WE_POINTBOGUSRANGE
//						|| we == WE_NONCONVEX
                       )
                    {
                        FreeWinding(w);
                        dbrushsidetextured[brush->firstSide + j] = true;
                        continue;
                    } //end if
                } //end else
            } //end else
            if (WindingArea(w) < 20)
            {
                dbrushsidetextured[brush->firstSide + j] = true;
                continue;
            } //end if
            //find a face for texturing this brush
            for (k = 0; k < q3_numDrawSurfaces; k++)
            {
                surface = &drawSurfaces[k];
                if (surface->surfaceType != MST_PLANAR) continue;
                //
                //Q3_SurfacePlane(surface, plane.normal, &plane.dist);
                plane = &q3_surfaceplanes[k];
                //the surface plane and the brush side plane should be pretty much the same
                if (fabs(fabs(plane->dist) - fabs(dplanes[brushside->planeNum].dist)) > 5) continue;
                dot = DotProduct(plane->normal, dplanes[brushside->planeNum].normal);
                if (dot > -0.9 && dot < 0.9) continue;
                //if the face is partly or totally on the brush side
                if (Q3_FaceOnWinding(surface, w))
                {
                    dbrushsidetextured[brush->firstSide + j] = true;
                    //Log_Write("Q3_FaceOnWinding");
                    break;
                } //end if
            } //end for
            FreeWinding(w);
        } //end for
    } //end for
    qprintf("\r%6d brush sides\n", numsides);
    numtextured = 0;
    for (i = 0; i < q3_numbrushsides; i++)
    {
        if (forcesidesvisible) dbrushsidetextured[i] = true;
        if (dbrushsidetextured[i]) numtextured++;
    } //end for
    Log_Print("%d brush sides textured out of %d\n", numtextured, q3_numbrushsides);
} //end of the function Q3_FindVisibleBrushSides