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.

202 lines
5.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef MORPH3D_H
  8. #define MORPH3D_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "MapClass.h" // dvs: For CMapObjectList
  13. #include "Box3D.h"
  14. #include "SSolid.h"
  15. #include "Resource.h"
  16. #include "ScaleVerticesDlg.h"
  17. #include "ToolInterface.h"
  18. #include "mathlib/vector.h"
  19. class IMesh;
  20. class Morph3D;
  21. class CRender2D;
  22. class CRender3D;
  23. const SSHANDLE SSH_SCALEORIGIN = 0xffff0L;
  24. typedef struct
  25. {
  26. CMapSolid *pMapSolid;
  27. CSSolid *pStrucSolid;
  28. SSHANDLE ssh;
  29. } MORPHHANDLE;
  30. class Morph3D : public Box3D
  31. {
  32. public:
  33. Morph3D();
  34. virtual ~Morph3D();
  35. BOOL IsMorphing(CMapSolid *pSolid, CSSolid **pStrucSolidRvl = NULL);
  36. bool SplitFace();
  37. bool CanSplitFace();
  38. void SelectHandle(MORPHHANDLE *pInfo, UINT cmd = scSelect);
  39. void SelectHandle2D( CMapView2D *pView, MORPHHANDLE *pInfo, UINT cmd = scSelect);
  40. void DeselectHandle(MORPHHANDLE *pInfo);
  41. void MoveSelectedHandles(const Vector &Delta);
  42. int GetSelectedHandleCount(void) { return m_SelectedHandles.Count(); }
  43. void GetSelectedCenter(Vector& pt);
  44. SSHANDLETYPE GetSelectedType() { return m_SelectedType; }
  45. bool IsSelected(MORPHHANDLE &mh);
  46. void SelectObject(CMapSolid *pSolid, UINT cmd = scSelect);
  47. bool SelectAt( CMapView *pView, UINT nFlags, const Vector2D &vPoint );
  48. void GetMorphBounds(Vector &mins, Vector &maxs, bool bReset);
  49. void SnapSelectedToGrid( int nGridSpacing );
  50. // Toggle mode - vertex & edge, vertex, edge.
  51. void ToggleMode();
  52. void OnScaleCmd(BOOL bReInit = FALSE);
  53. void UpdateScale();
  54. BOOL IsScaling() { return m_bScaling; }
  55. void GetMorphingObjects(CUtlVector<CMapClass *> &List);
  56. inline int GetObjectCount(void);
  57. inline CSSolid *GetObject(int pos);
  58. //
  59. // Tool3D implementation.
  60. //
  61. virtual bool IsEmpty() { return !m_StrucSolids.Count() && !m_bBoxSelecting; }
  62. virtual void SetEmpty();
  63. virtual void FinishTranslation(bool bSave);
  64. virtual unsigned int GetConstraints(unsigned int nKeyFlags);
  65. //
  66. // CBaseTool implementation.
  67. //
  68. virtual void OnActivate();
  69. virtual void OnDeactivate();
  70. virtual ToolID_t GetToolID(void) { return TOOL_MORPH; }
  71. virtual bool CanDeactivate( void );
  72. virtual bool OnKeyDown2D(CMapView2D *pView, UINT nChar, UINT nRepCnt, UINT nFlags);
  73. virtual bool OnChar2D(CMapView2D *pView, UINT nChar, UINT nRepCnt, UINT nFlags);
  74. virtual bool OnLMouseDown2D(CMapView2D *pView, UINT nFlags, const Vector2D &vPoint);
  75. virtual bool OnLMouseUp2D(CMapView2D *pView, UINT nFlags, const Vector2D &vPoint);
  76. virtual bool OnMouseMove2D(CMapView2D *pView, UINT nFlags, const Vector2D &vPoint);
  77. virtual bool OnLMouseDown3D(CMapView3D *pView, UINT nFlags, const Vector2D &vPoint);
  78. virtual bool OnLMouseUp3D(CMapView3D *pView, UINT nFlags, const Vector2D &vPoint);
  79. virtual bool OnKeyDown3D(CMapView3D *pView, UINT nChar, UINT nRepCnt, UINT nFlags);
  80. virtual bool OnMouseMove3D(CMapView3D *pView, UINT nFlags, const Vector2D &vPoint);
  81. virtual void RenderTool2D(CRender2D *pRender);
  82. virtual void RenderTool3D(CRender3D *pRender);
  83. private:
  84. void OnEscape(void);
  85. bool NudgeHandles(CMapView *pView, UINT nChar, bool bSnap);
  86. bool MorphHitTest(CMapView *pView, const Vector2D &vPoint, MORPHHANDLE *pInfo);
  87. void GetHandlePos(MORPHHANDLE *pInfo, Vector& pt);
  88. SSHANDLE Get2DMatches(CMapView2D *pView, CSSolid *pStrucSolid, SSHANDLEINFO &hi, CUtlVector<SSHANDLE>*pSimilarList = NULL);
  89. void StartTranslation(CMapView *pView, const Vector2D &vPoint, MORPHHANDLE *pInfo );
  90. void RenderSolid3D(CRender3D *pRender, CSSolid *pSolid);
  91. //
  92. // Tool3D implementations.
  93. //
  94. int HitTest(CMapView *pView, const Vector2D &ptClient, bool bTestHandles = false);
  95. virtual bool UpdateTranslation( const Vector &pos, UINT uFlags );
  96. bool StartBoxSelection( CMapView *pView, const Vector2D &vPoint, const Vector &vStart);
  97. void SelectInBox();
  98. void EndBoxSelection();
  99. bool IsBoxSelecting() { return m_bBoxSelecting; }
  100. bool CanDeselectList( void );
  101. // list of active Structured Solids:
  102. CUtlVector<CSSolid*> m_StrucSolids;
  103. // list of selected nodes:
  104. CUtlVector<MORPHHANDLE> m_SelectedHandles;
  105. // type of selected handles:
  106. SSHANDLETYPE m_SelectedType;
  107. // main morph handle:
  108. MORPHHANDLE m_MorphHandle;
  109. Vector m_OrigHandlePos;
  110. // morph bounds:
  111. BoundBox m_MorphBounds;
  112. // handle mode:
  113. enum
  114. {
  115. hmBoth = 0x01 | 0x02,
  116. hmVertex = 0x01,
  117. hmEdge = 0x02
  118. };
  119. bool m_bLButtonDownControlState;
  120. Vector2D m_vLastMouseMovement;
  121. bool m_bHit;
  122. MORPHHANDLE m_DragHandle; // The morph handle that we are dragging.
  123. bool m_bMorphing;
  124. bool m_bMovingSelected; // not moving them yet - might just select this
  125. int m_HandleMode;
  126. bool m_bBoxSelecting;
  127. bool m_bScaling;
  128. bool m_bUpdateOrg;
  129. CScaleVerticesDlg m_ScaleDlg;
  130. Vector *m_pOrigPosList;
  131. Vector m_ScaleOrg;
  132. };
  133. //-----------------------------------------------------------------------------
  134. // Purpose: Returns the number of solids selected for morphing.
  135. //-----------------------------------------------------------------------------
  136. inline int Morph3D::GetObjectCount(void)
  137. {
  138. return(m_StrucSolids.Count());
  139. }
  140. //-----------------------------------------------------------------------------
  141. // Purpose: Iterates the selected solids.
  142. //-----------------------------------------------------------------------------
  143. inline CSSolid *Morph3D::GetObject(int pos)
  144. {
  145. return(m_StrucSolids.Element(pos));
  146. }
  147. #endif // MORPH3D_H