📄 be_aas_debug.c
字号:
/*
===========================================================================
Copyright (C) 1999-2005 Id Software, Inc.
This file is part of Quake III Arena source code.
Quake III Arena source code 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.
Quake III Arena source code 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 Foobar; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
/*****************************************************************************
* name: be_aas_debug.c
*
* desc: AAS debug code
*
* $Archive: /MissionPack/code/botlib/be_aas_debug.c $
*
*****************************************************************************/
#include "../game/q_shared.h"
#include "l_memory.h"
#include "l_script.h"
#include "l_precomp.h"
#include "l_struct.h"
#include "l_libvar.h"
#include "aasfile.h"
#include "../game/botlib.h"
#include "../game/be_aas.h"
#include "be_interface.h"
#include "be_aas_funcs.h"
#include "be_aas_def.h"
#define MAX_DEBUGLINES 1024
#define MAX_DEBUGPOLYGONS 8192
int debuglines[MAX_DEBUGLINES];
int debuglinevisible[MAX_DEBUGLINES];
int numdebuglines;
static int debugpolygons[MAX_DEBUGPOLYGONS];
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_ClearShownPolygons(void)
{
int i;
//*
for (i = 0; i < MAX_DEBUGPOLYGONS; i++)
{
if (debugpolygons[i]) botimport.DebugPolygonDelete(debugpolygons[i]);
debugpolygons[i] = 0;
} //end for
//*/
/*
for (i = 0; i < MAX_DEBUGPOLYGONS; i++)
{
botimport.DebugPolygonDelete(i);
debugpolygons[i] = 0;
} //end for
*/
} //end of the function AAS_ClearShownPolygons
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_ShowPolygon(int color, int numpoints, vec3_t *points)
{
int i;
for (i = 0; i < MAX_DEBUGPOLYGONS; i++)
{
if (!debugpolygons[i])
{
debugpolygons[i] = botimport.DebugPolygonCreate(color, numpoints, points);
break;
} //end if
} //end for
} //end of the function AAS_ShowPolygon
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_ClearShownDebugLines(void)
{
int i;
//make all lines invisible
for (i = 0; i < MAX_DEBUGLINES; i++)
{
if (debuglines[i])
{
//botimport.DebugLineShow(debuglines[i], NULL, NULL, LINECOLOR_NONE);
botimport.DebugLineDelete(debuglines[i]);
debuglines[i] = 0;
debuglinevisible[i] = qfalse;
} //end if
} //end for
} //end of the function AAS_ClearShownDebugLines
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_DebugLine(vec3_t start, vec3_t end, int color)
{
int line;
for (line = 0; line < MAX_DEBUGLINES; line++)
{
if (!debuglines[line])
{
debuglines[line] = botimport.DebugLineCreate();
debuglinevisible[line] = qfalse;
numdebuglines++;
} //end if
if (!debuglinevisible[line])
{
botimport.DebugLineShow(debuglines[line], start, end, color);
debuglinevisible[line] = qtrue;
return;
} //end else
} //end for
} //end of the function AAS_DebugLine
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_PermanentLine(vec3_t start, vec3_t end, int color)
{
int line;
line = botimport.DebugLineCreate();
botimport.DebugLineShow(line, start, end, color);
} //end of the function AAS_PermenentLine
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_DrawPermanentCross(vec3_t origin, float size, int color)
{
int i, debugline;
vec3_t start, end;
for (i = 0; i < 3; i++)
{
VectorCopy(origin, start);
start[i] += size;
VectorCopy(origin, end);
end[i] -= size;
AAS_DebugLine(start, end, color);
debugline = botimport.DebugLineCreate();
botimport.DebugLineShow(debugline, start, end, color);
} //end for
} //end of the function AAS_DrawPermanentCross
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_DrawPlaneCross(vec3_t point, vec3_t normal, float dist, int type, int color)
{
int n0, n1, n2, j, line, lines[2];
vec3_t start1, end1, start2, end2;
//make a cross in the hit plane at the hit point
VectorCopy(point, start1);
VectorCopy(point, end1);
VectorCopy(point, start2);
VectorCopy(point, end2);
n0 = type % 3;
n1 = (type + 1) % 3;
n2 = (type + 2) % 3;
start1[n1] -= 6;
start1[n2] -= 6;
end1[n1] += 6;
end1[n2] += 6;
start2[n1] += 6;
start2[n2] -= 6;
end2[n1] -= 6;
end2[n2] += 6;
start1[n0] = (dist - (start1[n1] * normal[n1] +
start1[n2] * normal[n2])) / normal[n0];
end1[n0] = (dist - (end1[n1] * normal[n1] +
end1[n2] * normal[n2])) / normal[n0];
start2[n0] = (dist - (start2[n1] * normal[n1] +
start2[n2] * normal[n2])) / normal[n0];
end2[n0] = (dist - (end2[n1] * normal[n1] +
end2[n2] * normal[n2])) / normal[n0];
for (j = 0, line = 0; j < 2 && line < MAX_DEBUGLINES; line++)
{
if (!debuglines[line])
{
debuglines[line] = botimport.DebugLineCreate();
lines[j++] = debuglines[line];
debuglinevisible[line] = qtrue;
numdebuglines++;
} //end if
else if (!debuglinevisible[line])
{
lines[j++] = debuglines[line];
debuglinevisible[line] = qtrue;
} //end else
} //end for
botimport.DebugLineShow(lines[0], start1, end1, color);
botimport.DebugLineShow(lines[1], start2, end2, color);
} //end of the function AAS_DrawPlaneCross
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_ShowBoundingBox(vec3_t origin, vec3_t mins, vec3_t maxs)
{
vec3_t bboxcorners[8];
int lines[3];
int i, j, line;
//upper corners
bboxcorners[0][0] = origin[0] + maxs[0];
bboxcorners[0][1] = origin[1] + maxs[1];
bboxcorners[0][2] = origin[2] + maxs[2];
//
bboxcorners[1][0] = origin[0] + mins[0];
bboxcorners[1][1] = origin[1] + maxs[1];
bboxcorners[1][2] = origin[2] + maxs[2];
//
bboxcorners[2][0] = origin[0] + mins[0];
bboxcorners[2][1] = origin[1] + mins[1];
bboxcorners[2][2] = origin[2] + maxs[2];
//
bboxcorners[3][0] = origin[0] + maxs[0];
bboxcorners[3][1] = origin[1] + mins[1];
bboxcorners[3][2] = origin[2] + maxs[2];
//lower corners
Com_Memcpy(bboxcorners[4], bboxcorners[0], sizeof(vec3_t) * 4);
for (i = 0; i < 4; i++) bboxcorners[4 + i][2] = origin[2] + mins[2];
//draw bounding box
for (i = 0; i < 4; i++)
{
for (j = 0, line = 0; j < 3 && line < MAX_DEBUGLINES; line++)
{
if (!debuglines[line])
{
debuglines[line] = botimport.DebugLineCreate();
lines[j++] = debuglines[line];
debuglinevisible[line] = qtrue;
numdebuglines++;
} //end if
else if (!debuglinevisible[line])
{
lines[j++] = debuglines[line];
debuglinevisible[line] = qtrue;
} //end else
} //end for
//top plane
botimport.DebugLineShow(lines[0], bboxcorners[i],
bboxcorners[(i+1)&3], LINECOLOR_RED);
//bottom plane
botimport.DebugLineShow(lines[1], bboxcorners[4+i],
bboxcorners[4+((i+1)&3)], LINECOLOR_RED);
//vertical lines
botimport.DebugLineShow(lines[2], bboxcorners[i],
bboxcorners[4+i], LINECOLOR_RED);
} //end for
} //end of the function AAS_ShowBoundingBox
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_ShowFace(int facenum)
{
int i, color, edgenum;
aas_edge_t *edge;
aas_face_t *face;
aas_plane_t *plane;
vec3_t start, end;
color = LINECOLOR_YELLOW;
//check if face number is in range
if (facenum >= aasworld.numfaces)
{
botimport.Print(PRT_ERROR, "facenum %d out of range\n", facenum);
} //end if
face = &aasworld.faces[facenum];
//walk through the edges of the face
for (i = 0; i < face->numedges; i++)
{
//edge number
edgenum = abs(aasworld.edgeindex[face->firstedge + i]);
//check if edge number is in range
if (edgenum >= aasworld.numedges)
{
botimport.Print(PRT_ERROR, "edgenum %d out of range\n", edgenum);
} //end if
edge = &aasworld.edges[edgenum];
if (color == LINECOLOR_RED) color = LINECOLOR_GREEN;
else if (color == LINECOLOR_GREEN) color = LINECOLOR_BLUE;
else if (color == LINECOLOR_BLUE) color = LINECOLOR_YELLOW;
else color = LINECOLOR_RED;
AAS_DebugLine(aasworld.vertexes[edge->v[0]],
aasworld.vertexes[edge->v[1]],
color);
} //end for
plane = &aasworld.planes[face->planenum];
edgenum = abs(aasworld.edgeindex[face->firstedge]);
edge = &aasworld.edges[edgenum];
VectorCopy(aasworld.vertexes[edge->v[0]], start);
VectorMA(start, 20, plane->normal, end);
AAS_DebugLine(start, end, LINECOLOR_RED);
} //end of the function AAS_ShowFace
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_ShowFacePolygon(int facenum, int color, int flip)
{
int i, edgenum, numpoints;
vec3_t points[128];
aas_edge_t *edge;
aas_face_t *face;
//check if face number is in range
if (facenum >= aasworld.numfaces)
{
botimport.Print(PRT_ERROR, "facenum %d out of range\n", facenum);
} //end if
face = &aasworld.faces[facenum];
//walk through the edges of the face
numpoints = 0;
if (flip)
{
for (i = face->numedges-1; i >= 0; i--)
{
//edge number
edgenum = aasworld.edgeindex[face->firstedge + i];
edge = &aasworld.edges[abs(edgenum)];
VectorCopy(aasworld.vertexes[edge->v[edgenum < 0]], points[numpoints]);
numpoints++;
} //end for
} //end if
else
{
for (i = 0; i < face->numedges; i++)
{
//edge number
edgenum = aasworld.edgeindex[face->firstedge + i];
edge = &aasworld.edges[abs(edgenum)];
VectorCopy(aasworld.vertexes[edge->v[edgenum < 0]], points[numpoints]);
numpoints++;
} //end for
} //end else
AAS_ShowPolygon(color, numpoints, points);
} //end of the function AAS_ShowFacePolygon
//===========================================================================
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -