Team Fortress 2 Source Code as on 22/4/2020
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.

947 lines
35 KiB

  1. //========= Copyright 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 UpdateTriRemove( void );
  107. void CreateShoreOverlays( CMapFace *pFace, Shoreline_t *pShoreline );
  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 ResetFieldVectors( void );
  158. inline void SetFieldVector( int index, Vector const &v );
  159. inline void GetFieldVector( int index, Vector& v );
  160. inline void ResetFieldDistances( void );
  161. inline void SetFieldDistance( int index, float distance );
  162. inline float GetFieldDistance( int index );
  163. inline void ResetSubdivPositions( void );
  164. inline void SetSubdivPosition( int ndx, Vector const &v );
  165. inline void GetSubdivPosition( int ndx, Vector& v );
  166. inline void ResetSubdivNormals( void );
  167. inline void SetSubdivNormal( int ndx, Vector const &v );
  168. inline void GetSubdivNormal( int ndx, Vector &v );
  169. inline int GetTriCount( void ) { return m_CoreDispInfo.GetTriCount(); }
  170. inline void GetTriIndices( int iTri, unsigned short &v1, unsigned short &v2, unsigned short &v3 ) { m_CoreDispInfo.GetTriIndices( iTri, v1, v2, v3 ); }
  171. inline void GetTriPos( int iTri, Vector &v1, Vector &v2, Vector &v3 ) { m_CoreDispInfo.GetTriPos( iTri, v1, v2, v3 ); }
  172. inline void SetTriTag( int iTri, unsigned short nTag ) { m_CoreDispInfo.SetTriTag( iTri, nTag ); }
  173. inline void ResetTriTag( int iTri, unsigned short nTag ) { m_CoreDispInfo.ResetTriTag( iTri, nTag ); }
  174. inline void ToggleTriTag( int iTri, unsigned short nTag ) { m_CoreDispInfo.ToggleTriTag( iTri, nTag ); }
  175. inline bool IsTriTag( int iTri, unsigned short nTag ) { return m_CoreDispInfo.IsTriTag( iTri, nTag ); }
  176. inline bool IsTriWalkable( int iTri ) { return m_CoreDispInfo.IsTriWalkable( iTri ); }
  177. inline bool IsTriBuildable( int iTri ) { return m_CoreDispInfo.IsTriBuildable( iTri ); }
  178. // this is gone in m_CoreDispInfo.
  179. inline bool IsTriRemove( int iTri ) { return false; } //m_CoreDispInfo.IsTriRemove( 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. CUtlVector<CoreDispVert_t*> m_aRemoveVerts;
  279. CUtlVector<unsigned short> m_aRemoveIndices;
  280. // Painting Data.
  281. struct PaintCanvas_t
  282. {
  283. enum { CANVAS_SIZE = MAPDISP_MAX_VERTS };
  284. int m_nType; // what does the canvas hold - position, alpha, etc.
  285. Vector m_Values[CANVAS_SIZE];
  286. bool m_bValuesDirty[CANVAS_SIZE];
  287. bool m_bDirty;
  288. };
  289. PaintCanvas_t m_Canvas;
  290. //=========================================================================
  291. //
  292. // Painting Functions
  293. //
  294. void PaintPosition_Update( int iVert );
  295. void PaintAlpha_Update( int iVert );
  296. //=========================================================================
  297. //
  298. // Update/Modification/Editing Functions
  299. //
  300. void UpSample( int oldPower );
  301. void DownSample( int oldPower );
  302. void GetValidSamplePoints( int index, int width, int height, bool *pValidPoints );
  303. void SamplePoints( int index, int width, int height, bool *pValidPoints, float *pValue, float *pAlpha,
  304. Vector& newDispVector, Vector& newSubdivPos, Vector &newSubdivNormal );
  305. void PostCreate( void );
  306. void UpdateBoundingBox( void );
  307. void UpdateLightmapExtents( void );
  308. bool ValidLightmapSize( void );
  309. void CheckAndUpdateOverlays( bool bFull );
  310. bool EntityInBoundingBox( Vector const &vOrigin );
  311. enum { FLIP_HORIZONTAL = 0,
  312. FLIP_VERTICAL,
  313. FLIP_TRANSPOSE };
  314. void Flip( int flipType );
  315. int GetAxisTypeBasedOnView( int majorAxis, int vertAxis, int horzAxis );
  316. int GetMajorAxis( Vector &v );
  317. //=========================================================================
  318. //
  319. // Collision Testing
  320. //
  321. void CreateBoundingBoxes( BBox_t *pBBox, int count, float bloat );
  322. void CreatePlanesFromBoundingBox( Plane_t *planes, const Vector& bbMin, const Vector& bbMax );
  323. void CollideWithBoundingBoxes( const Vector& rayStart, const Vector& rayEnd, BBox_t *pBBox, int bboxCount, Tri_t *pTris, int *triCount );
  324. float CollideWithTriangles( const Vector& RayStart, const Vector& RayEnd, Tri_t *pTris, int triCount, Vector& surfNormal );
  325. //=========================================================================
  326. //
  327. // Rendering
  328. //
  329. void RenderHitBox( CRender3D *pRender, bool bNudge );
  330. void RenderPaintSphere( CRender3D *pRender, CToolDisplace *pTool );
  331. void CalcColor( CRender3D *pRender, bool bIsSelected, SelectionState_t faceSelectionState, Color &pColor );
  332. void RenderSurface( CRender3D *pRender, bool bIsSelected, SelectionState_t faceSelectionState );
  333. void RenderOverlaySurface( CRender3D *pRender, bool bIsSelected, SelectionState_t faceSelectionState );
  334. void RenderWalkableSurface( CRender3D *pRender, bool bIsSelected, SelectionState_t faceSelectionState );
  335. void RenderRemoveSurface( CRender3D *pRender, bool bIsSelected, SelectionState_t faceSelectionState );
  336. void RenderBuildableSurface( CRender3D *pRender, bool bIsSelected, SelectionState_t faceSelectionState );
  337. void RenderWireframeSurface( CRender3D *pRender, bool bIsSelected, SelectionState_t faceSelectionState );
  338. void RenderDisAllowedVerts( CRender3D *pRender );
  339. void Render3DDebug( CRender3D *pRender, bool isSelected );
  340. //=========================================================================
  341. //
  342. // Neighboring Functions
  343. //
  344. inline void ResetNeighbors( void );
  345. void FindNeighbors( void );
  346. //=========================================================================
  347. //
  348. // Load/Save Functions
  349. //
  350. static ChunkFileResult_t LoadDispDistancesCallback(CChunkFile *pFile, CMapDisp *pDisp);
  351. static ChunkFileResult_t LoadDispDistancesKeyCallback(const char *szKey, const char *szValue, CMapDisp *pDisp);
  352. static ChunkFileResult_t LoadDispOffsetsCallback(CChunkFile *pFile, CMapDisp *pDisp);
  353. static ChunkFileResult_t LoadDispOffsetsKeyCallback(const char *szKey, const char *szValue, CMapDisp *pDisp);
  354. static ChunkFileResult_t LoadDispOffsetNormalsCallback(CChunkFile *pFile, CMapDisp *pDisp);
  355. static ChunkFileResult_t LoadDispOffsetNormalsKeyCallback(const char *szKey, const char *szValue, CMapDisp *pDisp);
  356. static ChunkFileResult_t LoadDispKeyCallback(const char *szKey, const char *szValue, CMapDisp *pDisp);
  357. static ChunkFileResult_t LoadDispNormalsCallback(CChunkFile *pFile, CMapDisp *pDisp);
  358. static ChunkFileResult_t LoadDispNormalsKeyCallback(const char *szKey, const char *szValue, CMapDisp *pDisp);
  359. static ChunkFileResult_t LoadDispAlphasCallback(CChunkFile *pFile, CMapDisp *pDisp);
  360. static ChunkFileResult_t LoadDispAlphasKeyCallback(const char *szKey, const char *szValue, CMapDisp *pDisp);
  361. static ChunkFileResult_t LoadDispTriangleTagsCallback(CChunkFile *pFile, CMapDisp *pDisp);
  362. static ChunkFileResult_t LoadDispTriangleTagsKeyCallback(const char *szKey, const char *szValue, CMapDisp *pDisp);
  363. static ChunkFileResult_t LoadDispAllowedVertsCallback(CChunkFile *pFile, CMapDisp *pDisp);
  364. static ChunkFileResult_t LoadDispAllowedVertsKeyCallback(const char *szKey, const char *szValue, CMapDisp *pDisp);
  365. //=========================================================================
  366. //
  367. // Utility
  368. //
  369. bool ComparePoints( const Vector& pt1, const Vector& pt2, const float tolerance );
  370. int GetStartIndexFromLevel( int levelIndex );
  371. int GetEndIndexFromLevel( int levelIndex );
  372. void SnapPointToPlane( Vector const &vNormal, float dist, Vector &pt );
  373. };
  374. //-----------------------------------------------------------------------------
  375. //-----------------------------------------------------------------------------
  376. inline void CMapDisp::SetPower( int power )
  377. {
  378. m_CoreDispInfo.SetPower( power );
  379. }
  380. //-----------------------------------------------------------------------------
  381. //-----------------------------------------------------------------------------
  382. inline int CMapDisp::GetPower( void )
  383. {
  384. return m_CoreDispInfo.GetPower();
  385. }
  386. //-----------------------------------------------------------------------------
  387. //-----------------------------------------------------------------------------
  388. inline int CMapDisp::CalcPower( int width )
  389. {
  390. switch( width )
  391. {
  392. case 5:
  393. return 2;
  394. case 9:
  395. return 3;
  396. case 17:
  397. return 4;
  398. default:
  399. return -1;
  400. }
  401. }
  402. //-----------------------------------------------------------------------------
  403. //-----------------------------------------------------------------------------
  404. inline int CMapDisp::GetWidth( void )
  405. {
  406. return m_CoreDispInfo.GetWidth();
  407. }
  408. //-----------------------------------------------------------------------------
  409. //-----------------------------------------------------------------------------
  410. inline int CMapDisp::GetHeight( void )
  411. {
  412. return m_CoreDispInfo.GetHeight();
  413. }
  414. //-----------------------------------------------------------------------------
  415. //-----------------------------------------------------------------------------
  416. inline int CMapDisp::GetSize( void )
  417. {
  418. return m_CoreDispInfo.GetSize();
  419. }
  420. //-----------------------------------------------------------------------------
  421. //-----------------------------------------------------------------------------
  422. inline void CMapDisp::SetElevation( float elevation )
  423. {
  424. m_CoreDispInfo.SetElevation( elevation );
  425. }
  426. //-----------------------------------------------------------------------------
  427. //-----------------------------------------------------------------------------
  428. inline float CMapDisp::GetElevation( void )
  429. {
  430. return m_CoreDispInfo.GetElevation();
  431. }
  432. //-----------------------------------------------------------------------------
  433. //-----------------------------------------------------------------------------
  434. inline float CMapDisp::GetScale( void )
  435. {
  436. return m_Scale;
  437. }
  438. //-----------------------------------------------------------------------------
  439. //-----------------------------------------------------------------------------
  440. inline void CMapDisp::GetBoundingBox( Vector& boxMin, Vector& boxMax )
  441. {
  442. boxMin = m_BBox[0];
  443. boxMax = m_BBox[1];
  444. }
  445. //-----------------------------------------------------------------------------
  446. //-----------------------------------------------------------------------------
  447. inline size_t CMapDisp::GetDataSize( void )
  448. {
  449. return ( sizeof( CMapDisp ) );
  450. }
  451. //-----------------------------------------------------------------------------
  452. //-----------------------------------------------------------------------------
  453. inline bool CMapDisp::IsTouched( void )
  454. {
  455. return m_CoreDispInfo.IsTouched();
  456. }
  457. //-----------------------------------------------------------------------------
  458. //-----------------------------------------------------------------------------
  459. inline void CMapDisp::SetTouched( void )
  460. {
  461. m_CoreDispInfo.SetTouched( true );
  462. }
  463. //-----------------------------------------------------------------------------
  464. //-----------------------------------------------------------------------------
  465. inline void CMapDisp::ResetTouched( void )
  466. {
  467. m_CoreDispInfo.SetTouched( false );
  468. }
  469. //-----------------------------------------------------------------------------
  470. //-----------------------------------------------------------------------------
  471. inline void CMapDisp::SetHasMappingAxes( bool value )
  472. {
  473. m_bHasMappingAxes = value;
  474. }
  475. //-----------------------------------------------------------------------------
  476. //-----------------------------------------------------------------------------
  477. inline void CMapDisp::SetSubdivided( bool bSubdiv )
  478. {
  479. m_bSubdiv = bSubdiv;
  480. }
  481. //-----------------------------------------------------------------------------
  482. //-----------------------------------------------------------------------------
  483. inline bool CMapDisp::IsSubdivided( void )
  484. {
  485. return m_bSubdiv;
  486. }
  487. //-----------------------------------------------------------------------------
  488. //-----------------------------------------------------------------------------
  489. inline void CMapDisp::SetReSubdivision( bool bReSubdiv )
  490. {
  491. m_bReSubdiv = bReSubdiv;
  492. }
  493. //-----------------------------------------------------------------------------
  494. //-----------------------------------------------------------------------------
  495. inline bool CMapDisp::NeedsReSubdivision( void )
  496. {
  497. return m_bReSubdiv;
  498. }
  499. //-----------------------------------------------------------------------------
  500. //-----------------------------------------------------------------------------
  501. inline void CMapDisp::GetSurfPoint( int index, Vector& pt )
  502. {
  503. CCoreDispSurface *pSurf = m_CoreDispInfo.GetSurface();
  504. pSurf->GetPoint( index, pt );
  505. }
  506. //-----------------------------------------------------------------------------
  507. //-----------------------------------------------------------------------------
  508. inline void CMapDisp::GetSurfNormal( Vector& normal )
  509. {
  510. CCoreDispSurface *pSurf = m_CoreDispInfo.GetSurface();
  511. pSurf->GetNormal( normal );
  512. }
  513. //-----------------------------------------------------------------------------
  514. //-----------------------------------------------------------------------------
  515. inline int CMapDisp::GetSurfPointStartIndex( void )
  516. {
  517. CCoreDispSurface *pSurf = m_CoreDispInfo.GetSurface();
  518. return pSurf->GetPointStartIndex();
  519. }
  520. //-----------------------------------------------------------------------------
  521. //-----------------------------------------------------------------------------
  522. inline void CMapDisp::SetSurfPointStartIndex( int index )
  523. {
  524. CCoreDispSurface *pSurf = m_CoreDispInfo.GetSurface();
  525. pSurf->SetPointStartIndex( index );
  526. }
  527. //-----------------------------------------------------------------------------
  528. //-----------------------------------------------------------------------------
  529. inline void CMapDisp::GetSurfTexCoord( int ndx, Vector2D &texCoord )
  530. {
  531. CCoreDispSurface *pSurf = m_CoreDispInfo.GetSurface();
  532. pSurf->GetTexCoord( ndx, texCoord );
  533. }
  534. //-----------------------------------------------------------------------------
  535. //-----------------------------------------------------------------------------
  536. inline void CMapDisp::SetSurfTexCoord( int ndx, Vector2D const &texCoord )
  537. {
  538. CCoreDispSurface *pSurf = m_CoreDispInfo.GetSurface();
  539. pSurf->SetTexCoord( ndx, texCoord );
  540. }
  541. //-----------------------------------------------------------------------------
  542. //-----------------------------------------------------------------------------
  543. inline void CMapDisp::SetVert( int index, Vector const &v )
  544. {
  545. m_CoreDispInfo.SetVert( index, v );
  546. }
  547. //-----------------------------------------------------------------------------
  548. //-----------------------------------------------------------------------------
  549. inline void CMapDisp::GetVert( int index, Vector& v )
  550. {
  551. m_CoreDispInfo.GetVert( index, v );
  552. }
  553. //-----------------------------------------------------------------------------
  554. //-----------------------------------------------------------------------------
  555. inline void CMapDisp::SetAlpha( int index, float alpha )
  556. {
  557. m_CoreDispInfo.SetAlpha( index, alpha );
  558. }
  559. //-----------------------------------------------------------------------------
  560. //-----------------------------------------------------------------------------
  561. inline float CMapDisp::GetAlpha( int index )
  562. {
  563. return m_CoreDispInfo.GetAlpha( index );
  564. }
  565. //-----------------------------------------------------------------------------
  566. //-----------------------------------------------------------------------------
  567. inline void CMapDisp::GetFlatVert( int index, Vector& v )
  568. {
  569. m_CoreDispInfo.GetFlatVert( index, v );
  570. }
  571. //-----------------------------------------------------------------------------
  572. //-----------------------------------------------------------------------------
  573. inline void CMapDisp::SetFlatVert( int index, const Vector &v )
  574. {
  575. m_CoreDispInfo.SetFlatVert( index, v );
  576. }
  577. //-----------------------------------------------------------------------------
  578. //-----------------------------------------------------------------------------
  579. inline void CMapDisp::ResetFieldVectors( void )
  580. {
  581. m_CoreDispInfo.ResetFieldVectors();
  582. }
  583. //-----------------------------------------------------------------------------
  584. //-----------------------------------------------------------------------------
  585. inline void CMapDisp::SetFieldVector( int index, Vector const &v )
  586. {
  587. m_CoreDispInfo.SetFieldVector( index, v );
  588. }
  589. //-----------------------------------------------------------------------------
  590. //-----------------------------------------------------------------------------
  591. inline void CMapDisp::GetFieldVector( int index, Vector& v )
  592. {
  593. m_CoreDispInfo.GetFieldVector( index, v );
  594. }
  595. //-----------------------------------------------------------------------------
  596. //-----------------------------------------------------------------------------
  597. inline void CMapDisp::ResetSubdivPositions( void )
  598. {
  599. m_CoreDispInfo.ResetSubdivPositions();
  600. }
  601. //-----------------------------------------------------------------------------
  602. //-----------------------------------------------------------------------------
  603. inline void CMapDisp::SetSubdivPosition( int ndx, Vector const &v )
  604. {
  605. m_CoreDispInfo.SetSubdivPosition( ndx, v );
  606. }
  607. //-----------------------------------------------------------------------------
  608. //-----------------------------------------------------------------------------
  609. inline void CMapDisp::GetSubdivPosition( int ndx, Vector& v )
  610. {
  611. m_CoreDispInfo.GetSubdivPosition( ndx, v );
  612. }
  613. //-----------------------------------------------------------------------------
  614. //-----------------------------------------------------------------------------
  615. inline void CMapDisp::ResetSubdivNormals( void )
  616. {
  617. m_CoreDispInfo.ResetSubdivNormals();
  618. }
  619. //-----------------------------------------------------------------------------
  620. //-----------------------------------------------------------------------------
  621. inline void CMapDisp::SetSubdivNormal( int ndx, Vector const &v )
  622. {
  623. m_CoreDispInfo.SetSubdivNormal( ndx, v );
  624. }
  625. //-----------------------------------------------------------------------------
  626. //-----------------------------------------------------------------------------
  627. inline void CMapDisp::GetSubdivNormal( int ndx, Vector &v )
  628. {
  629. m_CoreDispInfo.GetSubdivNormal( ndx, v );
  630. }
  631. //-----------------------------------------------------------------------------
  632. //-----------------------------------------------------------------------------
  633. inline void CMapDisp::ResetFieldDistances( void )
  634. {
  635. m_CoreDispInfo.ResetFieldDistances();
  636. }
  637. //-----------------------------------------------------------------------------
  638. //-----------------------------------------------------------------------------
  639. inline void CMapDisp::SetFieldDistance( int index, float dist )
  640. {
  641. m_CoreDispInfo.SetFieldDistance( index, dist );
  642. }
  643. //-----------------------------------------------------------------------------
  644. //-----------------------------------------------------------------------------
  645. inline float CMapDisp::GetFieldDistance( int index )
  646. {
  647. return m_CoreDispInfo.GetFieldDistance( index );
  648. }
  649. //-----------------------------------------------------------------------------
  650. //-----------------------------------------------------------------------------
  651. inline void CMapDisp::ResetNeighbors( void )
  652. {
  653. for( int i = 0; i < NUM_EDGES_CORNERS; i++ )
  654. {
  655. m_EdgeNeighbors[i] = EDITDISPHANDLE_INVALID;
  656. m_EdgeNeighborOrientations[i] = -1;
  657. m_CornerNeighborCounts[i] = 0;
  658. for( int j = 0; j < MAX_CORNER_NEIGHBORS; j++ )
  659. {
  660. m_CornerNeighbors[i][j] = EDITDISPHANDLE_INVALID;
  661. m_CornerNeighborOrientations[i][j] = -1;
  662. }
  663. }
  664. }
  665. //-----------------------------------------------------------------------------
  666. //-----------------------------------------------------------------------------
  667. inline void CMapDisp::SetEdgeNeighbor( int direction, EditDispHandle_t handle, int orient )
  668. {
  669. Assert( direction >= 0 );
  670. Assert( direction < NUM_EDGES_CORNERS );
  671. m_EdgeNeighbors[direction] = handle;
  672. m_EdgeNeighborOrientations[direction] = orient;
  673. }
  674. //-----------------------------------------------------------------------------
  675. //-----------------------------------------------------------------------------
  676. inline void CMapDisp::GetEdgeNeighbor( int direction, EditDispHandle_t &handle, int &orient )
  677. {
  678. Assert( direction >= 0 );
  679. Assert( direction < NUM_EDGES_CORNERS );
  680. handle = m_EdgeNeighbors[direction];
  681. orient = m_EdgeNeighborOrientations[direction];
  682. }
  683. //-----------------------------------------------------------------------------
  684. //-----------------------------------------------------------------------------
  685. inline EditDispHandle_t CMapDisp::GetEdgeNeighbor( int direction )
  686. {
  687. Assert( direction >= 0 );
  688. Assert( direction < NUM_EDGES_CORNERS );
  689. return m_EdgeNeighbors[direction];
  690. }
  691. //-----------------------------------------------------------------------------
  692. //-----------------------------------------------------------------------------
  693. inline void CMapDisp::AddCornerNeighbor( int direction, EditDispHandle_t handle, int orient )
  694. {
  695. Assert( direction >= 0 );
  696. Assert( direction < NUM_EDGES_CORNERS );
  697. if( m_CornerNeighborCounts[direction] >= MAX_CORNER_NEIGHBORS )
  698. return;
  699. m_CornerNeighbors[direction][m_CornerNeighborCounts[direction]] = handle;
  700. m_CornerNeighborOrientations[direction][m_CornerNeighborCounts[direction]] = orient;
  701. m_CornerNeighborCounts[direction]++;
  702. }
  703. //-----------------------------------------------------------------------------
  704. //-----------------------------------------------------------------------------
  705. inline int CMapDisp::GetCornerNeighborCount( int direction )
  706. {
  707. Assert( direction >= 0 );
  708. Assert( direction < NUM_EDGES_CORNERS );
  709. return m_CornerNeighborCounts[direction];
  710. }
  711. //-----------------------------------------------------------------------------
  712. //-----------------------------------------------------------------------------
  713. inline void CMapDisp::GetCornerNeighbor( int direction, int cornerIndex, EditDispHandle_t &handle, int &orient )
  714. {
  715. Assert( direction >= 0 );
  716. Assert( direction < NUM_EDGES_CORNERS );
  717. Assert( cornerIndex >= 0 );
  718. Assert( cornerIndex < MAX_CORNER_NEIGHBORS );
  719. handle = EDITDISPHANDLE_INVALID;
  720. orient = 0;
  721. if( cornerIndex >= m_CornerNeighborCounts[direction] )
  722. return;
  723. handle = m_CornerNeighbors[direction][cornerIndex];
  724. orient = m_CornerNeighborOrientations[direction][cornerIndex];
  725. }
  726. //-----------------------------------------------------------------------------
  727. //-----------------------------------------------------------------------------
  728. inline EditDispHandle_t CMapDisp::GetCornerNeighbor( int direction, int cornerIndex )
  729. {
  730. Assert( direction >= 0 );
  731. Assert( direction < NUM_EDGES_CORNERS );
  732. Assert( cornerIndex >= 0 );
  733. Assert( cornerIndex < MAX_CORNER_NEIGHBORS );
  734. if( cornerIndex >= m_CornerNeighborCounts[direction] )
  735. return NULL;
  736. return m_CornerNeighbors[direction][cornerIndex];
  737. }
  738. inline void CMapDisp::ResetTexelHitIndex( void ) { m_HitTexelIndex = -1; }
  739. inline void CMapDisp::SetTexelHitIndex( int index ) { m_HitTexelIndex = index; }
  740. inline int CMapDisp::GetTexelHitIndex( void ) { return m_HitTexelIndex; }
  741. inline void CMapDisp::SetDispMapHitIndex( int index ) { m_HitDispIndex = index; }
  742. inline void CMapDisp::ResetDispMapHitIndex( void ) { m_HitDispIndex = -1; }
  743. inline bool CMapDisp::Paint_IsDirty( void ) { return m_Canvas.m_bDirty; }
  744. #endif // MAPDISP_H