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.

186 lines
5.1 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef CLIPPER3D_H
  8. #define CLIPPER3D_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "MapClass.h" // For CMapObjectList
  13. #include "Tool3D.h"
  14. #include "ToolInterface.h"
  15. #include "Render2D.h"
  16. #include "MapFace.h"
  17. class CMapSolid;
  18. //=============================================================================
  19. //
  20. // CClipGroup
  21. //
  22. class CClipGroup
  23. {
  24. public:
  25. enum { FRONT = 0, BACK };
  26. inline CClipGroup();
  27. ~CClipGroup();
  28. inline void SetOrigSolid( CMapSolid *pSolid );
  29. inline CMapSolid *GetOrigSolid( void );
  30. inline void SetClipSolid( CMapSolid *pSolid, int side );
  31. inline CMapSolid *GetClipSolid( int side );
  32. private:
  33. CMapSolid *m_pOrigSolid;
  34. CMapSolid *m_pClipSolids[2]; // front, back
  35. };
  36. //-----------------------------------------------------------------------------
  37. //-----------------------------------------------------------------------------
  38. inline CClipGroup::CClipGroup()
  39. {
  40. m_pOrigSolid = NULL;
  41. m_pClipSolids[0] = NULL;
  42. m_pClipSolids[1] = NULL;
  43. }
  44. //-----------------------------------------------------------------------------
  45. //-----------------------------------------------------------------------------
  46. inline void CClipGroup::SetOrigSolid( CMapSolid *pSolid )
  47. {
  48. m_pOrigSolid = pSolid;
  49. }
  50. //-----------------------------------------------------------------------------
  51. //-----------------------------------------------------------------------------
  52. inline CMapSolid *CClipGroup::GetOrigSolid( void )
  53. {
  54. return m_pOrigSolid;
  55. }
  56. //-----------------------------------------------------------------------------
  57. //-----------------------------------------------------------------------------
  58. inline void CClipGroup::SetClipSolid( CMapSolid *pSolid, int side )
  59. {
  60. m_pClipSolids[side] = pSolid;
  61. }
  62. //-----------------------------------------------------------------------------
  63. //-----------------------------------------------------------------------------
  64. inline CMapSolid *CClipGroup::GetClipSolid( int side )
  65. {
  66. return m_pClipSolids[side];
  67. }
  68. class Clipper3D : public Tool3D
  69. {
  70. friend BOOL AddToClipList( CMapSolid *pSolid, Clipper3D *pClipper );
  71. public:
  72. enum { FRONT = 0, BACK, BOTH };
  73. Clipper3D();
  74. ~Clipper3D();
  75. void IterateClipMode( void );
  76. inline void ToggleMeasurements( void );
  77. //
  78. // Tool3D implementation.
  79. //
  80. virtual int HitTest( CMapView *pView, const Vector2D &vPoint, bool bTestHandles = false );
  81. virtual unsigned int GetConstraints(unsigned int nKeyFlags);
  82. //
  83. // CBaseTool implementation.
  84. //
  85. virtual void OnActivate();
  86. virtual void OnDeactivate();
  87. virtual ToolID_t GetToolID(void) { return TOOL_CLIPPER; }
  88. virtual void RenderTool2D(CRender2D *pRender);
  89. virtual void RenderTool3D(CRender3D *pRender);
  90. virtual bool OnKeyDown2D(CMapView2D *pView, UINT nChar, UINT nRepCnt, UINT nFlags);
  91. virtual bool OnKeyDown3D(CMapView3D *pView, UINT nChar, UINT nRepCnt, UINT nFlags);
  92. virtual bool OnLMouseDown2D(CMapView2D *pView, UINT nFlags, const Vector2D &vPoint);
  93. virtual bool OnLMouseUp2D(CMapView2D *pView, UINT nFlags, const Vector2D &vPoint);
  94. virtual bool OnMouseMove2D(CMapView2D *pView, UINT nFlags, const Vector2D &vPoint);
  95. protected:
  96. //
  97. // Tool3D implementation.
  98. //
  99. virtual bool UpdateTranslation( const Vector &vUpdate, UINT uFlags = 0 );
  100. virtual void FinishTranslation( bool bSave );
  101. private:
  102. void OnEscape(void);
  103. void SetClipObjects( const CMapObjectList *pList );
  104. void SetClipPlane( PLANE *pPlane );
  105. void BuildClipPlane( void );
  106. void SaveClipResults( void );
  107. void GetClipResults( void );
  108. void CalcClipResults( void );
  109. void ResetClipResults( void );
  110. void RemoveOrigSolid( CMapSolid *pOrigSolid );
  111. void SaveClipSolid( CMapSolid *pSolid, CMapSolid *pOrigSolid );
  112. void DrawBrushExtents(CRender2D *pRender, CMapSolid *pSolid, int nFlags);
  113. int m_Mode; // current clipping mode { back, front, both }
  114. PLANE m_ClipPlane; // the clipping plane -- front/back is uneccesary
  115. Vector m_ClipPoints[2]; // 2D clipping points -- used to create the clip plane
  116. int m_ClipPointHit; // the clipping that was "hit" {0, 1, -1}
  117. Vector m_vOrgPos;
  118. const CMapObjectList *m_pOrigObjects; // list of the initial objects to clip
  119. CUtlVector<CClipGroup*> m_ClipResults; // list of clipped objects
  120. bool m_bDrawMeasurements; // Whether to draw brush dimensions in the 2D view.
  121. CRender2D m_Render2D; // 2d renderer
  122. };
  123. //-----------------------------------------------------------------------------
  124. // Purpose: Toggles the clipper's rendering of brush measurements in the 2D view.
  125. //-----------------------------------------------------------------------------
  126. inline void Clipper3D::ToggleMeasurements( void )
  127. {
  128. m_bDrawMeasurements = !m_bDrawMeasurements;
  129. m_pDocument->UpdateAllViews( MAPVIEW_UPDATE_TOOL );
  130. }
  131. #endif // CLIPPER3D_H