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.

964 lines
34 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //-----------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #ifndef MAPDISP_H
  14. #define MAPDISP_H
  15. #pragma once
  16. //=============================================================================
  17. #pragma warning(push, 1)
  18. #pragma warning(disable:4701 4702 4530)
  19. #include <fstream>
  20. #pragma warning(pop)
  21. #include <UtlVector.h>
  22. #include "MapAtom.h"
  23. #include "Render3D.h"
  24. #include "mathlib/VMatrix.h"
  25. #include "DispMapImageFilter.h"
  26. #include "builddisp.h"
  27. #include "DispManager.h"
  28. class CChunkFile;
  29. class CMapClass;
  30. class CMapFace;
  31. class CSaveInfo;
  32. class IWorldEditDispMgr;
  33. class CToolDisplace;
  34. class Color;
  35. class CSelection;
  36. struct Shoreline_t;
  37. struct ExportDXFInfo_s;
  38. enum ChunkFileResult_t;
  39. // Painting Defines
  40. #define DISPPAINT_CHANNEL_POSITION 0
  41. #define DISPPAINT_CHANNEL_ALPHA 1
  42. #define WALKABLE_NORMAL_VALUE 0.7f
  43. #define BUILDABLE_NORMAL_VALUE 0.8f
  44. //=============================================================================
  45. //
  46. // Displacement Map Class
  47. //
  48. class CMapDisp : public CMapAtom
  49. {
  50. private:
  51. typedef struct
  52. {
  53. Vector min;
  54. Vector max;
  55. } BBox_t;
  56. typedef struct
  57. {
  58. Vector normal;
  59. float dist;
  60. } Plane_t;
  61. typedef struct
  62. {
  63. Vector v[3];
  64. } Tri_t;
  65. public:
  66. enum { MAPDISP_MAX_VERTS = 289 }; // 17x17
  67. enum { MAPDISP_MAX_FACES = 512 }; // ( 16x16 ) x 2
  68. enum { MAPDISP_MAX_NEIGHBORS = 8 }; // 4 edges + 4 corners -- always four-sided
  69. //=========================================================================
  70. //
  71. // Constructor/Deconstructor (Initialization)
  72. //
  73. CMapDisp();
  74. ~CMapDisp();
  75. inline void SetEditHandle( EditDispHandle_t handle ) { m_EditHandle = handle; }
  76. inline EditDispHandle_t GetEditHandle( void ) { return m_EditHandle; }
  77. bool InitDispSurfaceData( CMapFace *pFace, bool bGenerateStartPoint );
  78. void ResetFieldData( void );
  79. void InitData( int power );
  80. // void InitData( int power, int minTess, float smoothingAngle, Vector **dispVectorField, Vector **dispVectorOffset, float *dispDistances );
  81. //=========================================================================
  82. //
  83. // Creation, Copy
  84. //
  85. bool Create( void );
  86. CMapDisp *CopyFrom( CMapDisp *pMapDisp, bool bUpdateDependencies );
  87. //=========================================================================
  88. //
  89. // Update/Modification/Editing Functions
  90. //
  91. void UpdateSurfData( CMapFace *pFace );
  92. void UpdateSurfDataAndVectorField( CMapFace *pFace );
  93. void UpdateData( void );
  94. void UpdateDataAndNeighborData( void );
  95. void InvertAlpha( void );
  96. void Resample( int power );
  97. void Elevate( float elevation );
  98. bool TraceLine( Vector &HitPos, Vector &HitNormal, Vector const &RayStart, Vector const &RayEnd );
  99. bool TraceLineSnapTo( Vector &HitPos, Vector &HitNormal, Vector const &RayStart, Vector const &RayEnd );
  100. void DoTransform(const VMatrix &matrix);
  101. void ApplyNoise( float min, float max, float rockiness );
  102. bool PointSurfIntersection( Vector const &ptCenter, float radius, float &distMin, Vector &ptMin );
  103. void Split( EditDispHandle_t hBuilderDisp );
  104. void UpdateWalkable( void );
  105. void UpdateBuildable( void );
  106. void CreateShoreOverlays( CMapFace *pFace, Shoreline_t *pShoreline );
  107. virtual void PostUpdate(Notify_Dependent_t eNotifyType);
  108. //=========================================================================
  109. //
  110. // Attributes
  111. //
  112. inline void SetPower( int power );
  113. inline int GetPower( void );
  114. inline int CalcPower( int width );
  115. inline int GetSize( void );
  116. inline int GetWidth( void );
  117. inline int GetHeight( void );
  118. inline int TriangleCount() { return 2 * (GetWidth() - 1) * (GetHeight() - 1); }
  119. inline void SetElevation( float elevation );
  120. inline float GetElevation( void );
  121. void Scale( float scale );
  122. inline float GetScale( void );
  123. inline void GetBoundingBox( Vector& boxMin, Vector& boxMax );
  124. inline size_t GetDataSize( void );
  125. // flags
  126. inline bool IsTouched( void );
  127. inline void SetTouched( void );
  128. inline void ResetTouched( void );
  129. inline void SetHasMappingAxes( bool value );
  130. inline void SetSubdivided( bool bSubdiv );
  131. inline bool IsSubdivided( void );
  132. inline void SetReSubdivision( bool bReSubdiv );
  133. inline bool NeedsReSubdivision( void );
  134. //=========================================================================
  135. //
  136. // Base Surface Data
  137. //
  138. inline void GetSurfPoint( int index, Vector& pt );
  139. inline void GetSurfNormal( Vector& normal );
  140. inline int GetSurfPointStartIndex( void );
  141. inline void SetSurfPointStartIndex( int index );
  142. inline void GetSurfTexCoord( int ndx, Vector2D &texCoord );
  143. inline void SetSurfTexCoord( int ndx, Vector2D const &texCoord );
  144. inline int GetFlags( void ) { return m_CoreDispInfo.GetSurface()->GetFlags(); }
  145. inline void SetFlags( int nFlags ) { m_CoreDispInfo.GetSurface()->SetFlags( nFlags ); }
  146. inline bool CheckFlags( int nFlags ) { return ( ( nFlags & GetFlags() ) != 0 ) ? true : false; }
  147. //=========================================================================
  148. //
  149. // Surface Data
  150. //
  151. inline void SetVert( int index, Vector const &v );
  152. inline void GetVert( int index, Vector& v );
  153. inline void SetAlpha( int index, float alpha );
  154. inline float GetAlpha( int index );
  155. inline void GetFlatVert( int index, Vector& v );
  156. inline void SetFlatVert( int index, const Vector &v );
  157. inline void GetMultiBlend( int index, Vector4D &vBlend, Vector4D &vAlphaBlend, Vector &vColor1, Vector &vColor2, Vector &vColor3, Vector &vColor4 );
  158. inline void SetMultiBlend( int index, Vector4D &vBlend, Vector4D &vAlphaBlend, Vector &vColor1, Vector &vColor2, Vector &vColor3, Vector &vColor4 );
  159. inline void ResetFieldVectors( void );
  160. inline void SetFieldVector( int index, Vector const &v );
  161. inline void GetFieldVector( int index, Vector& v );
  162. inline void ResetFieldDistances( void );
  163. inline void SetFieldDistance( int index, float distance );
  164. inline float GetFieldDistance( int index );
  165. inline void ResetSubdivPositions( void );
  166. inline void SetSubdivPosition( int ndx, Vector const &v );
  167. inline void GetSubdivPosition( int ndx, Vector& v );
  168. inline void ResetSubdivNormals( void );
  169. inline void SetSubdivNormal( int ndx, Vector const &v );
  170. inline void GetSubdivNormal( int ndx, Vector &v );
  171. inline int GetTriCount( void ) { return m_CoreDispInfo.GetTriCount(); }
  172. inline void GetTriIndices( int iTri, unsigned short &v1, unsigned short &v2, unsigned short &v3 ) { m_CoreDispInfo.GetTriIndices( iTri, v1, v2, v3 ); }
  173. inline void GetTriPos( int iTri, Vector &v1, Vector &v2, Vector &v3 ) { m_CoreDispInfo.GetTriPos( iTri, v1, v2, v3 ); }
  174. inline void SetTriTag( int iTri, unsigned short nTag ) { m_CoreDispInfo.SetTriTag( iTri, nTag ); }
  175. inline void ResetTriTag( int iTri, unsigned short nTag ) { m_CoreDispInfo.ResetTriTag( iTri, nTag ); }
  176. inline void ToggleTriTag( int iTri, unsigned short nTag ) { m_CoreDispInfo.ToggleTriTag( iTri, nTag ); }
  177. inline bool IsTriTag( int iTri, unsigned short nTag ) { return m_CoreDispInfo.IsTriTag( iTri, nTag ); }
  178. inline bool IsTriWalkable( int iTri ) { return m_CoreDispInfo.IsTriWalkable( iTri ); }
  179. inline bool IsTriBuildable( int iTri ) { return m_CoreDispInfo.IsTriBuildable( iTri ); }
  180. int CollideWithDispTri( const Vector &rayStart, const Vector &rayEnd, float &flFraction, bool OneSided = false );
  181. //=========================================================================
  182. //
  183. // Neighbors
  184. //
  185. void UpdateNeighborDependencies( bool bDestroy );
  186. static void UpdateNeighborsOfDispsIntersectingBox( const Vector &bbMin, const Vector &bbMax, float flPadding );
  187. inline void SetEdgeNeighbor( int direction, EditDispHandle_t handle, int orient );
  188. inline void GetEdgeNeighbor( int direction, EditDispHandle_t &handle, int &orient );
  189. inline EditDispHandle_t GetEdgeNeighbor( int direction );
  190. inline int GetCornerNeighborCount( int direction );
  191. inline void AddCornerNeighbor( int direction, EditDispHandle_t handle, int orient );
  192. inline void GetCornerNeighbor( int direction, int cornerIndex, EditDispHandle_t &handle, int &orient );
  193. inline EditDispHandle_t GetCornerNeighbor( int direction, int cornerIndex );
  194. // for lighting preview
  195. void AddShadowingTriangles( CUtlVector<Vector> &tri_list );
  196. //=========================================================================
  197. //
  198. // Rendering
  199. //
  200. void Render3D( CRender3D *pRender, bool bIsSelected, SelectionState_t faceSelectionState );
  201. void Render2D( CRender2D *pRender, bool bIsSelected, SelectionState_t faceSelectionState );
  202. static void SetSelectMask( bool bSelectMask );
  203. static bool HasSelectMask( void );
  204. static void SetGridMask( bool bGridMask );
  205. static bool HasGridMask( void );
  206. //=========================================================================
  207. //
  208. // Selection
  209. //
  210. inline void SetTexelHitIndex( int index );
  211. inline int GetTexelHitIndex( void );
  212. inline void ResetTexelHitIndex( void );
  213. inline void SetDispMapHitIndex( int index );
  214. inline void ResetDispMapHitIndex( void );
  215. EditDispHandle_t GetHitDispMap( void );
  216. //=========================================================================
  217. //
  218. // Paint Functions
  219. //
  220. void Paint_Init( int nType );
  221. void Paint_InitSelfAndNeighbors( int nType );
  222. void Paint_SetValue( int iVert, Vector const &vPaint );
  223. void Paint_Update( bool bSplit );
  224. void Paint_UpdateSelfAndNeighbors( bool bSplit );
  225. inline bool Paint_IsDirty( void );
  226. //=========================================================================
  227. //
  228. // Undo Functions (friends)
  229. //
  230. friend void EditDisp_ForUndo( EditDispHandle_t editHandle, char *pszPositionName, bool bNeighborsUndo );
  231. //=========================================================================
  232. //
  233. // Utility Functions
  234. //
  235. void DispUVToSurf( Vector2D const &dispUV, Vector &surfPt, Vector *pNormal, float *pAlpha ) { m_CoreDispInfo.DispUVToSurf( dispUV, surfPt, pNormal, pAlpha ); }
  236. void BaseFacePlaneToDispUV( Vector const &planePt, Vector2D &dispUV ) { m_CoreDispInfo.BaseFacePlaneToDispUV( planePt, dispUV ); }
  237. bool SurfToBaseFacePlane( Vector const &surfPt, Vector &planePt ) { return m_CoreDispInfo.SurfToBaseFacePlane( surfPt, planePt ); }
  238. CCoreDispInfo *GetCoreDispInfo( void ) { return &m_CoreDispInfo; }
  239. //=========================================================================
  240. //
  241. // Load/Save Functions
  242. //
  243. ChunkFileResult_t LoadVMF(CChunkFile *pFile);
  244. ChunkFileResult_t SaveVMF(CChunkFile *pFile, CSaveInfo *pSaveInfo);
  245. bool SerializedLoadMAP( std::fstream &file, CMapFace *pFace, UINT version );
  246. bool SerializedLoadRMF( std::fstream &file, CMapFace *pFace, float version );
  247. bool SaveDXF(ExportDXFInfo_s *pInfo);
  248. void PostLoad( void );
  249. void UpdateVertPositionForSubdiv( int iVert, const Vector &vecNewSubdivPos );
  250. private:
  251. enum { NUM_EDGES_CORNERS = 4 };
  252. enum { MAX_CORNER_NEIGHBORS = 4 };
  253. EditDispHandle_t m_EditHandle; // id of displacement in global manager's list
  254. CCoreDispInfo m_CoreDispInfo; // core displacement info
  255. int m_HitTexelIndex; // the displacement map texel that was "hit"
  256. int m_HitDispIndex; // the displacement map that was hit (this or one of its neighbors)
  257. Vector m_LightPosition;
  258. float m_LightColor[3];
  259. EditDispHandle_t m_EdgeNeighbors[NUM_EDGES_CORNERS]; // four possible edge neighbors (W, N, E, S)
  260. int m_EdgeNeighborOrientations[NUM_EDGES_CORNERS]; // neighbor edge orientations
  261. int m_CornerNeighborCounts[NUM_EDGES_CORNERS]; // number of corner neighbors (not counting edge neighbors)
  262. EditDispHandle_t m_CornerNeighbors[NUM_EDGES_CORNERS][MAX_CORNER_NEIGHBORS]; // four corners/multiple corner neighbors possible (SW, SE, NW, NE)
  263. int m_CornerNeighborOrientations[NUM_EDGES_CORNERS][MAX_CORNER_NEIGHBORS]; // neighbor corner orientations
  264. bool m_bHasMappingAxes;
  265. Vector m_MapAxes[2]; // for older files (.map, .rmf)
  266. Vector m_BBox[2]; // axial-aligned bounding box
  267. float m_Scale;
  268. static bool m_bSelectMask; // masks for the Displacement Tool (FaceEditSheet)
  269. static bool m_bGridMask;
  270. bool m_bSubdiv;
  271. bool m_bReSubdiv;
  272. CUtlVector<CoreDispVert_t*> m_aWalkableVerts;
  273. CUtlVector<unsigned short> m_aWalkableIndices;
  274. CUtlVector<unsigned short> m_aForcedWalkableIndices;
  275. CUtlVector<CoreDispVert_t*> m_aBuildableVerts;
  276. CUtlVector<unsigned short> m_aBuildableIndices;
  277. CUtlVector<unsigned short> m_aForcedBuildableIndices;
  278. // Painting Data.
  279. struct PaintCanvas_t
  280. {
  281. enum { CANVAS_SIZE = MAPDISP_MAX_VERTS };
  282. int m_nType; // what does the canvas hold - position, alpha, etc.
  283. Vector m_Values[CANVAS_SIZE];
  284. bool m_bValuesDirty[CANVAS_SIZE];
  285. bool m_bDirty;
  286. };
  287. PaintCanvas_t m_Canvas;
  288. int m_FoWTriSoupID;
  289. //=========================================================================
  290. //
  291. // Painting Functions
  292. //
  293. void PaintPosition_Update( int iVert );
  294. void PaintAlpha_Update( int iVert );
  295. //=========================================================================
  296. //
  297. // Update/Modification/Editing Functions
  298. //
  299. void UpSample( int oldPower );
  300. void DownSample( int oldPower );
  301. void GetValidSamplePoints( int index, int width, int height, bool *pValidPoints );
  302. void SamplePoints( int index, int width, int height, bool *pValidPoints, float *pValue, float *pAlpha,
  303. Vector& newDispVector, Vector& newSubdivPos, Vector &newSubdivNormal );
  304. void PostCreate( void );
  305. void UpdateBoundingBox( void );
  306. void UpdateLightmapExtents( void );
  307. bool ValidLightmapSize( void );
  308. void CheckAndUpdateOverlays( bool bFull );
  309. bool EntityInBoundingBox( Vector const &vOrigin );
  310. enum { FLIP_HORIZONTAL = 0,
  311. FLIP_VERTICAL,
  312. FLIP_TRANSPOSE };
  313. void Flip( int flipType );
  314. int GetAxisTypeBasedOnView( int majorAxis, int vertAxis, int horzAxis );
  315. int GetMajorAxis( Vector &v );
  316. //=========================================================================
  317. //
  318. // Collision Testing
  319. //
  320. void CreateBoundingBoxes( BBox_t *pBBox, int count, float bloat );
  321. void CreatePlanesFromBoundingBox( Plane_t *planes, const Vector& bbMin, const Vector& bbMax );
  322. void CollideWithBoundingBoxes( const Vector& rayStart, const Vector& rayEnd, BBox_t *pBBox, int bboxCount, Tri_t *pTris, int *triCount );
  323. float CollideWithTriangles( const Vector& RayStart, const Vector& RayEnd, Tri_t *pTris, int triCount, Vector& surfNormal );
  324. //=========================================================================
  325. //
  326. // Rendering
  327. //
  328. void RenderHitBox( CRender3D *pRender, bool bNudge );
  329. void RenderPaintSphere( CRender3D *pRender, CToolDisplace *pTool );
  330. void CalcColor( CRender3D *pRender, bool bIsSelected, SelectionState_t faceSelectionState, Color &pColor );
  331. void RenderSurface( CRender3D *pRender, bool bIsSelected, SelectionState_t faceSelectionState );
  332. void RenderOverlaySurface( CRender3D *pRender, bool bIsSelected, SelectionState_t faceSelectionState );
  333. void RenderWalkableSurface( CRender3D *pRender, bool bIsSelected, SelectionState_t faceSelectionState );
  334. void RenderBuildableSurface( CRender3D *pRender, bool bIsSelected, SelectionState_t faceSelectionState );
  335. void RenderWireframeSurface( CRender3D *pRender, bool bIsSelected, SelectionState_t faceSelectionState );
  336. void RenderDisAllowedVerts( CRender3D *pRender );
  337. void Render3DDebug( CRender3D *pRender, bool isSelected );
  338. //=========================================================================
  339. //
  340. // Neighboring Functions
  341. //
  342. inline void ResetNeighbors( void );
  343. void FindNeighbors( void );
  344. //=========================================================================
  345. //
  346. // Load/Save Functions
  347. //
  348. static ChunkFileResult_t LoadDispDistancesCallback(CChunkFile *pFile, CMapDisp *pDisp);
  349. static ChunkFileResult_t LoadDispDistancesKeyCallback(const char *szKey, const char *szValue, CMapDisp *pDisp);
  350. static ChunkFileResult_t LoadDispOffsetsCallback(CChunkFile *pFile, CMapDisp *pDisp);
  351. static ChunkFileResult_t LoadDispOffsetsKeyCallback(const char *szKey, const char *szValue, CMapDisp *pDisp);
  352. static ChunkFileResult_t LoadDispOffsetNormalsCallback(CChunkFile *pFile, CMapDisp *pDisp);
  353. static ChunkFileResult_t LoadDispOffsetNormalsKeyCallback(const char *szKey, const char *szValue, CMapDisp *pDisp);
  354. static ChunkFileResult_t LoadDispKeyCallback(const char *szKey, const char *szValue, CMapDisp *pDisp);
  355. static ChunkFileResult_t LoadDispNormalsCallback(CChunkFile *pFile, CMapDisp *pDisp);
  356. static ChunkFileResult_t LoadDispNormalsKeyCallback(const char *szKey, const char *szValue, CMapDisp *pDisp);
  357. static ChunkFileResult_t LoadDispAlphasCallback(CChunkFile *pFile, CMapDisp *pDisp);
  358. static ChunkFileResult_t LoadDispAlphasKeyCallback(const char *szKey, const char *szValue, CMapDisp *pDisp);
  359. static ChunkFileResult_t LoadDispMultiBlendCallback(CChunkFile *pFile, CMapDisp *pDisp);
  360. static ChunkFileResult_t LoadDispMultiBlendKeyCallback(const char *szKey, const char *szValue, CMapDisp *pDisp);
  361. static ChunkFileResult_t LoadDispAlphaBlendCallback(CChunkFile *pFile, CMapDisp *pDisp);
  362. static ChunkFileResult_t LoadDispAlphaBlendKeyCallback(const char *szKey, const char *szValue, CMapDisp *pDisp);
  363. static ChunkFileResult_t LoadDispMultiBlendColorCallback0(CChunkFile *pFile, CMapDisp *pDisp);
  364. static ChunkFileResult_t LoadDispMultiBlendColorCallback1(CChunkFile *pFile, CMapDisp *pDisp);
  365. static ChunkFileResult_t LoadDispMultiBlendColorCallback2(CChunkFile *pFile, CMapDisp *pDisp);
  366. static ChunkFileResult_t LoadDispMultiBlendColorCallback3(CChunkFile *pFile, CMapDisp *pDisp);
  367. static ChunkFileResult_t LoadDispMultiBlendColorKeyCallback(const char *szKey, const char *szValue, CMapDisp *pDisp);
  368. static ChunkFileResult_t LoadDispTriangleTagsCallback(CChunkFile *pFile, CMapDisp *pDisp);
  369. static ChunkFileResult_t LoadDispTriangleTagsKeyCallback(const char *szKey, const char *szValue, CMapDisp *pDisp);
  370. static ChunkFileResult_t LoadDispAllowedVertsCallback(CChunkFile *pFile, CMapDisp *pDisp);
  371. static ChunkFileResult_t LoadDispAllowedVertsKeyCallback(const char *szKey, const char *szValue, CMapDisp *pDisp);
  372. //=========================================================================
  373. //
  374. // Utility
  375. //
  376. bool ComparePoints( const Vector& pt1, const Vector& pt2, const float tolerance );
  377. int GetStartIndexFromLevel( int levelIndex );
  378. int GetEndIndexFromLevel( int levelIndex );
  379. void SnapPointToPlane( Vector const &vNormal, float dist, Vector &pt );
  380. };
  381. //-----------------------------------------------------------------------------
  382. //-----------------------------------------------------------------------------
  383. inline void CMapDisp::SetPower( int power )
  384. {
  385. m_CoreDispInfo.SetPower( power );
  386. }
  387. //-----------------------------------------------------------------------------
  388. //-----------------------------------------------------------------------------
  389. inline int CMapDisp::GetPower( void )
  390. {
  391. return m_CoreDispInfo.GetPower();
  392. }
  393. //-----------------------------------------------------------------------------
  394. //-----------------------------------------------------------------------------
  395. inline int CMapDisp::CalcPower( int width )
  396. {
  397. switch( width )
  398. {
  399. case 5:
  400. return 2;
  401. case 9:
  402. return 3;
  403. case 17:
  404. return 4;
  405. default:
  406. return -1;
  407. }
  408. }
  409. //-----------------------------------------------------------------------------
  410. //-----------------------------------------------------------------------------
  411. inline int CMapDisp::GetWidth( void )
  412. {
  413. return m_CoreDispInfo.GetWidth();
  414. }
  415. //-----------------------------------------------------------------------------
  416. //-----------------------------------------------------------------------------
  417. inline int CMapDisp::GetHeight( void )
  418. {
  419. return m_CoreDispInfo.GetHeight();
  420. }
  421. //-----------------------------------------------------------------------------
  422. //-----------------------------------------------------------------------------
  423. inline int CMapDisp::GetSize( void )
  424. {
  425. return m_CoreDispInfo.GetSize();
  426. }
  427. //-----------------------------------------------------------------------------
  428. //-----------------------------------------------------------------------------
  429. inline void CMapDisp::SetElevation( float elevation )
  430. {
  431. m_CoreDispInfo.SetElevation( elevation );
  432. }
  433. //-----------------------------------------------------------------------------
  434. //-----------------------------------------------------------------------------
  435. inline float CMapDisp::GetElevation( void )
  436. {
  437. return m_CoreDispInfo.GetElevation();
  438. }
  439. //-----------------------------------------------------------------------------
  440. //-----------------------------------------------------------------------------
  441. inline float CMapDisp::GetScale( void )
  442. {
  443. return m_Scale;
  444. }
  445. //-----------------------------------------------------------------------------
  446. //-----------------------------------------------------------------------------
  447. inline void CMapDisp::GetBoundingBox( Vector& boxMin, Vector& boxMax )
  448. {
  449. boxMin = m_BBox[0];
  450. boxMax = m_BBox[1];
  451. }
  452. //-----------------------------------------------------------------------------
  453. //-----------------------------------------------------------------------------
  454. inline size_t CMapDisp::GetDataSize( void )
  455. {
  456. return ( sizeof( CMapDisp ) );
  457. }
  458. //-----------------------------------------------------------------------------
  459. //-----------------------------------------------------------------------------
  460. inline bool CMapDisp::IsTouched( void )
  461. {
  462. return m_CoreDispInfo.IsTouched();
  463. }
  464. //-----------------------------------------------------------------------------
  465. //-----------------------------------------------------------------------------
  466. inline void CMapDisp::SetTouched( void )
  467. {
  468. m_CoreDispInfo.SetTouched( true );
  469. }
  470. //-----------------------------------------------------------------------------
  471. //-----------------------------------------------------------------------------
  472. inline void CMapDisp::ResetTouched( void )
  473. {
  474. m_CoreDispInfo.SetTouched( false );
  475. }
  476. //-----------------------------------------------------------------------------
  477. //-----------------------------------------------------------------------------
  478. inline void CMapDisp::SetHasMappingAxes( bool value )
  479. {
  480. m_bHasMappingAxes = value;
  481. }
  482. //-----------------------------------------------------------------------------
  483. //-----------------------------------------------------------------------------
  484. inline void CMapDisp::SetSubdivided( bool bSubdiv )
  485. {
  486. m_bSubdiv = bSubdiv;
  487. }
  488. //-----------------------------------------------------------------------------
  489. //-----------------------------------------------------------------------------
  490. inline bool CMapDisp::IsSubdivided( void )
  491. {
  492. return m_bSubdiv;
  493. }
  494. //-----------------------------------------------------------------------------
  495. //-----------------------------------------------------------------------------
  496. inline void CMapDisp::SetReSubdivision( bool bReSubdiv )
  497. {
  498. m_bReSubdiv = bReSubdiv;
  499. }
  500. //-----------------------------------------------------------------------------
  501. //-----------------------------------------------------------------------------
  502. inline bool CMapDisp::NeedsReSubdivision( void )
  503. {
  504. return m_bReSubdiv;
  505. }
  506. //-----------------------------------------------------------------------------
  507. //-----------------------------------------------------------------------------
  508. inline void CMapDisp::GetSurfPoint( int index, Vector& pt )
  509. {
  510. CCoreDispSurface *pSurf = m_CoreDispInfo.GetSurface();
  511. pSurf->GetPoint( index, pt );
  512. }
  513. //-----------------------------------------------------------------------------
  514. //-----------------------------------------------------------------------------
  515. inline void CMapDisp::GetSurfNormal( Vector& normal )
  516. {
  517. CCoreDispSurface *pSurf = m_CoreDispInfo.GetSurface();
  518. pSurf->GetNormal( normal );
  519. }
  520. //-----------------------------------------------------------------------------
  521. //-----------------------------------------------------------------------------
  522. inline int CMapDisp::GetSurfPointStartIndex( void )
  523. {
  524. CCoreDispSurface *pSurf = m_CoreDispInfo.GetSurface();
  525. return pSurf->GetPointStartIndex();
  526. }
  527. //-----------------------------------------------------------------------------
  528. //-----------------------------------------------------------------------------
  529. inline void CMapDisp::SetSurfPointStartIndex( int index )
  530. {
  531. CCoreDispSurface *pSurf = m_CoreDispInfo.GetSurface();
  532. pSurf->SetPointStartIndex( index );
  533. }
  534. //-----------------------------------------------------------------------------
  535. //-----------------------------------------------------------------------------
  536. inline void CMapDisp::GetSurfTexCoord( int ndx, Vector2D &texCoord )
  537. {
  538. CCoreDispSurface *pSurf = m_CoreDispInfo.GetSurface();
  539. pSurf->GetTexCoord( ndx, texCoord );
  540. }
  541. //-----------------------------------------------------------------------------
  542. //-----------------------------------------------------------------------------
  543. inline void CMapDisp::SetSurfTexCoord( int ndx, Vector2D const &texCoord )
  544. {
  545. CCoreDispSurface *pSurf = m_CoreDispInfo.GetSurface();
  546. pSurf->SetTexCoord( ndx, texCoord );
  547. }
  548. //-----------------------------------------------------------------------------
  549. //-----------------------------------------------------------------------------
  550. inline void CMapDisp::SetVert( int index, Vector const &v )
  551. {
  552. m_CoreDispInfo.SetVert( index, v );
  553. }
  554. //-----------------------------------------------------------------------------
  555. //-----------------------------------------------------------------------------
  556. inline void CMapDisp::GetVert( int index, Vector& v )
  557. {
  558. m_CoreDispInfo.GetVert( index, v );
  559. }
  560. //-----------------------------------------------------------------------------
  561. //-----------------------------------------------------------------------------
  562. inline void CMapDisp::SetAlpha( int index, float alpha )
  563. {
  564. m_CoreDispInfo.SetAlpha( index, alpha );
  565. }
  566. //-----------------------------------------------------------------------------
  567. //-----------------------------------------------------------------------------
  568. inline float CMapDisp::GetAlpha( int index )
  569. {
  570. return m_CoreDispInfo.GetAlpha( index );
  571. }
  572. //-----------------------------------------------------------------------------
  573. //-----------------------------------------------------------------------------
  574. inline void CMapDisp::GetFlatVert( int index, Vector& v )
  575. {
  576. m_CoreDispInfo.GetFlatVert( index, v );
  577. }
  578. //-----------------------------------------------------------------------------
  579. //-----------------------------------------------------------------------------
  580. inline void CMapDisp::SetFlatVert( int index, const Vector &v )
  581. {
  582. m_CoreDispInfo.SetFlatVert( index, v );
  583. }
  584. inline void CMapDisp::GetMultiBlend( int index, Vector4D &vBlend, Vector4D &vAlphaBlend, Vector &vColor1, Vector &vColor2, Vector &vColor3, Vector &vColor4 )
  585. {
  586. m_CoreDispInfo.GetMultiBlend( index, vBlend, vAlphaBlend, vColor1, vColor2, vColor3, vColor4 );
  587. }
  588. inline void CMapDisp::SetMultiBlend( int index, Vector4D &vBlend, Vector4D &vAlphaBlend, Vector &vColor1, Vector &vColor2, Vector &vColor3, Vector &vColor4 )
  589. {
  590. m_CoreDispInfo.SetMultiBlend( index, vBlend, vAlphaBlend, vColor1, vColor2, vColor3, vColor4 );
  591. }
  592. //-----------------------------------------------------------------------------
  593. //-----------------------------------------------------------------------------
  594. inline void CMapDisp::ResetFieldVectors( void )
  595. {
  596. m_CoreDispInfo.ResetFieldVectors();
  597. }
  598. //-----------------------------------------------------------------------------
  599. //-----------------------------------------------------------------------------
  600. inline void CMapDisp::SetFieldVector( int index, Vector const &v )
  601. {
  602. m_CoreDispInfo.SetFieldVector( index, v );
  603. }
  604. //-----------------------------------------------------------------------------
  605. //-----------------------------------------------------------------------------
  606. inline void CMapDisp::GetFieldVector( int index, Vector& v )
  607. {
  608. m_CoreDispInfo.GetFieldVector( index, v );
  609. }
  610. //-----------------------------------------------------------------------------
  611. //-----------------------------------------------------------------------------
  612. inline void CMapDisp::ResetSubdivPositions( void )
  613. {
  614. m_CoreDispInfo.ResetSubdivPositions();
  615. }
  616. //-----------------------------------------------------------------------------
  617. //-----------------------------------------------------------------------------
  618. inline void CMapDisp::SetSubdivPosition( int ndx, Vector const &v )
  619. {
  620. m_CoreDispInfo.SetSubdivPosition( ndx, v );
  621. }
  622. //-----------------------------------------------------------------------------
  623. //-----------------------------------------------------------------------------
  624. inline void CMapDisp::GetSubdivPosition( int ndx, Vector& v )
  625. {
  626. m_CoreDispInfo.GetSubdivPosition( ndx, v );
  627. }
  628. //-----------------------------------------------------------------------------
  629. //-----------------------------------------------------------------------------
  630. inline void CMapDisp::ResetSubdivNormals( void )
  631. {
  632. m_CoreDispInfo.ResetSubdivNormals();
  633. }
  634. //-----------------------------------------------------------------------------
  635. //-----------------------------------------------------------------------------
  636. inline void CMapDisp::SetSubdivNormal( int ndx, Vector const &v )
  637. {
  638. m_CoreDispInfo.SetSubdivNormal( ndx, v );
  639. }
  640. //-----------------------------------------------------------------------------
  641. //-----------------------------------------------------------------------------
  642. inline void CMapDisp::GetSubdivNormal( int ndx, Vector &v )
  643. {
  644. m_CoreDispInfo.GetSubdivNormal( ndx, v );
  645. }
  646. //-----------------------------------------------------------------------------
  647. //-----------------------------------------------------------------------------
  648. inline void CMapDisp::ResetFieldDistances( void )
  649. {
  650. m_CoreDispInfo.ResetFieldDistances();
  651. }
  652. //-----------------------------------------------------------------------------
  653. //-----------------------------------------------------------------------------
  654. inline void CMapDisp::SetFieldDistance( int index, float dist )
  655. {
  656. m_CoreDispInfo.SetFieldDistance( index, dist );
  657. }
  658. //-----------------------------------------------------------------------------
  659. //-----------------------------------------------------------------------------
  660. inline float CMapDisp::GetFieldDistance( int index )
  661. {
  662. return m_CoreDispInfo.GetFieldDistance( index );
  663. }
  664. //-----------------------------------------------------------------------------
  665. //-----------------------------------------------------------------------------
  666. inline void CMapDisp::ResetNeighbors( void )
  667. {
  668. for( int i = 0; i < NUM_EDGES_CORNERS; i++ )
  669. {
  670. m_EdgeNeighbors[i] = EDITDISPHANDLE_INVALID;
  671. m_EdgeNeighborOrientations[i] = -1;
  672. m_CornerNeighborCounts[i] = 0;
  673. for( int j = 0; j < MAX_CORNER_NEIGHBORS; j++ )
  674. {
  675. m_CornerNeighbors[i][j] = EDITDISPHANDLE_INVALID;
  676. m_CornerNeighborOrientations[i][j] = -1;
  677. }
  678. }
  679. }
  680. //-----------------------------------------------------------------------------
  681. //-----------------------------------------------------------------------------
  682. inline void CMapDisp::SetEdgeNeighbor( int direction, EditDispHandle_t handle, int orient )
  683. {
  684. assert( direction >= 0 );
  685. assert( direction < NUM_EDGES_CORNERS );
  686. m_EdgeNeighbors[direction] = handle;
  687. m_EdgeNeighborOrientations[direction] = orient;
  688. }
  689. //-----------------------------------------------------------------------------
  690. //-----------------------------------------------------------------------------
  691. inline void CMapDisp::GetEdgeNeighbor( int direction, EditDispHandle_t &handle, int &orient )
  692. {
  693. assert( direction >= 0 );
  694. assert( direction < NUM_EDGES_CORNERS );
  695. handle = m_EdgeNeighbors[direction];
  696. orient = m_EdgeNeighborOrientations[direction];
  697. }
  698. //-----------------------------------------------------------------------------
  699. //-----------------------------------------------------------------------------
  700. inline EditDispHandle_t CMapDisp::GetEdgeNeighbor( int direction )
  701. {
  702. assert( direction >= 0 );
  703. assert( direction < NUM_EDGES_CORNERS );
  704. return m_EdgeNeighbors[direction];
  705. }
  706. //-----------------------------------------------------------------------------
  707. //-----------------------------------------------------------------------------
  708. inline void CMapDisp::AddCornerNeighbor( int direction, EditDispHandle_t handle, int orient )
  709. {
  710. assert( direction >= 0 );
  711. assert( direction < NUM_EDGES_CORNERS );
  712. if( m_CornerNeighborCounts[direction] >= MAX_CORNER_NEIGHBORS )
  713. return;
  714. m_CornerNeighbors[direction][m_CornerNeighborCounts[direction]] = handle;
  715. m_CornerNeighborOrientations[direction][m_CornerNeighborCounts[direction]] = orient;
  716. m_CornerNeighborCounts[direction]++;
  717. }
  718. //-----------------------------------------------------------------------------
  719. //-----------------------------------------------------------------------------
  720. inline int CMapDisp::GetCornerNeighborCount( int direction )
  721. {
  722. assert( direction >= 0 );
  723. assert( direction < NUM_EDGES_CORNERS );
  724. return m_CornerNeighborCounts[direction];
  725. }
  726. //-----------------------------------------------------------------------------
  727. //-----------------------------------------------------------------------------
  728. inline void CMapDisp::GetCornerNeighbor( int direction, int cornerIndex, EditDispHandle_t &handle, int &orient )
  729. {
  730. assert( direction >= 0 );
  731. assert( direction < NUM_EDGES_CORNERS );
  732. assert( cornerIndex >= 0 );
  733. assert( cornerIndex < MAX_CORNER_NEIGHBORS );
  734. handle = EDITDISPHANDLE_INVALID;
  735. orient = 0;
  736. if( cornerIndex >= m_CornerNeighborCounts[direction] )
  737. return;
  738. handle = m_CornerNeighbors[direction][cornerIndex];
  739. orient = m_CornerNeighborOrientations[direction][cornerIndex];
  740. }
  741. //-----------------------------------------------------------------------------
  742. //-----------------------------------------------------------------------------
  743. inline EditDispHandle_t CMapDisp::GetCornerNeighbor( int direction, int cornerIndex )
  744. {
  745. assert( direction >= 0 );
  746. assert( direction < NUM_EDGES_CORNERS );
  747. assert( cornerIndex >= 0 );
  748. assert( cornerIndex < MAX_CORNER_NEIGHBORS );
  749. if( cornerIndex >= m_CornerNeighborCounts[direction] )
  750. return NULL;
  751. return m_CornerNeighbors[direction][cornerIndex];
  752. }
  753. inline void CMapDisp::ResetTexelHitIndex( void ) { m_HitTexelIndex = -1; }
  754. inline void CMapDisp::SetTexelHitIndex( int index ) { m_HitTexelIndex = index; }
  755. inline int CMapDisp::GetTexelHitIndex( void ) { return m_HitTexelIndex; }
  756. inline void CMapDisp::SetDispMapHitIndex( int index ) { m_HitDispIndex = index; }
  757. inline void CMapDisp::ResetDispMapHitIndex( void ) { m_HitDispIndex = -1; }
  758. inline bool CMapDisp::Paint_IsDirty( void ) { return m_Canvas.m_bDirty; }
  759. #endif // MAPDISP_H