Esempio n. 1
0
void AddHullEdge (expand_t *ex, vec3_t p1, vec3_t p2)
{
    int		pt1, pt2;
    int		i;
    int		a, b, c, d, e;
    vec3_t	edgevec, planeorg, planevec;
    plane_t	plane;
    vec_t	l;

    pt1 = AddHullPoint (ex, p1);
    pt2 = AddHullPoint (ex, p2);

    // now use the rounded values
    p1 = ex->hull_points[pt1];
    p2 = ex->hull_points[pt2];

    for (i=0 ; i<ex->num_hull_edges ; i++)
        if ( (ex->hull_edges[i][0] == pt1 && ex->hull_edges[i][1] == pt2)
                || (ex->hull_edges[i][0] == pt2 && ex->hull_edges[i][1] == pt1) )
            return;	// allread added

    if (ex->num_hull_edges == MAX_HULL_EDGES)
        Error ("MAX_HULL_EDGES");

    ex->hull_edges[i][0] = pt1;
    ex->hull_edges[i][1] = pt2;
    ex->num_hull_edges++;

    VectorSubtract (p1, p2, edgevec);
    VectorNormalize (edgevec);

    for (a=0 ; a<3 ; a++)
    {
        b = (a+1)%3;
        c = (a+2)%3;
        for (d=0 ; d<=1 ; d++)
            for (e=0 ; e<=1 ; e++)
            {
                VectorCopy (p1, plane.iorigin);
                plane.iorigin[b] += hull_size[ex->hullnum][d][b];
                plane.iorigin[c] += hull_size[ex->hullnum][e][c];

                VectorCopy (vec3_origin, planevec);
                planevec[a] = 1;

                plane.inormal[0] = planevec[1]*edgevec[2] - planevec[2]*edgevec[1];
                plane.inormal[1] = planevec[2]*edgevec[0] - planevec[0]*edgevec[2];
                plane.inormal[2] = planevec[0]*edgevec[1] - planevec[1]*edgevec[0];

                if (!plane.inormal[0] && !plane.inormal[1] && !plane.inormal[2])
                    continue;	// degenerate
                TestAddPlane (ex, &plane);
            }
    }


}
Esempio n. 2
0
/*
============
AddHullEdge

Creates all of the hull planes around the given edge, if not done allready
=============
*/
void AddHullEdge (vec3_t p1, vec3_t p2, int hullnum)
{
	int		pt1, pt2;
	int		i;
	int		a, b, c, d, e;
	vec3_t	edgevec, planeorg, planevec;
	plane_t	plane;
	vec_t	length;

	pt1 = AddHullPoint (p1, hullnum);
	pt2 = AddHullPoint (p2, hullnum);

	for (i=0 ; i<num_hull_edges ; i++)
		if ((hull_edges[i][0] == pt1 && hull_edges[i][1] == pt2) || (hull_edges[i][0] == pt2 && hull_edges[i][1] == pt1))
			return;	// already added

	if (num_hull_edges == MAX_HULL_EDGES)
		Error ("AddHullEdge: MAX_HULL_EDGES");

	hull_edges[num_hull_edges][0] = pt1;
	hull_edges[num_hull_edges][1] = pt2;
	num_hull_edges++;

	VectorSubtract(p1, p2, edgevec);
	VectorNormalize(edgevec);

	for (a=0 ; a<3 ; a++)
	{
		b = (a+1)%3;
		c = (a+2)%3;

		planevec[a] = 1;
		planevec[b] = 0;
		planevec[c] = 0;
		CrossProduct(planevec, edgevec, plane.normal);
		length = VectorNormalize(plane.normal);

		/* If this edge is almost parallel to the hull edge, skip it. */
		if (length < ANGLE_EPSILON)
			continue;

		for (d = 0 ; d < 2 ; d++)
		{
			for (e = 0 ; e < 2 ; e++)
			{
				VectorCopy(p1, planeorg);
				planeorg[b] -= hullinfo.hullsizes[hullnum][d^1][b];
				planeorg[c] -= hullinfo.hullsizes[hullnum][e^1][c];
				plane.dist = DotProduct(planeorg, plane.normal);

				TestAddPlane(&plane);
			}
		}
	}
}
Esempio n. 3
0
/*
============
AddHullEdge

Creates all of the hull planes around the given edge, if not done allready
=============
*/
void AddHullEdge (vec3_t p1, vec3_t p2, int hullnum)
{
	int		pt1, pt2;
	int		i;
	int		a, b, c, d, e;
	vec3_t	edgevec, planeorg, planevec;
	plane_t	plane;
	vec_t	l;
	
	pt1 = AddHullPoint (p1, hullnum);
	pt2 = AddHullPoint (p2, hullnum);
	
	for (i=0 ; i<num_hull_edges ; i++)
		if ( (hull_edges[i][0] == pt1 && hull_edges[i][1] == pt2)
		|| (hull_edges[i][0] == pt2 && hull_edges[i][1] == pt1) )
			return;	// allread added
		
	if (num_hull_edges == MAX_HULL_EDGES)
		Error ("MAX_HULL_EDGES");

	hull_edges[i][0] = pt1;
	hull_edges[i][1] = pt2;
	num_hull_edges++;
		
	VectorSubtract (p1, p2, edgevec);
	VectorNormalize (edgevec);
	
	for (a=0 ; a<3 ; a++)
	{
		b = (a+1)%3;
		c = (a+2)%3;
		for (d=0 ; d<=1 ; d++)
			for (e=0 ; e<=1 ; e++)
			{
				VectorCopy (p1, planeorg);
				planeorg[b] += hull_size[hullnum][d][b];
				planeorg[c] += hull_size[hullnum][e][c];
				
				VectorCopy (vec3_origin, planevec);
				planevec[a] = 1;
				
				CrossProduct (planevec, edgevec, plane.normal);
				l = VectorLength (plane.normal);
				if (l < 1-ANGLEEPSILON || l > 1+ANGLEEPSILON)
					continue;
				plane.dist = DotProduct (planeorg, plane.normal);				
				TestAddPlane (&plane);
			}
	}
	

}		
Esempio n. 4
0
File: brush.c Progetto: kellyrm/Q1
/*
============
AddHullEdge

Creates all of the hull planes around the given edge, if not done allready
=============
*/
void AddHullEdge (vec3_t p1, vec3_t p2, int hullnum)
{
	int	pt1, pt2;
	int	i;
	int	a, b, c, d, e;
	vec3_t	edgevec, planeorg, planevec;
	plane_t	plane;
	vec_t	l;

	pt1 = AddHullPoint (p1, hullnum);
	pt2 = AddHullPoint (p2, hullnum);

	for (i=0 ; i<num_hull_edges ; i++)
		if ( (hull_edges[i][0] == pt1 && hull_edges[i][1] == pt2)
		|| (hull_edges[i][0] == pt2 && hull_edges[i][1] == pt1) )
			return;	// allread added

	if (num_hull_edges == MAX_HULL_EDGES)
		Message (MSGERR, "MAX_HULL_EDGES (%d) exceeded", MAX_HULL_EDGES);

	hull_edges[i][0] = pt1;
	hull_edges[i][1] = pt2;
	num_hull_edges++;

	VectorSubtract (p1, p2, edgevec);
	VectorNormalize (edgevec);

	for (a=0 ; a<3 ; a++)
	{
		VectorCopy (vec3_origin, planevec);
		planevec[a] = 1;

		CrossProduct (planevec, edgevec, plane.normal);
		l = VectorLength (plane.normal);
			
		if (options.OldExpand)
		{
			if (l < 1-ANGLEEPSILON || l > 1+ANGLEEPSILON)
				continue;
		}
		else
		{
			// If this edge is almost parallel to the hull edge, skip it
			if (l < ANGLEEPSILON)
				continue;
			
			VectorScale (plane.normal, 1 / l, plane.normal);
		}

		b = (a+1)%3;
		c = (a+2)%3;
		for (d=0 ; d<=1 ; d++)
			for (e=0 ; e<=1 ; e++)
			{
				VectorCopy (p1, planeorg);
				planeorg[b] += ExpandSize (hullnum, d, b);
				planeorg[c] += ExpandSize (hullnum, e, c);

				plane.dist = DotProduct (planeorg, plane.normal);
				TestAddPlane (&plane);
			}
	}


}