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.

198 lines
6.9 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #if !defined( BEAMSEGDRAW_H )
  8. #define BEAMSEGDRAW_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #define NOISE_DIVISIONS 128
  13. #include "mathlib/vector.h"
  14. #include "materialsystem/imesh.h"
  15. //-----------------------------------------------------------------------------
  16. // Forward declarations
  17. //-----------------------------------------------------------------------------
  18. struct BeamTrail_t;
  19. class IMaterial;
  20. //-----------------------------------------------------------------------------
  21. // CBeamSegDraw is a simple interface to beam rendering.
  22. //-----------------------------------------------------------------------------
  23. struct BeamSeg_t
  24. {
  25. VectorAligned m_vPos;
  26. color32 m_color;
  27. float m_flTexCoord; // Y texture coordinate
  28. float m_flWidth;
  29. void SetColor( float r, float g, float b, float a )
  30. {
  31. // Specify the points.
  32. Assert( IsFinite(r) && IsFinite(g) && IsFinite(b) && IsFinite(a) );
  33. Assert( (r >= 0.0) && (g >= 0.0) && (b >= 0.0) && (a >= 0.0) );
  34. Assert( (r <= 1.0) && (g <= 1.0) && (b <= 1.0) && (a <= 1.0) );
  35. m_color.r = FastFToC( r );
  36. m_color.g = FastFToC( g );
  37. m_color.b = FastFToC( b );
  38. m_color.a = FastFToC( a );
  39. }
  40. void SetColor( float r, float g, float b )
  41. {
  42. // Specify the points.
  43. Assert( IsFinite(r) && IsFinite(g) && IsFinite(b) );
  44. Assert( (r >= 0.0) && (g >= 0.0) && (b >= 0.0) );
  45. Assert( (r <= 1.0) && (g <= 1.0) && (b <= 1.0) );
  46. m_color.r = FastFToC( r );
  47. m_color.g = FastFToC( g );
  48. m_color.b = FastFToC( b );
  49. }
  50. void SetAlpha( float a )
  51. {
  52. // Specify the points.
  53. Assert( IsFinite(a) );
  54. Assert( (a >= 0.0) );
  55. Assert( (a <= 1.0) );
  56. m_color.a = FastFToC( a );
  57. }
  58. void SetColor( const Vector &vecColor, float a )
  59. {
  60. SetColor( vecColor.x, vecColor.y, vecColor.z, a );
  61. }
  62. void SetColor( const Vector4D &vecColor )
  63. {
  64. SetColor( vecColor.x, vecColor.y, vecColor.z, vecColor.w );
  65. }
  66. void SetColor( const Vector &vecColor )
  67. {
  68. SetColor( vecColor.x, vecColor.y, vecColor.z );
  69. }
  70. void GetColor( Vector4D *pColor )
  71. {
  72. pColor->x = m_color.r / 255.0f;
  73. pColor->y = m_color.g / 255.0f;
  74. pColor->z = m_color.b / 255.0f;
  75. pColor->w = m_color.a / 255.0f;
  76. }
  77. void GetColor( Vector *pColor )
  78. {
  79. pColor->x = m_color.r / 255.0f;
  80. pColor->y = m_color.g / 255.0f;
  81. pColor->z = m_color.b / 255.0f;
  82. }
  83. };
  84. struct BeamSegRenderInfo_t
  85. {
  86. Vector m_vecPoint1;
  87. Vector m_vecPoint2;
  88. Vector m_vecCenter;
  89. Vector m_vecTangentS;
  90. Vector m_vecTangentT;
  91. float m_flTexCoord;
  92. color32 m_color;
  93. };
  94. class CBeamSegDraw
  95. {
  96. public:
  97. CBeamSegDraw() : m_pRenderContext( NULL ) {}
  98. // Pass null for pMaterial if you have already set the material you want.
  99. void Start( IMatRenderContext *pRenderContext, int nSegs, IMaterial *pMaterial=0, CMeshBuilder *pMeshBuilder = NULL, int nMeshVertCount = 0 );
  100. void ComputeRenderInfo( BeamSegRenderInfo_t *pRenderInfo, const Vector &vecCameraPos, int nSegCount, const BeamSeg_t *pSegs ) RESTRICT;
  101. virtual void NextSeg( BeamSeg_t *pSeg );
  102. void End();
  103. protected:
  104. void SpecifySeg( const Vector &vecCameraPos, const Vector &vNextPos );
  105. void ComputeNormal( const Vector &vecCameraPos, const Vector &vStartPos, const Vector &vNextPos, Vector *pNormal );
  106. static void LoadSIMDData( FourVectors *pV4StartPos, FourVectors *pV4EndPos, FourVectors *pV4HalfWidth, int nSegCount, const BeamSeg_t *pSegs );
  107. CMeshBuilder *m_pMeshBuilder;
  108. int m_nMeshVertCount;
  109. CMeshBuilder m_Mesh;
  110. BeamSeg_t m_Seg;
  111. int m_nTotalSegs;
  112. int m_nSegsDrawn;
  113. Vector m_vNormalLast;
  114. IMatRenderContext *m_pRenderContext;
  115. Vector m_vecCameraPos;
  116. };
  117. class CBeamSegDrawArbitrary : public CBeamSegDraw
  118. {
  119. public:
  120. void SetNormal( const Vector &normal );
  121. void NextSeg( BeamSeg_t *pSeg );
  122. protected:
  123. void SpecifySeg( const Vector &vNextPos );
  124. BeamSeg_t m_PrevSeg;
  125. };
  126. #if 0
  127. int ScreenTransform( const Vector& point, Vector& screen );
  128. void DrawSegs( int noise_divisions, float *prgNoise, const model_t* spritemodel,
  129. float frame, int rendermode, const Vector& source, const Vector& delta,
  130. float startWidth, float endWidth, float scale, float freq, float speed, int segments,
  131. int flags, float* color, float fadeLength, float flHDRColorScale = 1.0f );
  132. void DrawTeslaSegs( int noise_divisions, float *prgNoise, const model_t* spritemodel,
  133. float frame, int rendermode, const Vector& source, const Vector& delta,
  134. float startWidth, float endWidth, float scale, float freq, float speed, int segments,
  135. int flags, float* color, float fadeLength, float flHDRColorScale = 1.0f );
  136. void DrawSplineSegs( int noise_divisions, float *prgNoise,
  137. const model_t* beammodel, const model_t* halomodel, float flHaloScale,
  138. float frame, int rendermode, int numAttachments, Vector* attachment,
  139. float startWidth, float endWidth, float scale, float freq, float speed, int segments,
  140. int flags, float* color, float fadeLength, float flHDRColorScale = 1.0f );
  141. void DrawHalo(IMaterial* pMaterial, const Vector& source, float scale, float const* color, float flHDRColorScale = 1.0f );
  142. void BeamDrawHalo( const model_t* spritemodel, float frame, int rendermode, const Vector& source,
  143. float scale, float* color, float flHDRColorScale = 1.0f );
  144. void DrawDisk( int noise_divisions, float *prgNoise, const model_t* spritemodel,
  145. float frame, int rendermode, const Vector& source, const Vector& delta,
  146. float width, float scale, float freq, float speed,
  147. int segments, float* color, float flHDRColorScale = 1.0f );
  148. void DrawCylinder( int noise_divisions, float *prgNoise, const model_t* spritemodel,
  149. float frame, int rendermode, const Vector& source,
  150. const Vector& delta, float width, float scale, float freq,
  151. float speed, int segments, float* color, float flHDRColorScale = 1.0f );
  152. void DrawRing( int noise_divisions, float *prgNoise, void (*pfnNoise)( float *noise, int divs, float scale ),
  153. const model_t* spritemodel, float frame, int rendermode,
  154. const Vector& source, const Vector& delta, float width, float amplitude,
  155. float freq, float speed, int segments, float* color, float flHDRColorScale = 1.0f );
  156. void DrawBeamFollow( const model_t* spritemodel, BeamTrail_t* pHead, int frame, int rendermode, Vector& delta,
  157. Vector& screen, Vector& screenLast, float die, const Vector& source,
  158. int flags, float width, float amplitude, float freq, float* color, float flHDRColorScale = 1.0f );
  159. void DrawBeamQuadratic( const Vector &start, const Vector &control, const Vector &end, float width, const Vector &color, float scrollOffset, float flHDRColorScale = 1.0f );
  160. #endif
  161. //-----------------------------------------------------------------------------
  162. // Assumes the material has already been bound
  163. //-----------------------------------------------------------------------------
  164. void DrawSprite( const Vector &vecOrigin, float flWidth, float flHeight, color32 color );
  165. #endif // BEAMDRAW_H