aboutsummaryrefslogtreecommitdiff
path: root/sp/src/utils/common/scratchpad_helpers.cpp
blob: ecab731bd3f7cbd9daa3857e4ab8cd15d0378c9b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================//

#include "scratchpad_helpers.h"
#include "bspfile.h"
#include "bsplib.h"


void ScratchPad_DrawWinding( 
	IScratchPad3D *pPad, 
	int nPoints, 
	Vector *pPoints, 
	Vector vColor, 
	Vector vOffset )
{
	for ( int i=0; i < nPoints; i++ )
	{
		pPad->DrawLine( CSPVert( pPoints[i]+vOffset, vColor ), CSPVert( pPoints[(i+1)%nPoints]+vOffset, vColor ) );
	}
}


void ScratchPad_DrawFace( IScratchPad3D *pPad, dface_t *f, int iFaceNumber, const CSPColor &faceColor, const Vector &vOffset )
{
	// Draw the face's outline, then put text for its face index on it too.
	CUtlVector<Vector> points;
	for ( int iEdge = 0; iEdge < f->numedges; iEdge++ )
	{
		int v;
		int se = dsurfedges[f->firstedge + iEdge];
		if ( se < 0 )
			v = dedges[-se].v[1];
		else
			v = dedges[se].v[0];
	
		dvertex_t *dv = &dvertexes[v];
		points.AddToTail( dv->point );
	}

	// Draw the outline.
	Vector vCenter( 0, 0, 0 );
	for ( int iEdge=0; iEdge < points.Count(); iEdge++ )
	{
		pPad->DrawLine( CSPVert( points[iEdge]+vOffset, faceColor ), CSPVert( points[(iEdge+1)%points.Count()]+vOffset, faceColor ) );
		vCenter += points[iEdge];
	}
	vCenter /= points.Count();
	vCenter += vOffset;

	// Draw the text.
	if ( iFaceNumber != -1 )
	{
		char str[64];
		Q_snprintf( str, sizeof( str ), "%d", iFaceNumber );

		CTextParams params;

		params.m_bCentered = true;
		params.m_bOutline = true;
		params.m_flLetterWidth = 2;
		params.m_vColor.Init( 1, 0, 0 );
		
		VectorAngles( dplanes[f->planenum].normal, params.m_vAngles );
		params.m_bTwoSided = true;

		params.m_vPos = vCenter;
		
		pPad->DrawText( str, params );
	}
}


void ScratchPad_DrawWorld( IScratchPad3D *pPad, bool bDrawFaceNumbers, const CSPColor &faceColor )
{
	bool bAutoFlush = pPad->GetAutoFlush();
	pPad->SetAutoFlush( false );

	for ( int i=0; i < numleafs; i++ )
	{
		dleaf_t *l = &dleafs[i];
		if ( l->contents & CONTENTS_DETAIL )
			continue;
			
		for ( int z=0; z < l->numleaffaces; z++ )
		{
			int iFace = dleaffaces[l->firstleafface+z];
			dface_t *f = &dfaces[iFace];
			ScratchPad_DrawFace( pPad, f, bDrawFaceNumbers ? i : -1 );
		}
	}

	pPad->SetAutoFlush( bAutoFlush );
}


void ScratchPad_DrawWorld( bool bDrawFaceNumbers, const CSPColor &faceColor )
{
	IScratchPad3D *pPad = ScratchPad3D_Create();
	ScratchPad_DrawWorld( pPad, bDrawFaceNumbers );
}