Counter Strike : Global Offensive Source Code
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.

326 lines
8.2 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef ISCRATCHPAD3D_H
  8. #define ISCRATCHPAD3D_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. // IScratchPad3D will store drawing commands in a file to be viewed by ScratchPad3DViewer.
  13. // It can be used while stepping through geometry code to visualize what is going on as
  14. // drawing commands will be immediately visible in ScratchPad3DViewer even while you're stuck
  15. // in the debugger
  16. // ScratchPad3DViewer initially orbits 100 inches from the origin, so it can be useful
  17. // to call SetMapping to map what you're drawing input into this cube.
  18. #include "mathlib/vector.h"
  19. #include "mathlib/vector2d.h"
  20. #include "utlvector.h"
  21. class IFileSystem;
  22. class CSPColor
  23. {
  24. public:
  25. CSPColor()
  26. {
  27. m_flAlpha = 1;
  28. }
  29. CSPColor( const Vector &vColor, float flAlpha=1 )
  30. {
  31. m_vColor = vColor;
  32. m_flAlpha = flAlpha;
  33. }
  34. CSPColor( float r, float g, float b, float a=1 )
  35. {
  36. m_vColor.Init( r, g, b );
  37. m_flAlpha = a;
  38. }
  39. Vector m_vColor;
  40. float m_flAlpha;
  41. };
  42. class CSPVert
  43. {
  44. public:
  45. CSPVert();
  46. CSPVert( Vector const &vPos, const CSPColor &vColor=CSPColor( Vector(1, 1, 1), 1 ) );
  47. void Init( Vector const &vPos, const CSPColor &vColor=CSPColor( Vector(1, 1, 1), 1 ) );
  48. public:
  49. Vector m_vPos;
  50. CSPColor m_vColor;
  51. };
  52. class CSPVertList
  53. {
  54. public:
  55. explicit CSPVertList( int nVerts = 0 );
  56. CSPVertList(CSPVert const *pVerts, int nVerts);
  57. CSPVertList(Vector const *pVerts, int nVerts, CSPColor vColor=CSPColor(1,1,1) );
  58. CSPVertList(Vector const *pVerts, Vector const *pColors, int nVerts);
  59. CSPVertList(Vector const *pVerts, CSPColor const *pColors, int nVerts);
  60. CSPVertList(Vector const &vert1, CSPColor const &color1,
  61. Vector const &vert2, CSPColor const &color2,
  62. Vector const &vert3, CSPColor const &color3);
  63. CUtlVector<CSPVert> m_Verts;
  64. };
  65. class SPRGBA
  66. {
  67. public:
  68. unsigned char r,g,b,a;
  69. };
  70. class CTextParams
  71. {
  72. public:
  73. CTextParams();
  74. Vector m_vColor; // Color of the string (starting color.. at some point,
  75. // we can embed commands in the text itself to change the color).
  76. float m_flAlpha; // Alpha of the whole thing.
  77. bool m_bSolidBackground; // Should the background be solid or alpha'd?
  78. // Draw an outline around the text?
  79. bool m_bOutline;
  80. Vector m_vPos; // Where to render the text.
  81. bool m_bCentered; // Centered on m_vPos, or is m_vPos the upper-left corner?
  82. QAngle m_vAngles; // Orientation of the text.
  83. bool m_bTwoSided; // Render the text from both sides?
  84. float m_flLetterWidth; // Letter width in world space.
  85. };
  86. abstract_class IScratchPad3D
  87. {
  88. protected:
  89. virtual ~IScratchPad3D() {}
  90. // Types.
  91. public:
  92. enum RenderState
  93. {
  94. RS_FillMode=0, // val = one of the FillMode enums
  95. RS_ZRead,
  96. RS_ZBias // val = 0 - 16 to push Z towards viewer
  97. };
  98. enum FillMode
  99. {
  100. FillMode_Wireframe=0,
  101. FillMode_Solid
  102. };
  103. public:
  104. virtual void Release() = 0;
  105. // This sets up a mapping between input coordinates and output coordinates.
  106. // This can be used to zoom into an area of interest where you'll be drawing things.
  107. // An alternative is to press Z while in VisLibViewer to have it center and zoom on
  108. // everything that has been drawn.
  109. virtual void SetMapping(
  110. Vector const &vInputMin,
  111. Vector const &vInputMax,
  112. Vector const &vOutputMin,
  113. Vector const &vOutputMax ) = 0;
  114. // Enable/disable auto flush. When set to true (the default), all drawing commands
  115. // are immediately written to the file and will show up in VisLibViewer right away.
  116. // If you want to draw a lot of things, you can set this to false and call Flush()
  117. // manually when you want the file written out.
  118. // When you set auto flush to true, it calls Flush().
  119. virtual bool GetAutoFlush() = 0;
  120. virtual void SetAutoFlush( bool bAutoFlush ) = 0;
  121. // Draw a point. Point size is (roughly) in world coordinates, so points
  122. // get smaller as the viewer moves away.
  123. virtual void DrawPoint( CSPVert const &v, float flPointSize ) = 0;
  124. // Draw a line.
  125. virtual void DrawLine( CSPVert const &v1, CSPVert const &v2 ) = 0;
  126. // Draw a polygon.
  127. virtual void DrawPolygon( CSPVertList const &verts ) = 0;
  128. // Draw 2D rectangles.
  129. virtual void DrawRectYZ( float xPos, Vector2D const &vMin, Vector2D const &vMax, const CSPColor &vColor ) = 0;
  130. virtual void DrawRectXZ( float yPos, Vector2D const &vMin, Vector2D const &vMax, const CSPColor &vColor ) = 0;
  131. virtual void DrawRectXY( float zPos, Vector2D const &vMin, Vector2D const &vMax, const CSPColor &vColor ) = 0;
  132. // Draw a wireframe box.
  133. virtual void DrawWireframeBox( Vector const &vMin, Vector const &vMax, Vector const &vColor ) = 0;
  134. // Draw some text.
  135. virtual void DrawText( const char *pStr, const CTextParams &params ) = 0;
  136. // Wireframe on/off.
  137. virtual void SetRenderState( RenderState state, unsigned long val ) = 0;
  138. // Clear all the drawing commands.
  139. virtual void Clear() = 0;
  140. // Calling this writes all the commands to the file. If AutoFlush is true, this is called
  141. // automatically in all the drawing commands.
  142. virtual void Flush() = 0;
  143. // Primitives that build on the atomic primitives.
  144. public:
  145. // Draw a black and white image.
  146. // Corners are in this order: bottom-left, top-left, top-right, bottom-right.
  147. // If the corners are NULL, then the image is drawn in the XY plane from (-100,-100) to (100,100).
  148. virtual void DrawImageBW(
  149. unsigned char const *pData,
  150. int width,
  151. int height,
  152. int pitchInBytes,
  153. bool bOutlinePixels=true,
  154. bool bOutlineImage=false,
  155. Vector *vCorners=NULL ) = 0;
  156. // Draw an RGBA image.
  157. // Corners are in this order: bottom-left, top-left, top-right, bottom-right.
  158. virtual void DrawImageRGBA(
  159. SPRGBA *pData,
  160. int width,
  161. int height,
  162. int pitchInBytes,
  163. bool bOutlinePixels=true,
  164. bool bOutlineImage=false,
  165. Vector *vCorners=NULL ) = 0;
  166. };
  167. // Just a helper for functions where you want to have a CScratchPad3D around
  168. // and release it automatically when the function exits.
  169. class CScratchPadAutoRelease
  170. {
  171. public:
  172. explicit CScratchPadAutoRelease( IScratchPad3D *pPad ) { m_pPad = pPad; }
  173. ~CScratchPadAutoRelease() { if( m_pPad ) m_pPad->Release(); }
  174. IScratchPad3D *m_pPad;
  175. };
  176. IScratchPad3D* ScratchPad3D_Create( char const *pFilename = "scratch.pad" );
  177. // ------------------------------------------------------------------------------------ //
  178. // Inlines.
  179. // ------------------------------------------------------------------------------------ //
  180. inline CTextParams::CTextParams()
  181. {
  182. m_vColor.Init( 1, 1, 1 );
  183. m_flAlpha = 1;
  184. m_bSolidBackground = true;
  185. m_bOutline = true;
  186. m_vPos.Init();
  187. m_bCentered = true;
  188. m_vAngles.Init();
  189. m_bTwoSided = true;
  190. m_flLetterWidth = 3;
  191. }
  192. inline CSPVert::CSPVert()
  193. {
  194. }
  195. inline CSPVert::CSPVert( Vector const &vPos, const CSPColor &vColor )
  196. {
  197. Init( vPos, vColor );
  198. }
  199. inline void CSPVert::Init( Vector const &vPos, const CSPColor &vColor )
  200. {
  201. m_vPos = vPos;
  202. m_vColor = vColor;
  203. }
  204. inline CSPVertList::CSPVertList( int nVerts )
  205. {
  206. if( nVerts )
  207. m_Verts.AddMultipleToTail( nVerts );
  208. }
  209. inline CSPVertList::CSPVertList(CSPVert const *pVerts, int nVerts )
  210. {
  211. m_Verts.CopyArray( pVerts, nVerts );
  212. }
  213. inline CSPVertList::CSPVertList(Vector const *pVerts, int nVerts, CSPColor vColor )
  214. {
  215. m_Verts.AddMultipleToTail( nVerts );
  216. for( int i=0; i < nVerts; i++ )
  217. {
  218. m_Verts[i].m_vPos = pVerts[i];
  219. m_Verts[i].m_vColor = vColor;
  220. }
  221. }
  222. inline CSPVertList::CSPVertList( Vector const *pVerts, Vector const *pColors, int nVerts )
  223. {
  224. m_Verts.AddMultipleToTail( nVerts );
  225. for( int i=0; i < nVerts; i++ )
  226. {
  227. m_Verts[i].m_vPos = pVerts[i];
  228. m_Verts[i].m_vColor = pColors[i];
  229. }
  230. }
  231. inline CSPVertList::CSPVertList( Vector const *pVerts, CSPColor const *pColors, int nVerts )
  232. {
  233. m_Verts.AddMultipleToTail( nVerts );
  234. for( int i=0; i < nVerts; i++ )
  235. {
  236. m_Verts[i].m_vPos = pVerts[i];
  237. m_Verts[i].m_vColor = pColors[i];
  238. }
  239. }
  240. inline CSPVertList::CSPVertList(
  241. Vector const &vert1, CSPColor const &color1,
  242. Vector const &vert2, CSPColor const &color2,
  243. Vector const &vert3, CSPColor const &color3 )
  244. {
  245. m_Verts.AddMultipleToTail( 3 );
  246. m_Verts[0].Init( vert1, color1 );
  247. m_Verts[1].Init( vert2, color2 );
  248. m_Verts[2].Init( vert3, color3 );
  249. }
  250. #endif // ISCRATCHPAD3D_H