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.

174 lines
5.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Tool used for point-and-click setting of angles.
  4. //
  5. //=============================================================================//
  6. #include "stdafx.h"
  7. #include "resource.h"
  8. #include "ToolPickAngles.h"
  9. #include "MapView3D.h"
  10. #include "MapSolid.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include <tier0/memdbgon.h>
  13. //-----------------------------------------------------------------------------
  14. // Purpose: Constructor. Inits data members.
  15. //-----------------------------------------------------------------------------
  16. CToolPickAngles::CToolPickAngles(void)
  17. {
  18. m_pNotifyTarget = NULL;
  19. }
  20. //-----------------------------------------------------------------------------
  21. // Purpose: Destructor.
  22. //-----------------------------------------------------------------------------
  23. CToolPickAngles::~CToolPickAngles(void)
  24. {
  25. }
  26. //-----------------------------------------------------------------------------
  27. // Purpose: Handles the left mouse button up message in the 3D view.
  28. // Input : pView - The view that the event occurred in.
  29. // nFlags - Flags per the Windows mouse message.
  30. // point - Point in client coordinates where the event occurred.
  31. // Output : Returns true if the message was handled by the tool, false if not.
  32. //-----------------------------------------------------------------------------
  33. bool CToolPickAngles::OnLMouseUp3D(CMapView3D *pView, UINT nFlags, const Vector2D &vPoint)
  34. {
  35. return true;
  36. }
  37. //-----------------------------------------------------------------------------
  38. // Purpose: Handles the left mouse button up message in the 3D view.
  39. // Input : pView - The view that the event occurred in.
  40. // nFlags - Flags per the Windows mouse message.
  41. // point - Point in client coordinates where the event occurred.
  42. // Output : Returns true if the message was handled by the tool, false if not.
  43. //-----------------------------------------------------------------------------
  44. bool CToolPickAngles::OnLMouseDown3D(CMapView3D *pView, UINT nFlags, const Vector2D &vPoint)
  45. {
  46. unsigned long ulFace;
  47. CMapClass *pObject = pView->NearestObjectAt( vPoint, ulFace);
  48. if (pObject != NULL)
  49. {
  50. CMapClass *pSelObject = pObject->PrepareSelection(selectObjects);
  51. CMapEntity *pEntity = dynamic_cast <CMapEntity *>(pSelObject);
  52. if (pEntity != NULL)
  53. {
  54. //
  55. // We clicked on an entity.
  56. //
  57. if (m_pNotifyTarget)
  58. {
  59. Vector vecCenter;
  60. pEntity->GetBoundsCenter(vecCenter);
  61. m_pNotifyTarget->OnNotifyPickAngles(vecCenter);
  62. }
  63. }
  64. else
  65. {
  66. CMapSolid *pSolid = dynamic_cast <CMapSolid *> (pObject);
  67. if (pSolid == NULL)
  68. {
  69. return true;
  70. }
  71. //
  72. // Build a ray to trace against the face that they clicked on to
  73. // find the point of intersection.
  74. //
  75. Vector Start,End;
  76. pView->GetCamera()->BuildRay( vPoint, Start, End);
  77. Vector HitPos;
  78. Vector HitNormal;
  79. CMapFace *pFace = pSolid->GetFace(ulFace);
  80. if (pFace->TraceLine(HitPos, HitNormal, Start, End))
  81. {
  82. if (m_pNotifyTarget)
  83. {
  84. m_pNotifyTarget->OnNotifyPickAngles(HitPos);
  85. }
  86. }
  87. }
  88. }
  89. return true;
  90. }
  91. //-----------------------------------------------------------------------------
  92. // Purpose: Handles the left mouse button double click message in the 3D view.
  93. // Input : pView - The view that the event occurred in.
  94. // nFlags - Flags per the Windows mouse message.
  95. // point - Point in client coordinates where the event occurred.
  96. // Output : Returns true if the message was handled by the tool, false if not.
  97. //-----------------------------------------------------------------------------
  98. bool CToolPickAngles::OnLMouseDblClk3D(CMapView3D *pView, UINT nFlags, const Vector2D &vPoint)
  99. {
  100. return true;
  101. }
  102. //-----------------------------------------------------------------------------
  103. // Purpose: Handles the right mouse button up message in the 3D view.
  104. // Input : pView - The view that the event occurred in.
  105. // nFlags - Flags per the Windows mouse message.
  106. // point - Point in client coordinates where the event occurred.
  107. // Output : Returns true if the message was handled by the tool, false if not.
  108. //-----------------------------------------------------------------------------
  109. bool CToolPickAngles::OnRMouseUp3D(CMapView3D *pView, UINT nFlags, const Vector2D &vPoint)
  110. {
  111. return true;
  112. }
  113. //-----------------------------------------------------------------------------
  114. // Purpose: Handles the mouse button up message in the 3D view.
  115. // Input : pView - The view that the event occurred in.
  116. // nFlags - Flags per the Windows mouse message.
  117. // point - Point in client coordinates where the event occurred.
  118. // Output : Returns true if the message was handled by the tool, false if not.
  119. //-----------------------------------------------------------------------------
  120. bool CToolPickAngles::OnRMouseDown3D(CMapView3D *pView, UINT nFlags, const Vector2D &vPoint)
  121. {
  122. return true;
  123. }
  124. //-----------------------------------------------------------------------------
  125. // Purpose: Handles the mouse move message in the 3D view.
  126. // Input : pView - The view that the event occurred in.
  127. // nFlags - Flags per the Windows mouse message.
  128. // point - Point in client coordinates where the event occurred.
  129. // Output : Returns true if the message was handled by the tool, false if not.
  130. //-----------------------------------------------------------------------------
  131. bool CToolPickAngles::OnMouseMove3D(CMapView3D *pView, UINT nFlags, const Vector2D &vPoint)
  132. {
  133. SetToolCursor();
  134. return true;
  135. }
  136. //-----------------------------------------------------------------------------
  137. // Purpose: Sets the cursor to the correct cursor for this tool.
  138. //-----------------------------------------------------------------------------
  139. void CToolPickAngles::SetToolCursor(void)
  140. {
  141. static HCURSOR hcur = NULL;
  142. if (!hcur)
  143. {
  144. hcur = LoadCursor(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDC_CROSSHAIR));
  145. }
  146. SetCursor(hcur);
  147. }