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.

284 lines
9.7 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef MAPOVERLAY_H
  8. #define MAPOVERLAY_H
  9. #pragma once
  10. #include <afxwin.h>
  11. #include "UtlVector.h"
  12. #include "MapSideList.h"
  13. class CHelperInfo;
  14. class CMapFace;
  15. class CRender3D;
  16. class CMapView;
  17. class IEditorTexture;
  18. #define OVERLAY_HANDLES_COUNT 4
  19. #define NUM_CLIPFACE_TEXCOORDS 2
  20. #define OVERLAY_TYPE_GENERIC 0x01
  21. #define OVERLAY_TYPE_SHORE 0x02
  22. //=============================================================================
  23. //
  24. // Class Map Overlay
  25. //
  26. class CMapOverlay : public CMapSideList
  27. {
  28. public:
  29. DECLARE_MAPCLASS( CMapOverlay, CMapSideList );
  30. // Construction/Deconstruction.
  31. CMapOverlay();
  32. ~CMapOverlay();
  33. // Factory for building from a list of string parameters.
  34. static CMapClass *CreateMapOverlay( CHelperInfo *pInfo, CMapEntity *pParent );
  35. // Virtual/Interface Implementation.
  36. virtual void PostloadWorld( CMapWorld *pWorld );
  37. virtual CMapClass *Copy( bool bUpdateDependencies );
  38. virtual CMapClass *CopyFrom( CMapClass *pObject, bool bUpdateDependencies );
  39. void CalcBounds( BOOL bFullUpdate = FALSE );
  40. virtual void OnParentKeyChanged( const char* szKey, const char* szValue );
  41. virtual void OnNotifyDependent( CMapClass *pObject, Notify_Dependent_t eNotifyType );
  42. void DoTransform( const VMatrix &matrix );
  43. void OnPaste( CMapClass *pCopy, CMapWorld *pSourceWorld, CMapWorld *pDestWorld,
  44. const CMapObjectList &OriginalList, CMapObjectList &NewList);
  45. void OnClone( CMapClass *pClone, CMapWorld *pWorld,
  46. const CMapObjectList &OriginalList, CMapObjectList &NewList );
  47. void OnUndoRedo( void );
  48. void Render3D( CRender3D *pRender );
  49. // Overlay.
  50. void HandlesReset( void );
  51. bool HandlesHitTest( CMapView *pView, const Vector2D &vPoint );
  52. void HandlesDragTo( Vector &vecImpact, CMapFace *pFace );
  53. void HandleMoveTo( int iHandle, Vector &vecPoint, CMapFace *pFace );
  54. void SetTexCoords( Vector2D vecTexCoords[4] );
  55. void GetHandlePos( int iHandle, Vector &vecPos );
  56. bool IsSelected( void ) { return ( GetSelectionState() == SELECT_NORMAL ); }
  57. void DoClip( void );
  58. void CenterEntity( void );
  59. void GetPlane( cplane_t &plane );
  60. int GetFaceCount( void ) { return m_Faces.Count(); }
  61. CMapFace *GetFace( int iFace ) { return m_Faces.Element( iFace ); }
  62. void SetMaterial( const char *szMaterialName );
  63. void SetMaterial( IEditorTexture *pTexture ) { m_Material.m_pTexture = pTexture; }
  64. IEditorTexture* GetMaterial() { return m_Material.m_pTexture; }
  65. // Creation.
  66. void Basis_Init( CMapFace *pFace );
  67. void Handles_Init( CMapFace *pFace );
  68. void SideList_Init( CMapFace *pFace );
  69. void SideList_AddFace( CMapFace *pFace );
  70. void SetLoaded( bool bLoaded ) { m_bLoaded = bLoaded; }
  71. // Attributes.
  72. inline virtual bool IsVisualElement( void ) { return true; }
  73. inline virtual bool ShouldRenderLast( void ) { return true; }
  74. inline const char* GetDescription() { return ( "Overlay" ); }
  75. void SetOverlayType( unsigned short uiType ) { m_uiFlags |= uiType; }
  76. void ResetOverlayType( unsigned short uiType ) { m_uiFlags &= ~uiType; }
  77. unsigned short GetOverlayType( void ) { return m_uiFlags; }
  78. ChunkFileResult_t SaveDataToVMF( CChunkFile *pFile, CSaveInfo *pSaveInfo );
  79. private:
  80. //=========================================================================
  81. //
  82. // Basis Data
  83. //
  84. struct Basis_t
  85. {
  86. CMapFace *m_pFace; // Index to the face the basis were derived from
  87. Vector m_vecOrigin; // Origin of basis vectors (in plane)
  88. Vector m_vecAxes[3]; // Basis vectors
  89. int m_nAxesFlip[3]; // u, v, n flip values (3 bits x,y,z) - saved off the z components of the first 3 uv points
  90. };
  91. void Basis_Clear( void );
  92. void Basis_SetFace( CMapFace *pFace );
  93. void Basis_UpdateOrigin( void );
  94. void Basis_BuildAxes( void );
  95. void Basis_SetInitialUAxis( Vector const &vecNormal );
  96. bool Basis_IsValid( void );
  97. void Basis_Copy( Basis_t *pSrc, Basis_t *pDst );
  98. void Basis_UpdateParentKey( void );
  99. // Legacy support.
  100. void Basis_BuildFromSideList( void );
  101. void Basis_ToggleAxesFlip( int iAxis, int iComponent );
  102. bool Basis_IsFlipped( int iAxis, int iComponent );
  103. //=========================================================================
  104. //
  105. // Handle Data
  106. //
  107. struct Handles_t
  108. {
  109. int m_iHit; // Index of the selected handle
  110. Vector2D m_vecBasisCoords[OVERLAY_HANDLES_COUNT]; // U,V coordinates of the 4 corners in the editable plane (use basis)
  111. Vector m_vec3D[OVERLAY_HANDLES_COUNT]; // World space handles for snap testing
  112. };
  113. void Handles_Clear( void );
  114. void Handles_Build3D();
  115. void Handles_Render3D( CRender3D *pRender );
  116. void Handles_SurfToOverlayPlane( CMapFace *pFace, Vector const &vSurf, Vector &vPoint );
  117. void Handles_Copy( Handles_t *pSrc, Handles_t *pDst );
  118. void Handles_UpdateParentKey( void );
  119. void Handles_FixOrder();
  120. //=========================================================================
  121. //
  122. // ClipFace Data
  123. //
  124. struct BlendData_t
  125. {
  126. void Init()
  127. {
  128. m_nType = 0;
  129. memset(m_iPoints, 0, sizeof(m_iPoints));
  130. memset(m_flBlends, 0, sizeof(m_flBlends));
  131. }
  132. int m_nType; // type of blend (point, edge, barycentric)
  133. short m_iPoints[3]; // displacement point indices
  134. float m_flBlends[3]; // blending values
  135. };
  136. struct ClipFace_t
  137. {
  138. CMapFace *m_pBuildFace;
  139. int m_nPointCount;
  140. CUtlVector<Vector> m_aPoints;
  141. CUtlVector<Vector> m_aDispPointUVs; // z is always 0 (need to be this way to share functions!)
  142. CUtlVector<Vector> m_aNormals;
  143. CUtlVector<Vector2D> m_aTexCoords[NUM_CLIPFACE_TEXCOORDS];
  144. CUtlVector<BlendData_t> m_aBlends;
  145. ClipFace_t()
  146. {
  147. m_pBuildFace = NULL;
  148. m_nPointCount = 0;
  149. }
  150. ~ClipFace_t()
  151. {
  152. m_aPoints.Purge();
  153. m_aDispPointUVs.Purge();
  154. m_aBlends.Purge();
  155. m_aNormals.Purge();
  156. for ( int iCoord = 0; iCoord < NUM_CLIPFACE_TEXCOORDS; ++iCoord )
  157. {
  158. m_aTexCoords[iCoord].Purge();
  159. }
  160. }
  161. };
  162. typedef CUtlVector<ClipFace_t*> ClipFaces_t;
  163. ClipFace_t *ClipFace_Create( int nSize );
  164. void ClipFace_Destroy( ClipFace_t **ppClipFace );
  165. ClipFace_t *ClipFace_Copy( ClipFace_t *pSrc );
  166. void ClipFace_GetBounds( ClipFace_t *pClipFace, Vector &vecMin, Vector &vecMax );
  167. void ClipFace_Clip( ClipFace_t *pClipFace, cplane_t *pClipPlane, float flEpsilon, ClipFace_t **ppFront, ClipFace_t **ppBack );
  168. void ClipFace_ClipBarycentric( ClipFace_t *pClipFace, cplane_t *pClipPlane, float flEpsilon, int iClip, CMapDisp *pDisp, ClipFace_t **ppFront, ClipFace_t **ppBack );
  169. void ClipFace_PreClipDisp( ClipFace_t *pClipFace, CMapDisp *pDisp );
  170. void ClipFace_PostClipDisp( void );
  171. void ClipFace_ResolveBarycentricClip( CMapDisp *pDisp, ClipFace_t *pClipFace, int iClipFacePoint, const Vector2D &vecPointUV, float *pCoefs, int *pTris, Vector2D *pVertsUV );
  172. bool ClipFace_CalcBarycentricCooefs( CMapDisp *pDisp, Vector2D *pVertsUV, const Vector2D &vecPointUV, float *pCoefs );
  173. int ClipFace_GetAxisType( cplane_t *pClipPlane );
  174. void ClipFace_BuildBlend( ClipFace_t *pClipFace, CMapDisp *pDisp, cplane_t *pClipPlane, int iClip, const Vector &vecUV, const Vector &vecPoint );
  175. void ClipFace_CopyBlendFrom( ClipFace_t *pClipFace, BlendData_t *pBlendFrom );
  176. void ClipFace_BuildFacesFromBlendedData( ClipFace_t *pClipFace );
  177. //=========================================================================
  178. //
  179. // Material Functions
  180. //
  181. struct Material_t
  182. {
  183. IEditorTexture *m_pTexture; // material
  184. Vector2D m_vecTextureU; // material starting and ending U
  185. Vector2D m_vecTextureV; // material starting and ending V
  186. };
  187. void Material_Clear( void );
  188. void Material_Copy( Material_t *pSrc, Material_t *pDst );
  189. void Material_TexCoordInit( void );
  190. void Material_UpdateParentKey( void );
  191. //=========================================================================
  192. //
  193. // Clipping
  194. //
  195. void PreClip( void );
  196. void PostClip( void );
  197. void DoClipFace( CMapFace *pFace );
  198. void DoClipDisp( CMapFace *pFace, ClipFace_t *pClippedFace );
  199. void DoClipDispInV( CMapDisp *pDisp, ClipFaces_t &aCurrentFaces );
  200. void DoClipDispInU( CMapDisp *pDisp, ClipFaces_t &aCurrentFaces );
  201. void DoClipDispInUVFromTLToBR( CMapDisp *pDisp, ClipFaces_t &aCurrentFaces );
  202. void DoClipDispInUVFromBLToTR( CMapDisp *pDisp, ClipFaces_t &aCurrentFaces );
  203. void Disp_ClipFragments( CMapDisp *pDisp, ClipFaces_t &aDispFragments );
  204. void Disp_DoClip( CMapDisp *pDisp, ClipFaces_t &aDispFragments, cplane_t &clipPlane, float clipDistStart, int nInterval, int nLoopStart, int nLoopEnd, int nLoopInc );
  205. //==========================================================================
  206. //
  207. // Transform
  208. //
  209. // Utility
  210. void OverlayUVToOverlayPlane( const Vector2D &vecUV, Vector &vecPoint );
  211. void OverlayPlaneToOverlayUV( const Vector &vecPoint, Vector2D &vecUV );
  212. void WorldToOverlayPlane( const Vector &vecWorld, Vector &vecPoint );
  213. void OverlayPlaneToWorld( CMapFace *pFace, const Vector &vecPlane, Vector &vecWorld );
  214. void OverlayPlaneToSurfFromList( const Vector &vecOverlayPoint, Vector &vecSurfPoint );
  215. bool EntityOnSurfFromListToBaseFacePlane( const Vector &vecWorldPoint, Vector &vecBasePoint );
  216. bool BuildEdgePlanes( Vector const *pPoints, int pointCount, cplane_t *pEdgePlanes, int edgePlaneCount );
  217. void UpdateDispBarycentric( void );
  218. void PostModified( void );
  219. void GetTriVerts( CMapDisp *pDisp, const Vector2D &vecSurfUV, int *pTris, Vector2D *pVertsUV );
  220. private:
  221. Basis_t m_Basis; // Overlay Basis Data
  222. Handles_t m_Handles; // Overlay Handle Data
  223. Material_t m_Material; // Overlay Material
  224. ClipFace_t *m_pOverlayFace; // Primary Overlay
  225. ClipFaces_t m_aRenderFaces; // Clipped Face Cache (Render Faces)
  226. unsigned short m_uiFlags; //
  227. bool m_bLoaded;
  228. };
  229. #endif // MAPOVERLAY_H