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.

131 lines
2.6 KiB

  1. //========= Copyright � 2009, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Defines the regular grid nav as required by DOTA. Builds, renders,
  4. // and saves out the nav. Traversable edges and cells are determined by
  5. // picking into the world.
  6. //
  7. //=============================================================================//
  8. #ifndef GRIDNAV_H
  9. #define GRIDNAV_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. class CRender3D;
  14. class CMapDoc;
  15. #include "mathlib/vector.h"
  16. #include "utlvector.h"
  17. class CGridNavCell
  18. {
  19. public:
  20. inline CGridNavCell();
  21. bool m_bTraversable;
  22. int m_nGridPosX;
  23. int m_nGridPosY;
  24. float m_flHeight;
  25. };
  26. class CGridNav
  27. {
  28. public:
  29. CGridNav();
  30. inline static bool IsEnabled();
  31. inline bool IsPreviewActive();
  32. inline void TogglePreview();
  33. static void Init( bool enabled, float flEdgeSize = 0.0f, float flOffsetX = 0.0f, float flOffsetY = 0.0f, float flTraceHeight = 0.0f );
  34. void Render( CRender3D *pRender, const Vector &vViewPos, const Vector &vViewDir );
  35. void Update( CMapDoc *pMapDoc, const Vector &vViewPos, const Vector &vViewDir );
  36. void GenerateGridNavFile( const char *pFileFullPath );
  37. inline int CoordToGridPosX( float flCoordX ) const;
  38. inline int CoordToGridPosY( float flCoordY ) const;
  39. inline float GridPosXToCoordCenter( int nGridPosX ) const;
  40. inline float GridPosYToCoordCenter( int nGridPosY ) const;
  41. private:
  42. static bool sm_bEnabled;
  43. static float sm_flEdgeSize;
  44. static float sm_flOffsetX;
  45. static float sm_flOffsetY;
  46. static float sm_flTraceHeight;
  47. Vector m_vLatestCameraPos;
  48. Vector m_vLatestCameraDir;
  49. bool m_bNeedsCameraRecompute;
  50. float m_flTimeCameraLastMoved;
  51. int m_nTicksCameraStill;
  52. CUtlVector< CGridNavCell > m_CurrentCells;
  53. bool m_bPreviewActive;
  54. };
  55. ////////////////////
  56. bool CGridNav::IsEnabled()
  57. {
  58. return sm_bEnabled;
  59. }
  60. bool CGridNav::IsPreviewActive()
  61. {
  62. return m_bPreviewActive;
  63. }
  64. void CGridNav::TogglePreview()
  65. {
  66. m_bPreviewActive = !m_bPreviewActive;
  67. }
  68. int CGridNav::CoordToGridPosX( float flCoordX ) const
  69. {
  70. return (int)floor( ( ( flCoordX - sm_flOffsetX ) + ( sm_flEdgeSize * 0.5f ) ) / sm_flEdgeSize );
  71. }
  72. int CGridNav::CoordToGridPosY( float flCoordY ) const
  73. {
  74. return (int)floor( ( ( flCoordY - sm_flOffsetY ) + ( sm_flEdgeSize * 0.5f ) ) / sm_flEdgeSize );
  75. }
  76. float CGridNav::GridPosXToCoordCenter( int nGridPosX ) const
  77. {
  78. return ( ( (float)(nGridPosX) ) * sm_flEdgeSize ) + sm_flOffsetX;
  79. }
  80. float CGridNav::GridPosYToCoordCenter( int nGridPosY ) const
  81. {
  82. return ( ( (float)(nGridPosY) ) * sm_flEdgeSize ) + sm_flOffsetY;
  83. }
  84. CGridNavCell::CGridNavCell()
  85. : m_bTraversable( false )
  86. , m_nGridPosX( 0 )
  87. , m_nGridPosY( 0 )
  88. , m_flHeight( 0.0f )
  89. {
  90. }
  91. #endif // GRIDNAV_H