Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
2.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "scratchpad_helpers.h"
  7. #include "bspfile.h"
  8. #include "bsplib.h"
  9. void ScratchPad_DrawWinding(
  10. IScratchPad3D *pPad,
  11. int nPoints,
  12. Vector *pPoints,
  13. Vector vColor,
  14. Vector vOffset )
  15. {
  16. for ( int i=0; i < nPoints; i++ )
  17. {
  18. pPad->DrawLine( CSPVert( pPoints[i]+vOffset, vColor ), CSPVert( pPoints[(i+1)%nPoints]+vOffset, vColor ) );
  19. }
  20. }
  21. void ScratchPad_DrawFace( IScratchPad3D *pPad, dface_t *f, int iFaceNumber, const CSPColor &faceColor, const Vector &vOffset )
  22. {
  23. // Draw the face's outline, then put text for its face index on it too.
  24. CUtlVector<Vector> points;
  25. for ( int iEdge = 0; iEdge < f->numedges; iEdge++ )
  26. {
  27. int v;
  28. int se = dsurfedges[f->firstedge + iEdge];
  29. if ( se < 0 )
  30. v = dedges[-se].v[1];
  31. else
  32. v = dedges[se].v[0];
  33. dvertex_t *dv = &dvertexes[v];
  34. points.AddToTail( dv->point );
  35. }
  36. // Draw the outline.
  37. Vector vCenter( 0, 0, 0 );
  38. for ( int iEdge=0; iEdge < points.Count(); iEdge++ )
  39. {
  40. pPad->DrawLine( CSPVert( points[iEdge]+vOffset, faceColor ), CSPVert( points[(iEdge+1)%points.Count()]+vOffset, faceColor ) );
  41. vCenter += points[iEdge];
  42. }
  43. vCenter /= points.Count();
  44. vCenter += vOffset;
  45. // Draw the text.
  46. if ( iFaceNumber != -1 )
  47. {
  48. char str[64];
  49. Q_snprintf( str, sizeof( str ), "%d", iFaceNumber );
  50. CTextParams params;
  51. params.m_bCentered = true;
  52. params.m_bOutline = true;
  53. params.m_flLetterWidth = 2;
  54. params.m_vColor.Init( 1, 0, 0 );
  55. VectorAngles( dplanes[f->planenum].normal, params.m_vAngles );
  56. params.m_bTwoSided = true;
  57. params.m_vPos = vCenter;
  58. pPad->DrawText( str, params );
  59. }
  60. }
  61. void ScratchPad_DrawWorld( IScratchPad3D *pPad, bool bDrawFaceNumbers, const CSPColor &faceColor )
  62. {
  63. bool bAutoFlush = pPad->GetAutoFlush();
  64. pPad->SetAutoFlush( false );
  65. for ( int i=0; i < numleafs; i++ )
  66. {
  67. dleaf_t *l = &dleafs[i];
  68. if ( l->contents & CONTENTS_DETAIL )
  69. continue;
  70. for ( int z=0; z < l->numleaffaces; z++ )
  71. {
  72. int iFace = dleaffaces[l->firstleafface+z];
  73. dface_t *f = &dfaces[iFace];
  74. ScratchPad_DrawFace( pPad, f, bDrawFaceNumbers ? i : -1 );
  75. }
  76. }
  77. pPad->SetAutoFlush( bAutoFlush );
  78. }
  79. void ScratchPad_DrawWorld( bool bDrawFaceNumbers, const CSPColor &faceColor )
  80. {
  81. IScratchPad3D *pPad = ScratchPad3D_Create();
  82. ScratchPad_DrawWorld( pPad, bDrawFaceNumbers );
  83. }