halflife-photomode/pm_shared/pm_debug.cpp

315 lines
6.4 KiB
C++
Raw Normal View History

/***
2013-08-30 13:34:05 -07:00
*
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* Use, distribution, and modification of this source code and/or resulting
* object code is restricted to non-commercial enhancements to products from
* Valve LLC. All other use, distribution, or modification is prohibited
* without written permission from Valve LLC.
*
****/
#include "Platform.h"
2013-08-30 13:34:05 -07:00
#include "mathlib.h"
#include "const.h"
#include "usercmd.h"
#include "pm_defs.h"
#include "pm_shared.h"
#include "pm_movevars.h"
#include "pm_debug.h"
#include <string.h>
#pragma warning(disable : 4244)
#pragma warning(disable : 4305)
extern playermove_t* pmove;
2013-08-30 13:34:05 -07:00
// Expand debugging BBOX particle hulls by this many units.
#define BOX_GAP 0.0f
2013-08-30 13:34:05 -07:00
static int PM_boxpnt[6][4] =
{
{0, 4, 6, 2}, // +X
{0, 1, 5, 4}, // +Y
{0, 2, 3, 1}, // +Z
{7, 5, 1, 3}, // -X
{7, 3, 2, 6}, // -Y
{7, 6, 4, 5}, // -Z
};
2013-08-30 13:34:05 -07:00
void PM_ShowClipBox()
2013-08-30 13:34:05 -07:00
{
#if defined(_DEBUG)
Vector org;
Vector offset = {0, 0, 0};
2013-08-30 13:34:05 -07:00
if (0 == pmove->runfuncs)
2013-08-30 13:34:05 -07:00
return;
// More debugging, draw the particle bbox for player and for the entity we are looking directly at.
// aslo prints entity info to the console overlay.
//if ( !pmove->server )
// return;
// Draw entity in center of view
// Also draws the normal to the clip plane that intersects our movement ray. Leaves a particle
// trail at the intersection point.
PM_ViewEntity();
VectorCopy(pmove->origin, org);
2013-08-30 13:34:05 -07:00
if (0 != pmove->server)
2013-08-30 13:34:05 -07:00
{
VectorAdd(org, offset, org);
2013-08-30 13:34:05 -07:00
}
else
{
VectorSubtract(org, offset, org);
2013-08-30 13:34:05 -07:00
}
// Show our BBOX in particles.
PM_DrawBBox(pmove->player_mins[pmove->usehull], pmove->player_maxs[pmove->usehull], org, 0 != pmove->server ? 132 : 0, 0.1);
2013-08-30 13:34:05 -07:00
PM_ParticleLine(org, org, 0 != pmove->server ? 132 : 0, 0.1, 5.0);
2013-08-30 13:34:05 -07:00
/*
{
int i;
for ( i = 0; i < pmove->numphysent; i++ )
{
if ( pmove->physents[ i ].info >= 1 && pmove->physents[ i ].info <= 4 )
{
PM_DrawBBox( pmove->player_mins[pmove->usehull], pmove->player_maxs[pmove->usehull], pmove->physents[i].origin, 132, 0.1 );
}
}
}
*/
#endif
}
/*
===============
PM_ParticleLine(Vector start, Vector end, int color, float life)
2013-08-30 13:34:05 -07:00
================
*/
void PM_ParticleLine(Vector start, Vector end, int pcolor, float life, float vert)
2013-08-30 13:34:05 -07:00
{
float linestep = 2.0f;
float curdist;
float len;
Vector curpos;
Vector diff;
2013-08-30 13:34:05 -07:00
int i;
// Determine distance;
VectorSubtract(end, start, diff);
2013-08-30 13:34:05 -07:00
len = VectorNormalize(diff);
curdist = 0;
while (curdist <= len)
{
for (i = 0; i < 3; i++)
curpos[i] = start[i] + curdist * diff[i];
pmove->PM_Particle(curpos, pcolor, life, 0, vert);
2013-08-30 13:34:05 -07:00
curdist += linestep;
}
}
/*
================
PM_DrawRectangle(Vector tl, Vector br)
2013-08-30 13:34:05 -07:00
================
*/
void PM_DrawRectangle(Vector tl, Vector bl, Vector tr, Vector br, int pcolor, float life)
2013-08-30 13:34:05 -07:00
{
PM_ParticleLine(tl, bl, pcolor, life, 0);
PM_ParticleLine(bl, br, pcolor, life, 0);
PM_ParticleLine(br, tr, pcolor, life, 0);
PM_ParticleLine(tr, tl, pcolor, life, 0);
}
/*
================
PM_DrawPhysEntBBox(int num)
================
*/
void PM_DrawPhysEntBBox(int num, int pcolor, float life)
{
physent_t* pe;
Vector org;
2013-08-30 13:34:05 -07:00
int j;
Vector tmp;
Vector p[8];
2013-08-30 13:34:05 -07:00
float gap = BOX_GAP;
Vector modelmins, modelmaxs;
2013-08-30 13:34:05 -07:00
if (num >= pmove->numphysent ||
num <= 0)
return;
pe = &pmove->physents[num];
if (pe->model)
{
VectorCopy(pe->origin, org);
pmove->PM_GetModelBounds(pe->model, modelmins, modelmaxs);
2013-08-30 13:34:05 -07:00
for (j = 0; j < 8; j++)
{
tmp[0] = (j & 1) != 0 ? modelmins[0] - gap : modelmaxs[0] + gap;
tmp[1] = (j & 2) != 0 ? modelmins[1] - gap : modelmaxs[1] + gap;
tmp[2] = (j & 4) != 0 ? modelmins[2] - gap : modelmaxs[2] + gap;
2013-08-30 13:34:05 -07:00
VectorCopy(tmp, p[j]);
}
// If the bbox should be rotated, do that
if (pe->angles != g_vecZero)
2013-08-30 13:34:05 -07:00
{
Vector forward, right, up;
2013-08-30 13:34:05 -07:00
AngleVectorsTranspose(pe->angles, &forward, &right, &up);
2013-08-30 13:34:05 -07:00
for (j = 0; j < 8; j++)
{
VectorCopy(p[j], tmp);
p[j][0] = DotProduct(tmp, forward);
p[j][1] = DotProduct(tmp, right);
p[j][2] = DotProduct(tmp, up);
2013-08-30 13:34:05 -07:00
}
}
// Offset by entity origin, if any.
for (j = 0; j < 8; j++)
VectorAdd(p[j], org, p[j]);
for (j = 0; j < 6; j++)
{
PM_DrawRectangle(
p[PM_boxpnt[j][1]],
p[PM_boxpnt[j][0]],
p[PM_boxpnt[j][2]],
p[PM_boxpnt[j][3]],
pcolor, life);
}
}
else
{
for (j = 0; j < 8; j++)
{
tmp[0] = (j & 1) != 0 ? pe->mins[0] : pe->maxs[0];
tmp[1] = (j & 2) != 0 ? pe->mins[1] : pe->maxs[1];
tmp[2] = (j & 4) != 0 ? pe->mins[2] : pe->maxs[2];
2013-08-30 13:34:05 -07:00
VectorAdd(tmp, pe->origin, tmp);
VectorCopy(tmp, p[j]);
}
for (j = 0; j < 6; j++)
{
PM_DrawRectangle(
p[PM_boxpnt[j][1]],
p[PM_boxpnt[j][0]],
p[PM_boxpnt[j][2]],
p[PM_boxpnt[j][3]],
pcolor, life);
}
}
}
/*
================
PM_DrawBBox(Vector mins, Vector maxs, Vector origin, int pcolor, float life)
2013-08-30 13:34:05 -07:00
================
*/
void PM_DrawBBox(Vector mins, Vector maxs, Vector origin, int pcolor, float life)
2013-08-30 13:34:05 -07:00
{
int j;
Vector tmp;
Vector p[8];
2013-08-30 13:34:05 -07:00
float gap = BOX_GAP;
for (j = 0; j < 8; j++)
{
tmp[0] = (j & 1) != 0 ? mins[0] - gap : maxs[0] + gap;
tmp[1] = (j & 2) != 0 ? mins[1] - gap : maxs[1] + gap;
tmp[2] = (j & 4) != 0 ? mins[2] - gap : maxs[2] + gap;
2013-08-30 13:34:05 -07:00
VectorAdd(tmp, origin, tmp);
VectorCopy(tmp, p[j]);
}
for (j = 0; j < 6; j++)
{
PM_DrawRectangle(
p[PM_boxpnt[j][1]],
p[PM_boxpnt[j][0]],
p[PM_boxpnt[j][2]],
p[PM_boxpnt[j][3]],
pcolor, life);
}
}
/*
================
PM_ViewEntity
Shows a particle trail from player to entity in crosshair.
Shows particles at that entities bbox
Tries to shoot a ray out by about 128 units.
================
*/
void PM_ViewEntity()
2013-08-30 13:34:05 -07:00
{
Vector forward, right, up;
2013-08-30 13:34:05 -07:00
float raydist = 256.0f;
Vector origin;
Vector end;
2013-08-30 13:34:05 -07:00
int i;
pmtrace_t trace;
int pcolor = 77;
float fup;
#if 0
if ( !pm_showclip.value )
return;
#endif
AngleVectors(pmove->angles, &forward, &right, &up); // Determine movement angles
2013-08-30 13:34:05 -07:00
VectorCopy(pmove->origin, origin);
2013-08-30 13:34:05 -07:00
fup = 0.5 * (pmove->player_mins[pmove->usehull][2] + pmove->player_maxs[pmove->usehull][2]);
2013-08-30 13:34:05 -07:00
fup += pmove->view_ofs[2];
fup -= 4;
for (i = 0; i < 3; i++)
{
end[i] = origin[i] + raydist * forward[i];
}
trace = pmove->PM_PlayerTrace(origin, end, PM_STUDIO_BOX, -1);
2013-08-30 13:34:05 -07:00
if (trace.ent > 0) // Not the world
2013-08-30 13:34:05 -07:00
{
pcolor = 111;
}
2013-08-30 13:34:05 -07:00
// Draw the hull or bbox.
if (trace.ent > 0)
{
PM_DrawPhysEntBBox(trace.ent, pcolor, 0.3f);
}
}