Пример #1
0
static wedge_t *FindEdge(const vec3_t p1, const vec3_t p2, vec_t* t1, vec_t* t2)
{
    vec3_t          origin;
    vec3_t          dir;
    wedge_t*        w;
    vec_t           temp;
    int             h;

    VectorSubtract(p2, p1, dir);
    if (!CanonicalVector(dir))
    {
#if _DEBUG
        Warning("CanonicalVector: degenerate @ (%4.3f %4.3f %4.3f )\n", p1[0], p1[1], p1[2]);
#endif
    }

    *t1 = DotProduct(p1, dir);
    *t2 = DotProduct(p2, dir);

    VectorMA(p1, -*t1, dir, origin);

    if (*t1 > *t2)
    {
        temp = *t1;
        *t1 = *t2;
        *t2 = temp;
    }

    h = HashVec(origin);

    for (w = wedge_hash[h]; w; w = w->next)
    {
#ifdef HLBSP_TJUNC_PRECISION_FIX
		if (fabs (w->origin[0] - origin[0]) > EQUAL_EPSILON ||
			fabs (w->origin[1] - origin[1]) > EQUAL_EPSILON ||
			fabs (w->origin[2] - origin[2]) > EQUAL_EPSILON )
		{
			continue;
		}
		if (fabs (w->dir[0] - dir[0]) > NORMAL_EPSILON ||
			fabs (w->dir[1] - dir[1]) > NORMAL_EPSILON ||
			fabs (w->dir[2] - dir[2]) > NORMAL_EPSILON )
		{
			continue;
		}
#else
        temp = w->origin[0] - origin[0];
        if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON)
        {
            continue;
        }
        temp = w->origin[1] - origin[1];
        if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON)
        {
            continue;
        }
        temp = w->origin[2] - origin[2];
        if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON)
        {
            continue;
        }

        temp = w->dir[0] - dir[0];
        if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON)
        {
            continue;
        }
        temp = w->dir[1] - dir[1];
        if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON)
        {
            continue;
        }
        temp = w->dir[2] - dir[2];
        if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON)
        {
            continue;
        }
#endif

        return w;
    }

    hlassume(numwedges < MAX_WEDGES, assume_MAX_WEDGES);
    w = &wedges[numwedges];
    numwedges++;

    w->next = wedge_hash[h];
    wedge_hash[h] = w;

    VectorCopy(origin, w->origin);
    VectorCopy(dir, w->dir);
    w->head.next = w->head.prev = &w->head;
    w->head.t = 99999;
    return w;
}
Пример #2
0
static wedge_t *
FindEdge(vec3_t p1, vec3_t p2, vec_t *t1, vec_t *t2)
{
    vec3_t origin;
    vec3_t dir;
    wedge_t *w;
    vec_t temp;
    int h;

    VectorSubtract(p2, p1, dir);
    CanonicalVector(dir);

    *t1 = DotProduct(p1, dir);
    *t2 = DotProduct(p2, dir);

    VectorMA(p1, -*t1, dir, origin);

    if (*t1 > *t2) {
	temp = *t1;
	*t1 = *t2;
	*t2 = temp;
    }

    h = HashVec(origin);

    for (w = wedge_hash[h]; w; w = w->next) {
	temp = w->origin[0] - origin[0];
	if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON)
	    continue;
	temp = w->origin[1] - origin[1];
	if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON)
	    continue;
	temp = w->origin[2] - origin[2];
	if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON)
	    continue;

	temp = w->dir[0] - dir[0];
	if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON)
	    continue;
	temp = w->dir[1] - dir[1];
	if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON)
	    continue;
	temp = w->dir[2] - dir[2];
	if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON)
	    continue;

	return w;
    }

    if (numwedges >= cWEdges)
	Error(errLowWedgeCount);
    w = pWEdges + numwedges;
    numwedges++;

    w->next = wedge_hash[h];
    wedge_hash[h] = w;

    VectorCopy(origin, w->origin);
    VectorCopy(dir, w->dir);
    w->head.next = w->head.prev = &w->head;
    w->head.t = VECT_MAX;
    return w;
}
Пример #3
0
wedge_t	*FindEdge (vec3_t p1, vec3_t p2, vec_t *t1, vec_t *t2)
{
	vec3_t	origin;
	vec3_t	dir;
	wedge_t	*w;
	vec_t	temp;
	int		h;

	VectorSubtract (p2, p1, dir);

	// ignore degenerate edges
	if (!CanonicalVector (dir))
	{
		c_degenerateEdges++;
		return NULL;
	}

	*t1 = DotProduct (p1, dir);
	*t2 = DotProduct (p2, dir);

	VectorMA (p1, -*t1, dir, origin);

	if (*t1 > *t2)
	{
		temp = *t1;
		*t1 = *t2;
		*t2 = temp;
	}

	h = HashVec (origin);

	for (w = wedge_hash[h] ; w ; w=w->next)
	{
		temp = w->origin[0] - origin[0];
		if (temp < -pMath_EPSILON_EQUAL || temp > pMath_EPSILON_EQUAL)
			continue;
		temp = w->origin[1] - origin[1];
		if (temp < -pMath_EPSILON_EQUAL || temp > pMath_EPSILON_EQUAL)
			continue;
		temp = w->origin[2] - origin[2];
		if (temp < -pMath_EPSILON_EQUAL || temp > pMath_EPSILON_EQUAL)
			continue;

		temp = w->dir[0] - dir[0];
		if (temp < -pMath_EPSILON_EQUAL || temp > pMath_EPSILON_EQUAL)
			continue;
		temp = w->dir[1] - dir[1];
		if (temp < -pMath_EPSILON_EQUAL || temp > pMath_EPSILON_EQUAL)
			continue;
		temp = w->dir[2] - dir[2];
		if (temp < -pMath_EPSILON_EQUAL || temp > pMath_EPSILON_EQUAL)
			continue;

		return w;
	}

	if (numwedges == MAX_WEDGES)
		Error ("FindEdge: numwedges == MAX_WEDGES");
	w = &wedges[numwedges];
	numwedges++;

	w->next = wedge_hash[h];
	wedge_hash[h] = w;

	VectorCopy (origin, w->origin);
	VectorCopy (dir, w->dir);
	w->head.next = w->head.prev = &w->head;
	w->head.t = 99999;
	return w;
}