Ejemplo n.º 1
0
Archivo: brush.c Proyecto: kellyrm/Q1
/*
============
ExpandBrush
=============
*/
void ExpandBrush (int hullindex)
{
	int	i, x, s;
	vec3_t	corner;
	face_t	*f;
	plane_t	plane, *p;

	num_hull_points = 0;
	num_hull_edges = 0;

// create all the hull points

	for (f=brush_faces ; f ; f=f->next)
		for (i=0 ; i<f->numpoints ; i++)
			AddHullPoint (f->pts[i], hullindex);

// expand all of the planes
	for (i=0 ; i<numbrushfaces ; i++)
	{
		p = &faces[i].plane;

		VectorCopy (vec3_origin, corner);
		for (x=0 ; x<3 ; x++)
		{
			if (p->normal[x] > 0)
				corner[x] = ExpandSize (hullindex, 1, x);
			else if (p->normal[x] < 0)
				corner[x] = ExpandSize (hullindex, 0, x);
		}
		p->dist += DotProduct (corner, p->normal);
	}

// add any axis planes not contained in the brush to bevel off corners
	for (x=0 ; x<3 ; x++)
		for (s=-1 ; s<=1 ; s+=2)
		{
		// add the plane
			VectorCopy (vec3_origin, plane.normal);
			plane.normal[x] = s;
			if (s == -1)
				plane.dist = -brush_mins[x] - ExpandSize (hullindex, 0, x);
			else
				plane.dist = brush_maxs[x] + ExpandSize (hullindex, 1, x);
			AddBrushPlane (&plane, hullnum);
		}

// add all of the edge bevels
	for (f=brush_faces ; f ; f=f->next)
		for (i=0 ; i<f->numpoints ; i++)
			AddHullEdge (f->pts[i], f->pts[(i+1)%f->numpoints], hullindex);
}
Ejemplo n.º 2
0
/*
============
ExpandBrush
=============
*/
void ExpandBrush (brush_t *b, int hullnum)
{
    int		i, x, s;
    int		corner;
    bface_t	*brush_faces, *f, *nf;
    plane_t	*p, plane;
    int		iorigin[3], inormal[3];
    expand_t	ex;
    brushhull_t	*h;
    qboolean	axial;

    brush_faces = b->hulls[0].faces;
    h = &b->hulls[hullnum];

    ex.b = b;
    ex.hullnum = hullnum;
    ex.num_hull_points = 0;
    ex.num_hull_edges = 0;

// expand all of the planes
    axial = true;
    for (f=brush_faces ; f ; f=f->next)
    {
        p = f->plane;
        if (p->type > PLANE_Z)
            axial = false;	// not an xyz axial plane

        VectorCopy (p->iorigin, iorigin);
        VectorCopy (p->inormal, inormal);

        for (x=0 ; x<3 ; x++)
        {
            if (p->normal[x] > 0)
                corner = hull_size[hullnum][1][x];
            else if (p->normal[x] < 0)
                corner = - hull_size[hullnum][0][x];
            else
                corner = 0;
            iorigin[x] += p->normal[x]*corner;
        }
        nf = malloc(sizeof(*nf));
        memset (nf, 0, sizeof(*nf));

        nf->planenum = FindIntPlane (inormal, iorigin);
        nf->plane = &mapplanes[nf->planenum];
        nf->next = h->faces;
        nf->contents = CONTENTS_EMPTY;
        h->faces = nf;
        nf->texinfo = 0;	// all clip hulls have same texture
    }

    // if this was an axial brush, we are done
    if (axial)
        return;

#if 1
// add any axis planes not contained in the brush to bevel off corners
    for (x=0 ; x<3 ; x++)
        for (s=-1 ; s<=1 ; s+=2)
        {
            // add the plane
            VectorCopy (vec3_origin, plane.inormal);
            plane.inormal[x] = s;
            if (s == -1)
            {
                VectorAdd (b->hulls[0].mins, hull_size[hullnum][0], plane.iorigin);
            }
            else
            {
                VectorAdd (b->hulls[0].maxs, hull_size[hullnum][1], plane.iorigin);
            }
            AddBrushPlane (&ex, &plane);
        }
#endif

#if 0
// create all the hull points
    for (f=brush_faces ; f ; f=f->next)
        for (i=0 ; i<f->w->numpoints ; i++)
            AddHullPoint (&ex, f->w->p[i]);

// add all of the edge bevels
    for (f=brush_faces ; f ; f=f->next)
        for (i=0 ; i<f->w->numpoints ; i++)
            AddHullEdge (&ex, f->w->p[i], f->w->p[(i+1)%f->w->numpoints]);
#endif
}
Ejemplo n.º 3
0
/*
============
ExpandBrush
=============
*/
void ExpandBrush (int hullnum)
{
	int			i, x, s;
	vec3_t		corner;
	winding_t	*w;
	plane_t		plane;

	int				j, k, numwindings;
	vec_t			r;
	winding_t		**windings;
	plane_t			clipplane, faceplane;
	mface_t			*mf;
	vec3_t			point;
	vec3_t		mins, maxs;

	if (!numbrushfaces)
		return;

	num_hull_points = 0;
	num_hull_edges = 0;

	ClearBounds( mins, maxs );

	// generate windings and bounds data
	numwindings = 0;
	windings = calloc(numbrushfaces, sizeof(*windings));
	for (i = 0;i < numbrushfaces;i++)
	{
		mf = &faces[i];
		windings[i] = NULL;

		faceplane = mf->plane;
		w = BaseWindingForPlane (&faceplane);

		for (j = 0;j < numbrushfaces && w;j++)
		{
			clipplane = faces[j].plane;
			if( j == i )
				continue;

			// flip the plane, because we want to keep the back side
			VectorNegate(clipplane.normal, clipplane.normal);
			clipplane.dist *= -1;

			w = ClipWindingEpsilon (w, &clipplane, ON_EPSILON, true);
		}

		if (!w)
			continue;	// overcontrained plane

		for (j = 0;j < w->numpoints;j++)
		{
			for (k = 0;k < 3;k++)
			{
				point[k] = w->points[j][k];
				r = Q_rint( point[k] );
				if ( fabs( point[k] - r ) < ZERO_EPSILON)
					w->points[j][k] = r;
				else
					w->points[j][k] = point[k];

				// check for incomplete brushes
				if( w->points[j][k] >= BOGUS_RANGE || w->points[j][k] <= -BOGUS_RANGE )
					return;
			}

			AddPointToBounds( w->points[j], mins, maxs );
		}

		windings[i] = w;
	}

	// add all of the corner offsets
	for (i = 0;i < numwindings;i++)
	{
		w = windings[i];
		for (j = 0;j < w->numpoints;j++)
			AddHullPoint(w->points[j], hullnum);
	}

	// expand the face planes
	for (i = 0;i < numbrushfaces;i++)
	{
		mf = &faces[i];
		for (x=0 ; x<3 ; x++)
		{
			if (mf->plane.normal[x] > 0)
				corner[x] = -hullinfo.hullsizes[hullnum][0][x];
			else if (mf->plane.normal[x] < 0)
				corner[x] = -hullinfo.hullsizes[hullnum][1][x];
		}
		mf->plane.dist += DotProduct (corner, mf->plane.normal);
	}

	// add any axis planes not contained in the brush to bevel off corners
	for (x=0 ; x<3 ; x++)
		for (s=-1 ; s<=1 ; s+=2)
		{
			// add the plane
			VectorClear (plane.normal);
			plane.normal[x] = s;
			if (s == -1)
				plane.dist = -mins[x] + hullinfo.hullsizes[hullnum][1][x];
			else
				plane.dist = maxs[x] + -hullinfo.hullsizes[hullnum][0][x];
			AddBrushPlane (&plane);
		}

	// add all of the edge bevels
	for (i = 0;i < numwindings;i++)
	{
		w = windings[i];
		for (j = 0;j < w->numpoints;j++)
			AddHullEdge(w->points[j], w->points[(j+1)%w->numpoints], hullnum);
	}

	// free the windings as we no longer need them
	for (i = 0;i < numwindings;i++)
		if (windings[i])
			FreeWinding(windings[i]);
	free(windings);
}