2002-09-19 18:51:19 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
See file, 'COPYING', for details.
|
2002-09-19 16:58:48 +00:00
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "QF/sys.h"
|
|
|
|
|
|
|
|
#include "compat.h"
|
2010-08-18 08:52:13 +00:00
|
|
|
|
|
|
|
#include "brush.h"
|
2002-09-19 16:58:48 +00:00
|
|
|
#include "bsp5.h"
|
2010-08-18 08:52:13 +00:00
|
|
|
#include "draw.h"
|
2003-09-17 21:03:52 +00:00
|
|
|
#include "options.h"
|
2010-08-29 03:43:07 +00:00
|
|
|
#include "surfaces.h"
|
2010-08-18 08:52:13 +00:00
|
|
|
#include "winding.h"
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2010-09-01 01:06:54 +00:00
|
|
|
/** \addtogroup qfbsp_brush
|
|
|
|
*/
|
|
|
|
//@{
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
int numbrushplanes;
|
|
|
|
plane_t planes[MAX_MAP_PLANES];
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
int numbrushfaces;
|
2003-09-03 22:00:08 +00:00
|
|
|
mface_t faces[MAX_FACES]; // beveled clipping hull can generate many extra
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2003-09-03 22:00:08 +00:00
|
|
|
static entity_t *CurrentEntity;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2010-08-29 03:43:07 +00:00
|
|
|
brush_t *
|
|
|
|
AllocBrush (void)
|
|
|
|
{
|
|
|
|
brush_t *b;
|
|
|
|
|
|
|
|
b = malloc (sizeof (brush_t));
|
|
|
|
memset (b, 0, sizeof (brush_t));
|
|
|
|
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
2010-10-12 10:33:27 +00:00
|
|
|
/** Check the face for validity.
|
|
|
|
|
|
|
|
\param f The face to check.
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2010-10-12 10:33:27 +00:00
|
|
|
\note Does not catch 0 area polygons.
|
2002-09-19 16:58:48 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2010-09-02 04:01:45 +00:00
|
|
|
CheckFace (const face_t *f)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 18:51:19 +00:00
|
|
|
int i, j;
|
|
|
|
vec_t *p1, *p2;
|
|
|
|
vec_t d, edgedist;
|
|
|
|
vec3_t dir, edgenormal, facenormal;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2003-09-08 03:00:53 +00:00
|
|
|
if (f->points->numpoints < 3)
|
|
|
|
Sys_Error ("CheckFace: %i points", f->points->numpoints);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
VectorCopy (planes[f->planenum].normal, facenormal);
|
2002-09-19 18:51:19 +00:00
|
|
|
if (f->planeside)
|
2003-09-03 22:00:08 +00:00
|
|
|
VectorNegate (facenormal, facenormal);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2003-09-08 03:00:53 +00:00
|
|
|
for (i = 0; i < f->points->numpoints; i++) {
|
|
|
|
p1 = f->points->points[i];
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
for (j = 0; j < 3; j++)
|
2002-09-19 16:58:48 +00:00
|
|
|
if (p1[j] > BOGUS_RANGE || p1[j] < -BOGUS_RANGE)
|
2002-09-19 17:14:23 +00:00
|
|
|
Sys_Error ("CheckFace: BUGUS_RANGE: %f", p1[j]);
|
|
|
|
|
2003-09-08 03:00:53 +00:00
|
|
|
j = i + 1 == f->points->numpoints ? 0 : i + 1;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
// check the point is on the face plane
|
2010-09-02 04:01:45 +00:00
|
|
|
d = PlaneDiff (p1, &planes[f->planenum]);
|
2002-09-19 18:51:19 +00:00
|
|
|
|
2003-09-17 21:03:52 +00:00
|
|
|
// point off plane autofix
|
2002-09-19 16:58:48 +00:00
|
|
|
if (d < -ON_EPSILON || d > ON_EPSILON)
|
2003-09-17 21:03:52 +00:00
|
|
|
if (options.verbosity > 1)
|
|
|
|
printf ("CheckFace: point off plane: %g @ (%g %g %g)\n", d,
|
|
|
|
p1[0], p1[1], p1[2]);
|
2003-09-03 22:00:08 +00:00
|
|
|
VectorMultSub (p1, d, planes[f->planenum].normal, p1);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
// check the edge isn't degenerate
|
2003-09-08 03:00:53 +00:00
|
|
|
p2 = f->points->points[j];
|
2002-09-19 16:58:48 +00:00
|
|
|
VectorSubtract (p2, p1, dir);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
if (VectorLength (dir) < ON_EPSILON)
|
|
|
|
Sys_Error ("CheckFace: degenerate edge");
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
CrossProduct (facenormal, dir, edgenormal);
|
2002-09-25 21:35:49 +00:00
|
|
|
_VectorNormalize (edgenormal);
|
2002-09-19 16:58:48 +00:00
|
|
|
edgedist = DotProduct (p1, edgenormal);
|
|
|
|
edgedist += ON_EPSILON;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
// all other points must be on front side
|
2003-09-08 03:00:53 +00:00
|
|
|
for (j = 0; j < f->points->numpoints; j++) {
|
2002-09-19 16:58:48 +00:00
|
|
|
if (j == i)
|
|
|
|
continue;
|
2003-09-08 03:00:53 +00:00
|
|
|
d = DotProduct (f->points->points[j], edgenormal);
|
2002-09-19 16:58:48 +00:00
|
|
|
if (d > edgedist)
|
|
|
|
Sys_Error ("CheckFace: non-convex");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-12 10:33:27 +00:00
|
|
|
/** Initialize the bounding box of the brush set.
|
|
|
|
|
|
|
|
\param bs The brush set of which to initialize the bounding box.
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-09-19 18:51:19 +00:00
|
|
|
ClearBounds (brushset_t *bs)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 18:51:19 +00:00
|
|
|
int i, j;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2010-10-12 10:33:27 +00:00
|
|
|
for (j = 0; j < NUM_HULLS; j++) {
|
2002-09-19 17:14:23 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
2003-09-03 22:00:08 +00:00
|
|
|
bs->mins[i] = BOGUS_RANGE;
|
|
|
|
bs->maxs[i] = -BOGUS_RANGE;
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2010-10-12 10:33:27 +00:00
|
|
|
}
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
2010-10-12 10:33:27 +00:00
|
|
|
/** Grow the bounding box of the brush set to include the vector.
|
|
|
|
|
|
|
|
\param bs The brush set of which to grown the bounding box.
|
|
|
|
\param v The vector to be included in the bounding box.
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2010-09-02 04:01:45 +00:00
|
|
|
AddToBounds (brushset_t *bs, const vec3_t v)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 18:51:19 +00:00
|
|
|
int i;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
2002-09-19 16:58:48 +00:00
|
|
|
if (v[i] < bs->mins[i])
|
|
|
|
bs->mins[i] = v[i];
|
|
|
|
if (v[i] > bs->maxs[i])
|
|
|
|
bs->maxs[i] = v[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
int
|
2010-08-27 12:38:09 +00:00
|
|
|
PlaneTypeForNormal (const vec3_t normal)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 18:51:19 +00:00
|
|
|
float ax, ay, az;
|
2010-08-27 12:41:04 +00:00
|
|
|
int type;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// NOTE: should these have an epsilon around 1.0?
|
2002-09-19 16:58:48 +00:00
|
|
|
if (normal[0] == 1.0)
|
|
|
|
return PLANE_X;
|
|
|
|
if (normal[1] == 1.0)
|
|
|
|
return PLANE_Y;
|
|
|
|
if (normal[2] == 1.0)
|
|
|
|
return PLANE_Z;
|
2002-09-19 17:14:23 +00:00
|
|
|
if (normal[0] == -1.0 || normal[1] == -1.0 || normal[2] == -1.0)
|
2010-12-10 03:42:37 +00:00
|
|
|
Sys_Error ("PlaneTypeForNormal: not a canonical vector (%g %g %g)",
|
|
|
|
normal[0], normal[1], normal[2]);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
ax = fabs(normal[0]);
|
|
|
|
ay = fabs(normal[1]);
|
|
|
|
az = fabs(normal[2]);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2010-12-10 05:12:15 +00:00
|
|
|
if (az >= ax && az >= ay)
|
|
|
|
type = PLANE_ANYZ;
|
2010-08-27 12:41:04 +00:00
|
|
|
else if (ay >= ax && ay >= az)
|
|
|
|
type = PLANE_ANYY;
|
|
|
|
else
|
2010-12-10 05:12:15 +00:00
|
|
|
type = PLANE_ANYX;
|
2010-08-27 12:41:04 +00:00
|
|
|
if (normal[type - PLANE_ANYX] < 0)
|
2010-12-10 03:42:37 +00:00
|
|
|
Sys_Error ("PlaneTypeForNormal: not a canonical vector (%g %g %g) %d",
|
|
|
|
normal[0], normal[1], normal[2], type);
|
2010-08-27 12:41:04 +00:00
|
|
|
return type;
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define DISTEPSILON 0.01
|
|
|
|
#define ANGLEEPSILON 0.00001
|
|
|
|
|
2010-12-10 09:13:48 +00:00
|
|
|
int
|
2002-09-19 17:14:23 +00:00
|
|
|
NormalizePlane (plane_t *dp)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2010-12-10 09:13:48 +00:00
|
|
|
vec_t ax, ay, az;
|
|
|
|
int flip = 0;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2010-08-27 12:46:06 +00:00
|
|
|
// Make axis aligned planes point to +inf.
|
2002-09-19 17:14:23 +00:00
|
|
|
if (dp->normal[0] == -1.0) {
|
2002-09-19 16:58:48 +00:00
|
|
|
dp->normal[0] = 1.0;
|
|
|
|
dp->dist = -dp->dist;
|
2010-12-10 09:13:48 +00:00
|
|
|
flip = 1;
|
2003-09-03 22:00:08 +00:00
|
|
|
} else if (dp->normal[1] == -1.0) {
|
2002-09-19 16:58:48 +00:00
|
|
|
dp->normal[1] = 1.0;
|
|
|
|
dp->dist = -dp->dist;
|
2010-12-10 09:13:48 +00:00
|
|
|
flip = 1;
|
2003-09-03 22:00:08 +00:00
|
|
|
} else if (dp->normal[2] == -1.0) {
|
2002-09-19 16:58:48 +00:00
|
|
|
dp->normal[2] = 1.0;
|
|
|
|
dp->dist = -dp->dist;
|
2010-12-10 09:13:48 +00:00
|
|
|
flip = 1;
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
2010-08-27 12:46:06 +00:00
|
|
|
// For axis aligned planes, set the plane type and ensure the normal
|
|
|
|
// vector is mathematically correct.
|
2002-09-19 17:14:23 +00:00
|
|
|
if (dp->normal[0] == 1.0) {
|
2002-09-19 16:58:48 +00:00
|
|
|
dp->type = PLANE_X;
|
2003-09-17 20:26:57 +00:00
|
|
|
dp->normal[1] = dp->normal[2] = 0.0;
|
2010-12-10 09:13:48 +00:00
|
|
|
return flip;
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
if (dp->normal[1] == 1.0) {
|
2002-09-19 16:58:48 +00:00
|
|
|
dp->type = PLANE_Y;
|
2003-09-17 20:26:57 +00:00
|
|
|
dp->normal[0] = dp->normal[2] = 0.0;
|
2010-12-10 09:13:48 +00:00
|
|
|
return flip;
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
if (dp->normal[2] == 1.0) {
|
2002-09-19 16:58:48 +00:00
|
|
|
dp->type = PLANE_Z;
|
2003-09-17 20:26:57 +00:00
|
|
|
dp->normal[0] = dp->normal[1] = 0.0;
|
2010-12-10 09:13:48 +00:00
|
|
|
return flip;
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
2010-08-27 12:46:06 +00:00
|
|
|
// Find out with which axis the plane is most aligned.
|
2002-09-19 17:14:23 +00:00
|
|
|
ax = fabs (dp->normal[0]);
|
|
|
|
ay = fabs (dp->normal[1]);
|
|
|
|
az = fabs (dp->normal[2]);
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2010-12-10 05:12:15 +00:00
|
|
|
if (az >= ax && az >= ay)
|
|
|
|
dp->type = PLANE_ANYZ;
|
2002-09-19 16:58:48 +00:00
|
|
|
else if (ay >= ax && ay >= az)
|
|
|
|
dp->type = PLANE_ANYY;
|
|
|
|
else
|
2010-12-10 05:12:15 +00:00
|
|
|
dp->type = PLANE_ANYX;
|
2010-08-27 12:46:06 +00:00
|
|
|
// Make the plane's normal point towards +inf along its primary axis.
|
2002-09-19 17:14:23 +00:00
|
|
|
if (dp->normal[dp->type - PLANE_ANYX] < 0) {
|
2003-09-03 22:00:08 +00:00
|
|
|
VectorNegate (dp->normal, dp->normal);
|
2002-09-19 16:58:48 +00:00
|
|
|
dp->dist = -dp->dist;
|
2010-12-10 09:13:48 +00:00
|
|
|
flip = 1;
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2010-12-10 09:13:48 +00:00
|
|
|
return flip;
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
int
|
2010-09-02 04:01:45 +00:00
|
|
|
FindPlane (const plane_t *dplane, int *side)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 18:51:19 +00:00
|
|
|
int i;
|
|
|
|
plane_t *dp, pl;
|
|
|
|
vec_t dot;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
dot = VectorLength(dplane->normal);
|
2002-09-19 16:58:48 +00:00
|
|
|
if (dot < 1.0 - ANGLEEPSILON || dot > 1.0 + ANGLEEPSILON)
|
|
|
|
Sys_Error ("FindPlane: normalization error");
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
pl = *dplane;
|
|
|
|
NormalizePlane (&pl);
|
2002-09-19 17:14:23 +00:00
|
|
|
if (DotProduct (pl.normal, dplane->normal) > 0)
|
2002-09-19 16:58:48 +00:00
|
|
|
*side = 0;
|
|
|
|
else
|
|
|
|
*side = 1;
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
dp = planes;
|
|
|
|
for (i = 0; i < numbrushplanes; i++, dp++) {
|
2003-08-27 01:12:03 +00:00
|
|
|
vec3_t t;
|
|
|
|
VectorSubtract (dp->normal, pl.normal, t);
|
2002-09-19 16:58:48 +00:00
|
|
|
dot = DotProduct (dp->normal, pl.normal);
|
2010-08-27 13:12:13 +00:00
|
|
|
if (dot > 1.0 - ANGLEEPSILON
|
2002-09-19 18:51:19 +00:00
|
|
|
&& fabs(dp->dist - pl.dist) < DISTEPSILON) { // regular match
|
2002-09-19 17:14:23 +00:00
|
|
|
return i;
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numbrushplanes == MAX_MAP_PLANES)
|
|
|
|
Sys_Error ("numbrushplanes == MAX_MAP_PLANES");
|
|
|
|
|
|
|
|
planes[numbrushplanes] = pl;
|
|
|
|
|
|
|
|
numbrushplanes++;
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
return numbrushplanes - 1;
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-09-23 16:27:17 +00:00
|
|
|
Turn brushes into groups of faces.
|
2002-09-19 16:58:48 +00:00
|
|
|
*/
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
vec3_t brush_mins, brush_maxs;
|
|
|
|
face_t *brush_faces;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2010-10-12 10:33:27 +00:00
|
|
|
/** Find the entity with the matching target name.
|
|
|
|
|
|
|
|
\param targetname The target name for which to search.
|
|
|
|
\return The matching entity or NULL if not found.
|
|
|
|
*/
|
2003-09-03 22:00:08 +00:00
|
|
|
static entity_t *
|
|
|
|
FindTargetEntity (const char *targetname)
|
|
|
|
{
|
|
|
|
int entnum;
|
|
|
|
|
|
|
|
for (entnum = 0; entnum < num_entities; entnum++)
|
|
|
|
if (!strcmp (targetname,
|
|
|
|
ValueForKey (&entities[entnum], "targetname")))
|
|
|
|
return &entities[entnum];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
#define ZERO_EPSILON 0.001
|
2010-10-12 10:33:27 +00:00
|
|
|
|
|
|
|
/** Create the faces of the active brush.
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-09-19 17:14:23 +00:00
|
|
|
CreateBrushFaces (void)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 18:51:19 +00:00
|
|
|
face_t *f;
|
2003-09-03 22:00:08 +00:00
|
|
|
int i, j, k, rotate;
|
2002-09-19 18:51:19 +00:00
|
|
|
mface_t *mf;
|
|
|
|
plane_t plane;
|
2002-09-19 17:14:23 +00:00
|
|
|
vec_t r;
|
|
|
|
winding_t *w;
|
2003-09-03 22:00:08 +00:00
|
|
|
vec3_t offset, point;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2003-09-03 22:00:08 +00:00
|
|
|
offset[0] = offset[1] = offset[2] = 0;
|
|
|
|
brush_mins[0] = brush_mins[1] = brush_mins[2] = BOGUS_RANGE;
|
|
|
|
brush_maxs[0] = brush_maxs[1] = brush_maxs[2] = -BOGUS_RANGE;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
brush_faces = NULL;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2003-09-03 22:00:08 +00:00
|
|
|
rotate = !strncmp (ValueForKey (CurrentEntity, "classname"), "rotate_", 7);
|
|
|
|
if (rotate) {
|
|
|
|
entity_t *FoundEntity;
|
|
|
|
const char *searchstring;
|
|
|
|
char text[20];
|
|
|
|
|
|
|
|
searchstring = ValueForKey (CurrentEntity, "target");
|
|
|
|
FoundEntity = FindTargetEntity (searchstring);
|
|
|
|
if (FoundEntity)
|
|
|
|
GetVectorForKey (FoundEntity, "origin", offset);
|
|
|
|
|
|
|
|
snprintf (text, sizeof (text), "%g %g %g",
|
|
|
|
offset[0], offset[1], offset[2]);
|
|
|
|
SetKeyValue (CurrentEntity, "origin", text);
|
|
|
|
}
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
for (i = 0; i < numbrushfaces; i++) {
|
2002-09-19 16:58:48 +00:00
|
|
|
mf = &faces[i];
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
w = BaseWindingForPlane (&mf->plane);
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
for (j = 0; j < numbrushfaces && w; j++) {
|
2002-09-19 16:58:48 +00:00
|
|
|
if (j == i)
|
|
|
|
continue;
|
2002-09-19 17:14:23 +00:00
|
|
|
// flip the plane, because we want to keep the back side
|
2003-09-03 22:00:08 +00:00
|
|
|
VectorNegate (faces[j].plane.normal, plane.normal);
|
2002-09-19 16:58:48 +00:00
|
|
|
plane.dist = -faces[j].plane.dist;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2003-09-03 22:00:08 +00:00
|
|
|
// keepon was false. avoid clipping away windings on plane?
|
|
|
|
w = ClipWinding (w, &plane, true);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
if (!w)
|
2003-09-08 03:00:53 +00:00
|
|
|
continue; // overconstrained plane
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
// this face is a keeper
|
2002-09-19 16:58:48 +00:00
|
|
|
f = AllocFace ();
|
2003-09-08 03:00:53 +00:00
|
|
|
f->points = w;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
for (j = 0; j < w->numpoints; j++) {
|
2003-09-08 03:00:53 +00:00
|
|
|
vec_t *v = f->points->points[j];
|
|
|
|
VectorSubtract (v, offset, v);
|
2002-09-19 17:14:23 +00:00
|
|
|
for (k = 0; k < 3; k++) {
|
2003-09-08 03:00:53 +00:00
|
|
|
r = RINT (v[k]);
|
|
|
|
if (fabs (v[k] - r) < ZERO_EPSILON)
|
|
|
|
v[k] = r;
|
|
|
|
|
|
|
|
if (v[k] < brush_mins[k])
|
|
|
|
brush_mins[k] = v[k];
|
|
|
|
if (v[k] > brush_maxs[k])
|
|
|
|
brush_maxs[k] = v[k];
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2003-09-03 22:00:08 +00:00
|
|
|
VectorCopy (mf->plane.normal, plane.normal);
|
|
|
|
VectorScale (mf->plane.normal, mf->plane.dist, point);
|
|
|
|
VectorSubtract (point, offset, point);
|
|
|
|
plane.dist = DotProduct (plane.normal, point);
|
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
f->texturenum = mf->texinfo;
|
2003-09-03 22:00:08 +00:00
|
|
|
f->planenum = FindPlane (&plane, &f->planeside);
|
2002-09-19 16:58:48 +00:00
|
|
|
f->next = brush_faces;
|
|
|
|
brush_faces = f;
|
|
|
|
CheckFace (f);
|
2002-09-19 17:14:23 +00:00
|
|
|
}
|
2003-09-03 22:00:08 +00:00
|
|
|
|
|
|
|
// Rotatable objects have to have a bounding box big enough
|
|
|
|
// to account for all its rotations.
|
|
|
|
if (rotate) {
|
|
|
|
vec_t delta, min, max;
|
|
|
|
|
|
|
|
min = brush_mins[0];
|
|
|
|
if (min > brush_mins[1])
|
|
|
|
min = brush_mins[1];
|
|
|
|
if (min > brush_mins[2])
|
|
|
|
min = brush_mins[2];
|
|
|
|
|
|
|
|
max = brush_maxs[0];
|
2010-08-27 12:43:53 +00:00
|
|
|
if (max < brush_maxs[1])
|
2003-09-03 22:00:08 +00:00
|
|
|
max = brush_maxs[1];
|
2010-08-27 12:43:53 +00:00
|
|
|
if (max < brush_maxs[2])
|
2003-09-03 22:00:08 +00:00
|
|
|
max = brush_maxs[2];
|
|
|
|
|
|
|
|
delta = fabs(max);
|
|
|
|
if (fabs(min) > delta)
|
|
|
|
delta = fabs(min);
|
|
|
|
|
|
|
|
for (k = 0; k < 3; k++) {
|
|
|
|
brush_mins[k] = -delta;
|
|
|
|
brush_maxs[k] = delta;
|
|
|
|
}
|
|
|
|
}
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-09-23 16:27:17 +00:00
|
|
|
BEVELED CLIPPING HULL GENERATION
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
This is done by brute force, and could easily get a lot faster if anyone
|
|
|
|
cares.
|
2002-09-19 16:58:48 +00:00
|
|
|
*/
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
vec3_t hull_size[3][2] = {
|
|
|
|
{{0, 0, 0}, {0, 0, 0}},
|
|
|
|
{{-16, -16, -32}, {16, 16, 24}},
|
|
|
|
{{-32, -32, -64}, {32, 32, 24}}
|
2002-09-19 16:58:48 +00:00
|
|
|
};
|
|
|
|
|
2006-11-10 13:51:02 +00:00
|
|
|
#define MAX_HULL_POINTS 256
|
|
|
|
#define MAX_HULL_EDGES MAX_HULL_POINTS * 2
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
int num_hull_points;
|
|
|
|
vec3_t hull_points[MAX_HULL_POINTS];
|
|
|
|
vec3_t hull_corners[MAX_HULL_POINTS * 8];
|
|
|
|
int num_hull_edges;
|
|
|
|
int hull_edges[MAX_HULL_EDGES][2];
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2010-09-02 04:01:45 +00:00
|
|
|
AddBrushPlane (const plane_t *plane)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 18:51:19 +00:00
|
|
|
float l;
|
2002-09-19 17:14:23 +00:00
|
|
|
int i;
|
|
|
|
plane_t *pl;
|
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
if (numbrushfaces == MAX_FACES)
|
|
|
|
Sys_Error ("AddBrushPlane: numbrushfaces == MAX_FACES");
|
|
|
|
l = VectorLength (plane->normal);
|
|
|
|
if (l < 0.999 || l > 1.001)
|
|
|
|
Sys_Error ("AddBrushPlane: bad normal");
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
for (i = 0; i < numbrushfaces; i++) {
|
2002-09-19 16:58:48 +00:00
|
|
|
pl = &faces[i].plane;
|
2002-09-20 17:02:53 +00:00
|
|
|
if (_VectorCompare (pl->normal, plane->normal)
|
2002-09-19 17:14:23 +00:00
|
|
|
&& fabs (pl->dist - plane->dist) < ON_EPSILON)
|
2002-09-19 16:58:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
faces[i].plane = *plane;
|
|
|
|
faces[i].texinfo = faces[0].texinfo;
|
|
|
|
numbrushfaces++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-09-23 16:27:17 +00:00
|
|
|
TestAddPlane
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
Adds the given plane to the brush description if all of the original brush
|
|
|
|
vertexes can be put on the front side
|
2002-09-19 16:58:48 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2010-09-02 04:01:45 +00:00
|
|
|
TestAddPlane (const plane_t *plane)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 18:51:19 +00:00
|
|
|
int c, i;
|
|
|
|
int counts[3];
|
|
|
|
plane_t flip;
|
|
|
|
plane_t *pl;
|
2002-09-19 17:14:23 +00:00
|
|
|
vec_t d;
|
|
|
|
vec_t *corner;
|
|
|
|
vec3_t inv;
|
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// see if the plane has allready been added
|
2002-09-19 17:14:23 +00:00
|
|
|
for (i = 0; i < numbrushfaces; i++) {
|
2002-09-19 16:58:48 +00:00
|
|
|
pl = &faces[i].plane;
|
2002-09-20 17:02:53 +00:00
|
|
|
if (_VectorCompare (plane->normal, pl->normal)
|
2002-09-19 17:14:23 +00:00
|
|
|
&& fabs (plane->dist - pl->dist) < ON_EPSILON)
|
2002-09-19 16:58:48 +00:00
|
|
|
return;
|
2003-09-03 22:00:08 +00:00
|
|
|
VectorNegate (plane->normal, inv);
|
2002-09-20 17:02:53 +00:00
|
|
|
if (_VectorCompare (inv, pl->normal)
|
2002-09-19 17:14:23 +00:00
|
|
|
&& fabs (plane->dist + pl->dist) < ON_EPSILON) return;
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// check all the corner points
|
2002-09-19 16:58:48 +00:00
|
|
|
counts[0] = counts[1] = counts[2] = 0;
|
|
|
|
c = num_hull_points * 8;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
corner = hull_corners[0];
|
2002-09-19 17:14:23 +00:00
|
|
|
for (i = 0; i < c; i++, corner += 3) {
|
2002-09-19 16:58:48 +00:00
|
|
|
d = DotProduct (corner, plane->normal) - plane->dist;
|
2002-09-19 17:14:23 +00:00
|
|
|
if (d < -ON_EPSILON) {
|
2002-09-19 16:58:48 +00:00
|
|
|
if (counts[0])
|
|
|
|
return;
|
|
|
|
counts[1]++;
|
2002-09-19 17:14:23 +00:00
|
|
|
} else if (d > ON_EPSILON) {
|
2002-09-19 16:58:48 +00:00
|
|
|
if (counts[1])
|
|
|
|
return;
|
|
|
|
counts[0]++;
|
2002-09-19 17:14:23 +00:00
|
|
|
} else
|
2002-09-19 16:58:48 +00:00
|
|
|
counts[2]++;
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// the plane is a seperator
|
2002-09-19 17:14:23 +00:00
|
|
|
if (counts[0]) {
|
2003-09-03 22:00:08 +00:00
|
|
|
VectorNegate (plane->normal, flip.normal);
|
2002-09-19 16:58:48 +00:00
|
|
|
flip.dist = -plane->dist;
|
|
|
|
plane = &flip;
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
AddBrushPlane (plane);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-09-23 16:27:17 +00:00
|
|
|
AddHullPoint
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
Doesn't add if duplicated
|
2002-09-19 16:58:48 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static int
|
2010-09-02 04:01:45 +00:00
|
|
|
AddHullPoint (const vec3_t p, int hullnum)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 18:51:19 +00:00
|
|
|
int i, x, y, z;
|
|
|
|
vec_t *c;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
for (i = 0; i < num_hull_points; i++)
|
2002-09-20 17:02:53 +00:00
|
|
|
if (_VectorCompare (p, hull_points[i]))
|
2002-09-19 16:58:48 +00:00
|
|
|
return i;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
VectorCopy (p, hull_points[num_hull_points]);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
c = hull_corners[i * 8];
|
|
|
|
|
|
|
|
for (x = 0; x < 2; x++)
|
|
|
|
for (y = 0; y < 2; y++)
|
|
|
|
for (z = 0; z < 2; z++) {
|
2002-09-19 16:58:48 +00:00
|
|
|
c[0] = p[0] + hull_size[hullnum][x][0];
|
|
|
|
c[1] = p[1] + hull_size[hullnum][y][1];
|
|
|
|
c[2] = p[2] + hull_size[hullnum][z][2];
|
|
|
|
c += 3;
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
if (num_hull_points == MAX_HULL_POINTS)
|
|
|
|
Sys_Error ("MAX_HULL_POINTS");
|
|
|
|
|
|
|
|
num_hull_points++;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-09-23 16:27:17 +00:00
|
|
|
AddHullEdge
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
Creates all of the hull planes around the given edge, if not done already
|
2002-09-19 16:58:48 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2010-09-02 04:01:45 +00:00
|
|
|
AddHullEdge (const vec3_t p1, const vec3_t p2, int hullnum)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 18:51:19 +00:00
|
|
|
int pt1, pt2, a, b, c, d, e, i;
|
2002-09-19 17:14:23 +00:00
|
|
|
plane_t plane;
|
2002-09-19 18:51:19 +00:00
|
|
|
vec3_t edgevec, planeorg, planevec;
|
2002-09-19 17:14:23 +00:00
|
|
|
vec_t l;
|
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
pt1 = AddHullPoint (p1, hullnum);
|
|
|
|
pt2 = AddHullPoint (p2, hullnum);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
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))
|
2002-09-19 18:51:19 +00:00
|
|
|
return; // allready added
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
if (num_hull_edges == MAX_HULL_EDGES)
|
|
|
|
Sys_Error ("MAX_HULL_EDGES");
|
|
|
|
|
|
|
|
hull_edges[i][0] = pt1;
|
|
|
|
hull_edges[i][1] = pt2;
|
|
|
|
num_hull_edges++;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
VectorSubtract (p1, p2, edgevec);
|
2002-09-25 21:35:49 +00:00
|
|
|
_VectorNormalize (edgevec);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
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++) {
|
2002-09-19 16:58:48 +00:00
|
|
|
VectorCopy (p1, planeorg);
|
|
|
|
planeorg[b] += hull_size[hullnum][d][b];
|
|
|
|
planeorg[c] += hull_size[hullnum][e][c];
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2003-09-03 22:00:08 +00:00
|
|
|
VectorZero (planevec);
|
2002-09-19 16:58:48 +00:00
|
|
|
planevec[a] = 1;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
CrossProduct (planevec, edgevec, plane.normal);
|
|
|
|
l = VectorLength (plane.normal);
|
2002-09-19 17:14:23 +00:00
|
|
|
if (l < 1 - ANGLEEPSILON || l > 1 + ANGLEEPSILON)
|
2002-09-19 16:58:48 +00:00
|
|
|
continue;
|
2002-09-19 17:14:23 +00:00
|
|
|
plane.dist = DotProduct (planeorg, plane.normal);
|
2002-09-19 16:58:48 +00:00
|
|
|
TestAddPlane (&plane);
|
|
|
|
}
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
}
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-09-19 17:14:23 +00:00
|
|
|
ExpandBrush (int hullnum)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
face_t *f;
|
2002-09-19 18:51:19 +00:00
|
|
|
int i, x, s;
|
2002-09-19 17:14:23 +00:00
|
|
|
plane_t plane, *p;
|
2002-09-19 18:51:19 +00:00
|
|
|
vec3_t corner;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
num_hull_points = 0;
|
|
|
|
num_hull_edges = 0;
|
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// create all the hull points
|
2002-09-19 17:14:23 +00:00
|
|
|
for (f = brush_faces; f; f = f->next)
|
2003-09-08 03:00:53 +00:00
|
|
|
for (i = 0; i < f->points->numpoints; i++)
|
|
|
|
AddHullPoint (f->points->points[i], hullnum);
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// expand all of the planes
|
2002-09-19 17:14:23 +00:00
|
|
|
for (i = 0; i < numbrushfaces; i++) {
|
2002-09-19 16:58:48 +00:00
|
|
|
p = &faces[i].plane;
|
2003-09-03 22:00:08 +00:00
|
|
|
VectorZero (corner);
|
2002-09-19 17:14:23 +00:00
|
|
|
for (x = 0; x < 3; x++) {
|
2002-09-19 16:58:48 +00:00
|
|
|
if (p->normal[x] > 0)
|
|
|
|
corner[x] = hull_size[hullnum][1][x];
|
|
|
|
else if (p->normal[x] < 0)
|
|
|
|
corner[x] = hull_size[hullnum][0][x];
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
p->dist += DotProduct (corner, p->normal);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// add any axis planes not contained in the brush to bevel off corners
|
2002-09-19 17:14:23 +00:00
|
|
|
for (x = 0; x < 3; x++)
|
|
|
|
for (s = -1; s <= 1; s += 2) {
|
|
|
|
// add the plane
|
2003-09-03 22:00:08 +00:00
|
|
|
VectorZero (plane.normal);
|
2002-09-19 16:58:48 +00:00
|
|
|
plane.normal[x] = s;
|
|
|
|
if (s == -1)
|
|
|
|
plane.dist = -brush_mins[x] + -hull_size[hullnum][0][x];
|
|
|
|
else
|
|
|
|
plane.dist = brush_maxs[x] + hull_size[hullnum][1][x];
|
|
|
|
AddBrushPlane (&plane);
|
|
|
|
}
|
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// add all of the edge bevels
|
2002-09-19 17:14:23 +00:00
|
|
|
for (f = brush_faces; f; f = f->next)
|
2003-09-08 03:00:53 +00:00
|
|
|
for (i = 0; i < f->points->numpoints; i++)
|
|
|
|
AddHullEdge (f->points->points[i],
|
|
|
|
f->points->points[(i + 1) % f->points->numpoints],
|
|
|
|
hullnum);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-09-23 16:27:17 +00:00
|
|
|
LoadBrush
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
Converts a mapbrush to a bsp brush
|
2002-09-19 16:58:48 +00:00
|
|
|
*/
|
2010-08-27 13:12:13 +00:00
|
|
|
static brush_t *
|
2010-09-02 04:01:45 +00:00
|
|
|
LoadBrush (const mbrush_t *mb, int hullnum)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
brush_t *b;
|
2010-09-02 04:01:45 +00:00
|
|
|
const char *name;
|
2002-09-19 18:51:19 +00:00
|
|
|
int contents;
|
2010-09-02 04:01:45 +00:00
|
|
|
const mface_t *f;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// check texture name for attributes
|
2003-03-25 16:34:07 +00:00
|
|
|
if (mb->faces->texinfo < 0) {
|
|
|
|
// ignore HINT and SKIP in clip hulls
|
|
|
|
if (hullnum)
|
|
|
|
return NULL;
|
|
|
|
contents = CONTENTS_EMPTY;
|
|
|
|
} else {
|
2010-12-07 06:41:57 +00:00
|
|
|
name = miptexnames[bsp->texinfo[mb->faces->texinfo].miptex];
|
2003-03-25 16:34:07 +00:00
|
|
|
|
|
|
|
if (!strcasecmp (name, "clip") && hullnum == 0)
|
|
|
|
return NULL; // "clip" brushes don't show up in the draw hull
|
|
|
|
|
|
|
|
if (name[0] == '*' && worldmodel) { // entities never use water merging
|
|
|
|
if (!strncasecmp (name + 1, "lava", 4))
|
|
|
|
contents = CONTENTS_LAVA;
|
|
|
|
else if (!strncasecmp (name + 1, "slime", 5))
|
|
|
|
contents = CONTENTS_SLIME;
|
|
|
|
else
|
|
|
|
contents = CONTENTS_WATER;
|
|
|
|
} else if (!strncasecmp (name, "sky", 3) && worldmodel && hullnum == 0)
|
|
|
|
contents = CONTENTS_SKY;
|
2002-09-19 17:14:23 +00:00
|
|
|
else
|
2003-03-25 16:34:07 +00:00
|
|
|
contents = CONTENTS_SOLID;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2003-03-25 16:34:07 +00:00
|
|
|
if (hullnum && contents != CONTENTS_SOLID && contents != CONTENTS_SKY)
|
|
|
|
return NULL; // water brushes don't show up in clipping hulls
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2003-03-25 16:34:07 +00:00
|
|
|
// no seperate textures on clip hull
|
|
|
|
}
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// create the faces
|
2002-09-19 16:58:48 +00:00
|
|
|
brush_faces = NULL;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
numbrushfaces = 0;
|
2002-09-19 17:14:23 +00:00
|
|
|
for (f = mb->faces; f; f = f->next) {
|
2002-09-19 16:58:48 +00:00
|
|
|
faces[numbrushfaces] = *f;
|
|
|
|
if (hullnum)
|
|
|
|
faces[numbrushfaces].texinfo = 0;
|
|
|
|
numbrushfaces++;
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
CreateBrushFaces ();
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
if (!brush_faces) {
|
2002-09-19 16:58:48 +00:00
|
|
|
printf ("WARNING: couldn't create brush faces\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
if (hullnum) {
|
2002-09-19 16:58:48 +00:00
|
|
|
ExpandBrush (hullnum);
|
|
|
|
CreateBrushFaces ();
|
2003-02-04 23:26:26 +00:00
|
|
|
} else if (mb->detail) {
|
|
|
|
face_t *f;
|
|
|
|
for (f = brush_faces; f; f = f->next);
|
|
|
|
f->detail = 1;
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2002-09-19 18:51:19 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// create the brush
|
2002-09-19 16:58:48 +00:00
|
|
|
b = AllocBrush ();
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
b->contents = contents;
|
|
|
|
b->faces = brush_faces;
|
|
|
|
VectorCopy (brush_mins, b->mins);
|
|
|
|
VectorCopy (brush_maxs, b->maxs);
|
|
|
|
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2010-09-02 04:01:45 +00:00
|
|
|
Brush_DrawAll (const brushset_t *bs)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
brush_t *b;
|
|
|
|
face_t *f;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
for (b = bs->brushes; b; b = b->next)
|
|
|
|
for (f = b->faces; f; f = f->next)
|
|
|
|
Draw_DrawFace (f);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
brushset_t *
|
|
|
|
Brush_LoadEntity (entity_t *ent, int hullnum)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
brush_t *b, *next, *water, *other;
|
|
|
|
brushset_t *bset;
|
2002-09-19 18:51:19 +00:00
|
|
|
int numbrushes;
|
|
|
|
mbrush_t *mbr;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
bset = malloc (sizeof (brushset_t));
|
|
|
|
memset (bset, 0, sizeof (brushset_t));
|
2002-09-19 16:58:48 +00:00
|
|
|
ClearBounds (bset);
|
|
|
|
|
|
|
|
numbrushes = 0;
|
|
|
|
other = water = NULL;
|
|
|
|
|
|
|
|
qprintf ("--- Brush_LoadEntity ---\n");
|
|
|
|
|
2003-09-03 22:00:08 +00:00
|
|
|
CurrentEntity = ent;
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
for (mbr = ent->brushes; mbr; mbr = mbr->next) {
|
2002-09-19 16:58:48 +00:00
|
|
|
b = LoadBrush (mbr, hullnum);
|
|
|
|
if (!b)
|
|
|
|
continue;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
numbrushes++;
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
if (b->contents != CONTENTS_SOLID) {
|
2002-09-19 16:58:48 +00:00
|
|
|
b->next = water;
|
|
|
|
water = b;
|
2002-09-19 17:14:23 +00:00
|
|
|
} else {
|
2002-09-19 16:58:48 +00:00
|
|
|
b->next = other;
|
|
|
|
other = b;
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
AddToBounds (bset, b->mins);
|
|
|
|
AddToBounds (bset, b->maxs);
|
|
|
|
}
|
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// add all of the water textures at the start
|
2002-09-19 17:14:23 +00:00
|
|
|
for (b = water; b; b = next) {
|
2002-09-19 16:58:48 +00:00
|
|
|
next = b->next;
|
|
|
|
b->next = other;
|
|
|
|
other = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
bset->brushes = other;
|
|
|
|
|
|
|
|
brushset = bset;
|
|
|
|
Brush_DrawAll (bset);
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
qprintf ("%i brushes read\n", numbrushes);
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
return bset;
|
|
|
|
}
|
2010-09-01 01:06:54 +00:00
|
|
|
|
|
|
|
//@}
|