2004-08-21 01:25:48 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
#include "quakedef.h"
|
|
|
|
|
2009-03-04 00:29:22 +00:00
|
|
|
qboolean PM_TransformedHullCheck (model_t *model, vec3_t start, vec3_t end, trace_t *trace, vec3_t origin, vec3_t angles);
|
2006-01-28 02:35:40 +00:00
|
|
|
int Q1BSP_HullPointContents(hull_t *hull, vec3_t p);
|
2004-08-21 01:25:48 +00:00
|
|
|
static hull_t box_hull;
|
|
|
|
static dclipnode_t box_clipnodes[6];
|
|
|
|
static mplane_t box_planes[6];
|
|
|
|
|
|
|
|
extern vec3_t player_mins;
|
|
|
|
extern vec3_t player_maxs;
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
PM_InitBoxHull
|
|
|
|
|
|
|
|
Set up the planes and clipnodes so that the six floats of a bounding box
|
|
|
|
can just be stored out and get a proper hull_t structure.
|
|
|
|
===================
|
|
|
|
*/
|
|
|
|
void PM_InitBoxHull (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int side;
|
|
|
|
|
|
|
|
box_hull.clipnodes = box_clipnodes;
|
|
|
|
box_hull.planes = box_planes;
|
|
|
|
box_hull.firstclipnode = 0;
|
|
|
|
box_hull.lastclipnode = 5;
|
|
|
|
|
|
|
|
Q1BSP_SetHullFuncs(&box_hull);
|
|
|
|
|
|
|
|
for (i=0 ; i<6 ; i++)
|
|
|
|
{
|
|
|
|
box_clipnodes[i].planenum = i;
|
|
|
|
|
|
|
|
side = i&1;
|
|
|
|
|
|
|
|
box_clipnodes[i].children[side] = Q1CONTENTS_EMPTY;
|
|
|
|
if (i != 5)
|
|
|
|
box_clipnodes[i].children[side^1] = i + 1;
|
|
|
|
else
|
|
|
|
box_clipnodes[i].children[side^1] = Q1CONTENTS_SOLID;
|
|
|
|
|
|
|
|
box_planes[i].type = i>>1;
|
|
|
|
box_planes[i].normal[i>>1] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
PM_HullForBox
|
|
|
|
|
|
|
|
To keep everything totally uniform, bounding boxes are turned into small
|
|
|
|
BSP trees instead of being compared directly.
|
|
|
|
===================
|
|
|
|
*/
|
|
|
|
hull_t *PM_HullForBox (vec3_t mins, vec3_t maxs)
|
|
|
|
{
|
|
|
|
box_planes[0].dist = maxs[0];
|
|
|
|
box_planes[1].dist = mins[0];
|
|
|
|
box_planes[2].dist = maxs[1];
|
|
|
|
box_planes[3].dist = mins[1];
|
|
|
|
box_planes[4].dist = maxs[2];
|
|
|
|
box_planes[5].dist = mins[2];
|
|
|
|
|
|
|
|
return &box_hull;
|
|
|
|
}
|
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
|
|
|
|
int PM_TransformedModelPointContents (model_t *mod, vec3_t p, vec3_t origin, vec3_t angles)
|
2004-08-21 01:25:48 +00:00
|
|
|
{
|
|
|
|
vec3_t p_l, forward, up, right, temp;
|
|
|
|
VectorSubtract (p, origin, p_l);
|
|
|
|
|
|
|
|
// rotate start and end into the models frame of reference
|
2005-08-26 22:56:51 +00:00
|
|
|
if (angles[0] || angles[1] || angles[2])
|
2004-08-21 01:25:48 +00:00
|
|
|
{
|
|
|
|
AngleVectors (angles, forward, right, up);
|
|
|
|
|
|
|
|
VectorCopy (p_l, temp);
|
|
|
|
p_l[0] = DotProduct (temp, forward);
|
|
|
|
p_l[1] = -DotProduct (temp, right);
|
|
|
|
p_l[2] = DotProduct (temp, up);
|
|
|
|
}
|
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
return mod->funcs.PointContents(mod, p_l);
|
2004-08-21 01:25:48 +00:00
|
|
|
}
|
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
|
2004-08-21 01:25:48 +00:00
|
|
|
/*
|
|
|
|
==================
|
|
|
|
PM_PointContents
|
|
|
|
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
int PM_PointContents (vec3_t p)
|
|
|
|
{
|
|
|
|
int num;
|
|
|
|
|
|
|
|
int pc;
|
2005-08-26 22:56:51 +00:00
|
|
|
physent_t *pe;
|
|
|
|
model_t *pm;
|
2004-08-21 01:25:48 +00:00
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
pm = pmove.physents[0].model;
|
|
|
|
pc = pm->funcs.PointContents(pm, p);
|
2004-08-21 01:25:48 +00:00
|
|
|
//we need this for e2m2 - waterjumping on to plats wouldn't work otherwise.
|
|
|
|
for (num = 1; num < pmove.numphysent; num++)
|
|
|
|
{
|
2005-08-26 22:56:51 +00:00
|
|
|
pe = &pmove.physents[num];
|
|
|
|
pm = pe->model;
|
|
|
|
if (pm)
|
2009-03-03 01:52:30 +00:00
|
|
|
{
|
|
|
|
if (pe->forcecontentsmask)
|
|
|
|
{
|
|
|
|
if (PM_TransformedModelPointContents(pm, p, pe->origin, pe->angles))
|
|
|
|
pc |= pe->forcecontentsmask;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (pe->nonsolid)
|
|
|
|
continue;
|
|
|
|
pc |= PM_TransformedModelPointContents(pm, p, pe->origin, pe->angles);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (pe->forcecontentsmask)
|
|
|
|
{
|
|
|
|
if (p[0] >= pe->mins[0] && p[0] <= pe->maxs[0] &&
|
|
|
|
p[1] >= pe->mins[1] && p[1] <= pe->maxs[1] &&
|
|
|
|
p[2] >= pe->mins[2] && p[2] <= pe->maxs[2])
|
|
|
|
pc |= pe->forcecontentsmask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PM_ExtraBoxContents (vec3_t p)
|
|
|
|
{
|
|
|
|
int num;
|
|
|
|
|
|
|
|
int pc = 0;
|
|
|
|
physent_t *pe;
|
|
|
|
model_t *pm;
|
|
|
|
trace_t tr;
|
|
|
|
|
|
|
|
for (num = 1; num < pmove.numphysent; num++)
|
|
|
|
{
|
|
|
|
pe = &pmove.physents[num];
|
|
|
|
if (!pe->nonsolid)
|
|
|
|
continue;
|
|
|
|
pm = pe->model;
|
|
|
|
if (pm)
|
|
|
|
{
|
|
|
|
if (pe->forcecontentsmask)
|
|
|
|
{
|
|
|
|
PM_TransformedHullCheck(pm, p, p, &tr, pe->origin, pe->angles);
|
|
|
|
if (tr.startsolid)
|
|
|
|
pc |= pe->forcecontentsmask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (pe->forcecontentsmask)
|
|
|
|
{
|
|
|
|
if (p[0]+player_maxs[0] >= pe->mins[0] && p[0]+player_mins[0] <= pe->maxs[0] &&
|
|
|
|
p[1]+player_maxs[1] >= pe->mins[1] && p[1]+player_mins[1] <= pe->maxs[1] &&
|
|
|
|
p[2]+player_maxs[2] >= pe->mins[2] && p[2]+player_mins[2] <= pe->maxs[2])
|
|
|
|
pc |= pe->forcecontentsmask;
|
|
|
|
}
|
2004-08-21 01:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return pc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
LINE TESTING IN HULLS
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
// 1/32 epsilon to keep floating point happy
|
|
|
|
#define DIST_EPSILON (0.03125)
|
|
|
|
|
|
|
|
vec3_t trace_extents;
|
|
|
|
|
|
|
|
|
2005-07-16 00:53:08 +00:00
|
|
|
qboolean PM_TransformedHullCheck (model_t *model, vec3_t start, vec3_t end, trace_t *trace, vec3_t origin, vec3_t angles)
|
2004-08-21 01:25:48 +00:00
|
|
|
{
|
|
|
|
vec3_t start_l, end_l;
|
|
|
|
vec3_t a;
|
|
|
|
vec3_t forward, right, up;
|
|
|
|
vec3_t temp;
|
|
|
|
qboolean rotated;
|
|
|
|
qboolean result;
|
|
|
|
|
|
|
|
// subtract origin offset
|
|
|
|
VectorSubtract (start, origin, start_l);
|
|
|
|
VectorSubtract (end, origin, end_l);
|
|
|
|
|
|
|
|
// rotate start and end into the models frame of reference
|
2005-07-16 00:53:08 +00:00
|
|
|
if (model &&
|
2004-08-21 01:25:48 +00:00
|
|
|
(angles[0] || angles[1] || angles[2]) )
|
|
|
|
rotated = true;
|
|
|
|
else
|
|
|
|
rotated = false;
|
|
|
|
|
|
|
|
if (rotated)
|
|
|
|
{
|
|
|
|
AngleVectors (angles, forward, right, up);
|
|
|
|
|
|
|
|
VectorCopy (start_l, temp);
|
|
|
|
start_l[0] = DotProduct (temp, forward);
|
|
|
|
start_l[1] = -DotProduct (temp, right);
|
|
|
|
start_l[2] = DotProduct (temp, up);
|
|
|
|
|
|
|
|
VectorCopy (end_l, temp);
|
|
|
|
end_l[0] = DotProduct (temp, forward);
|
|
|
|
end_l[1] = -DotProduct (temp, right);
|
|
|
|
end_l[2] = DotProduct (temp, up);
|
|
|
|
}
|
|
|
|
// sweep the box through the model
|
2005-07-16 00:53:08 +00:00
|
|
|
|
2009-03-03 01:52:30 +00:00
|
|
|
if (model && model->funcs.Trace)
|
2005-07-16 00:53:08 +00:00
|
|
|
result = model->funcs.Trace(model, 0, 0, start_l, end_l, player_mins, player_maxs, trace);
|
|
|
|
else
|
2005-10-07 02:10:56 +00:00
|
|
|
{
|
2005-07-16 00:53:08 +00:00
|
|
|
result = Q1BSP_RecursiveHullCheck (&box_hull, box_hull.firstclipnode, 0, 1, start_l, end_l, trace);
|
2005-10-07 02:10:56 +00:00
|
|
|
}
|
2004-08-21 01:25:48 +00:00
|
|
|
|
2005-10-07 02:10:56 +00:00
|
|
|
if (rotated)
|
2004-08-21 01:25:48 +00:00
|
|
|
{
|
|
|
|
// FIXME: figure out how to do this with existing angles
|
|
|
|
// VectorNegate (angles, a);
|
|
|
|
|
2005-10-07 02:10:56 +00:00
|
|
|
if (trace->fraction != 1.0)
|
|
|
|
{
|
2006-03-23 19:22:12 +00:00
|
|
|
a[0] = -angles[0];
|
|
|
|
a[1] = -angles[1];
|
|
|
|
a[2] = -angles[2];
|
2005-10-07 02:10:56 +00:00
|
|
|
AngleVectors (a, forward, right, up);
|
|
|
|
|
|
|
|
VectorCopy (trace->plane.normal, temp);
|
|
|
|
trace->plane.normal[0] = DotProduct (temp, forward);
|
|
|
|
trace->plane.normal[1] = -DotProduct (temp, right);
|
|
|
|
trace->plane.normal[2] = DotProduct (temp, up);
|
|
|
|
}
|
|
|
|
trace->endpos[0] = start[0] + trace->fraction * (end[0] - start[0]);
|
|
|
|
trace->endpos[1] = start[1] + trace->fraction * (end[1] - start[1]);
|
|
|
|
trace->endpos[2] = start[2] + trace->fraction * (end[2] - start[2]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
trace->endpos[0] += origin[0];
|
|
|
|
trace->endpos[1] += origin[1];
|
|
|
|
trace->endpos[2] += origin[2];
|
|
|
|
}
|
2004-08-21 01:25:48 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
PM_TestPlayerPosition
|
|
|
|
|
|
|
|
Returns false if the given player position is not valid (in solid)
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
qboolean PM_TestPlayerPosition (vec3_t pos)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
physent_t *pe;
|
|
|
|
vec3_t mins, maxs;
|
|
|
|
hull_t *hull;
|
2005-08-26 22:56:51 +00:00
|
|
|
trace_t trace;
|
2004-08-21 01:25:48 +00:00
|
|
|
|
|
|
|
for (i=0 ; i< pmove.numphysent ; i++)
|
|
|
|
{
|
|
|
|
pe = &pmove.physents[i];
|
|
|
|
|
2009-03-03 01:52:30 +00:00
|
|
|
if (pe->nonsolid)
|
|
|
|
continue;
|
|
|
|
|
2004-08-21 01:25:48 +00:00
|
|
|
// get the clipping hull
|
|
|
|
if (pe->model)
|
|
|
|
{
|
2005-08-26 22:56:51 +00:00
|
|
|
/*
|
2004-08-21 01:25:48 +00:00
|
|
|
#ifdef Q2BSPS
|
|
|
|
if (pe->model->fromgame == fg_quake2 || pe->model->fromgame == fg_quake3)
|
|
|
|
{
|
2005-08-26 22:56:51 +00:00
|
|
|
trace_t trace = CM_TransformedBoxTrace(pe->model, pos, pos, player_mins, player_maxs, MASK_PLAYERSOLID, pe->origin, pe->angles);
|
2004-08-21 01:25:48 +00:00
|
|
|
if (trace.fraction == 0)
|
|
|
|
return false;
|
|
|
|
continue;
|
|
|
|
}
|
2005-08-26 22:56:51 +00:00
|
|
|
#endif*/
|
2005-10-07 16:21:54 +00:00
|
|
|
|
|
|
|
PM_TransformedHullCheck (pe->model, pos, pos, &trace, pe->origin, pe->angles);
|
2005-08-28 19:43:50 +00:00
|
|
|
if (trace.allsolid)
|
2005-08-26 22:56:51 +00:00
|
|
|
return false; //solid
|
2004-08-21 01:25:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VectorSubtract (pe->mins, player_maxs, mins);
|
|
|
|
VectorSubtract (pe->maxs, player_mins, maxs);
|
|
|
|
hull = PM_HullForBox (mins, maxs);
|
2005-08-26 22:56:51 +00:00
|
|
|
VectorSubtract(pos, pe->origin, mins);
|
2004-08-21 01:25:48 +00:00
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
if (Q1BSP_HullPointContents(hull, mins) & FTECONTENTS_SOLID)
|
|
|
|
return false;
|
|
|
|
|
2005-10-07 02:10:56 +00:00
|
|
|
// if (Q1BSP_Trace(&box_hull, 0, 0, pe->origin, pe->origin, pe->mins, pe->maxs, pos, pe->origin, pe->angles) & FTECONTENTS_SOLID)
|
2005-08-26 22:56:51 +00:00
|
|
|
// return false;
|
|
|
|
}
|
2004-08-21 01:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
PM_PlayerTrace
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
trace_t PM_PlayerTrace (vec3_t start, vec3_t end)
|
|
|
|
{
|
|
|
|
trace_t trace, total;
|
|
|
|
int i;
|
|
|
|
physent_t *pe;
|
|
|
|
|
|
|
|
// fill in a default trace
|
|
|
|
memset (&total, 0, sizeof(trace_t));
|
|
|
|
total.fraction = 1;
|
|
|
|
total.entnum = -1;
|
|
|
|
VectorCopy (end, total.endpos);
|
|
|
|
|
|
|
|
for (i=0 ; i< pmove.numphysent ; i++)
|
|
|
|
{
|
|
|
|
pe = &pmove.physents[i];
|
|
|
|
|
2009-03-03 01:52:30 +00:00
|
|
|
if (pe->nonsolid)
|
|
|
|
continue;
|
|
|
|
|
2005-10-07 16:21:54 +00:00
|
|
|
if (!pe->model)
|
2005-10-07 02:10:56 +00:00
|
|
|
{
|
|
|
|
vec3_t mins, maxs;
|
|
|
|
VectorSubtract (pe->mins, player_maxs, mins);
|
|
|
|
VectorSubtract (pe->maxs, player_mins, maxs);
|
|
|
|
PM_HullForBox (mins, maxs);
|
|
|
|
}
|
|
|
|
|
2004-08-21 01:25:48 +00:00
|
|
|
// trace a line through the apropriate clipping hull
|
2005-07-16 00:53:08 +00:00
|
|
|
PM_TransformedHullCheck (pe->model, start, end, &trace, pe->origin, pe->angles);
|
2004-08-21 01:25:48 +00:00
|
|
|
|
|
|
|
if (trace.allsolid)
|
|
|
|
trace.startsolid = true;
|
|
|
|
if (trace.startsolid)
|
2004-09-04 17:42:25 +00:00
|
|
|
{
|
2005-10-07 02:10:56 +00:00
|
|
|
// if (!pmove.physents[i].model) //caught inside annother model
|
|
|
|
// continue; //don't count this.
|
2004-08-21 01:25:48 +00:00
|
|
|
trace.fraction = 0;
|
2004-09-04 17:42:25 +00:00
|
|
|
}
|
2004-08-21 01:25:48 +00:00
|
|
|
|
|
|
|
// did we clip the move?
|
|
|
|
if (trace.fraction < total.fraction)
|
|
|
|
{
|
|
|
|
// fix trace up by the offset
|
|
|
|
total = trace;
|
|
|
|
total.entnum = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
2005-04-26 16:04:12 +00:00
|
|
|
//for use outside the pmove code. lame, but works.
|
|
|
|
trace_t PM_TraceLine (vec3_t start, vec3_t end)
|
|
|
|
{
|
2008-01-12 03:33:59 +00:00
|
|
|
VectorClear(player_mins);
|
|
|
|
VectorClear(player_maxs);
|
2005-04-26 16:04:12 +00:00
|
|
|
pmove.hullnum = 0;
|
|
|
|
return PM_PlayerTrace(start, end);
|
2005-07-20 20:21:10 +00:00
|
|
|
}
|