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.

518 lines
13 KiB

  1. //========= Copyright � 1996-2009, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "stdafx.h"
  7. #include "Box3D.h"
  8. #include "fgdlib/HelperInfo.h"
  9. #include "materialsystem/imaterialsystem.h"
  10. #include "materialsystem/IMesh.h"
  11. #include "MapDoc.h"
  12. #include "maplineoccluder.h"
  13. #include "MapView2D.h"
  14. #include "Material.h"
  15. #include "mathlib/MathLib.h"
  16. #include "Render2D.h"
  17. #include "Render3D.h"
  18. #include "ToolManager.h"
  19. #include "ToolSphere.h"
  20. //#include "..\FoW\FoW.h"
  21. //#include "..\fow\fow_2dplane.h"
  22. //#include "..\fow\fow_lineoccluder.h"
  23. // memdbgon must be the last include file in a .cpp file!!!
  24. #include <tier0/memdbgon.h>
  25. IMPLEMENT_MAPCLASS(CMapLineOccluder)
  26. //-----------------------------------------------------------------------------
  27. // Purpose: Factory function. Used for creating a CMapLineOccluder helper from a
  28. // set of string parameters from the FGD file.
  29. // Input : pInfo - Pointer to helper info class which gives us information
  30. // about how to create the helper.
  31. // Output : Returns a pointer to the helper, NULL if an error occurs.
  32. //-----------------------------------------------------------------------------
  33. CMapClass *CMapLineOccluder::Create(CHelperInfo *pHelperInfo, CMapEntity *pParent)
  34. {
  35. CMapLineOccluder *pOccluder = new CMapLineOccluder;
  36. if (pOccluder != NULL)
  37. {
  38. //
  39. // The first parameter should be the key name to represent. If it isn't
  40. // there we assume "radius".
  41. //
  42. #if 0
  43. const char *pszKeyName = pHelperInfo->GetParameter(0);
  44. if (pszKeyName != NULL)
  45. {
  46. strcpy(pOccluder->m_szKeyName, pszKeyName);
  47. }
  48. else
  49. {
  50. strcpy(pOccluder->m_szKeyName, "radius");
  51. }
  52. #endif
  53. //
  54. // Extract the line color from the parameter list.
  55. //
  56. unsigned char chRed = 255;
  57. unsigned char chGreen = 255;
  58. unsigned char chBlue = 255;
  59. const char *pszParam = pHelperInfo->GetParameter(1);
  60. if (pszParam != NULL)
  61. {
  62. chRed = atoi(pszParam);
  63. }
  64. pszParam = pHelperInfo->GetParameter(2);
  65. if (pszParam != NULL)
  66. {
  67. chGreen = atoi(pszParam);
  68. }
  69. pszParam = pHelperInfo->GetParameter(3);
  70. if (pszParam != NULL)
  71. {
  72. chBlue = atoi(pszParam);
  73. }
  74. pOccluder->SetRenderColor(chRed, chGreen, chBlue);
  75. }
  76. return pOccluder;
  77. }
  78. //-----------------------------------------------------------------------------
  79. // Purpose: Constructor.
  80. //-----------------------------------------------------------------------------
  81. CMapLineOccluder::CMapLineOccluder( bool AddToFoW ) :
  82. CMapHelper()
  83. {
  84. // m_szKeyName[0] = '\0';
  85. // m_flRadius = 0;
  86. r = 255;
  87. g = 0;
  88. b = 0;
  89. SetVisible( true );
  90. SetVisible2D( true );
  91. m_pLineOccluder = NULL;
  92. }
  93. //-----------------------------------------------------------------------------
  94. // Purpose: Destructor.
  95. //-----------------------------------------------------------------------------
  96. CMapLineOccluder::~CMapLineOccluder(void)
  97. {
  98. // [smessick] commented out missing FOW stuff
  99. #if 0
  100. if ( m_pLineOccluder != NULL )
  101. {
  102. delete m_pLineOccluder;
  103. m_pLineOccluder = NULL;
  104. }
  105. #endif
  106. }
  107. //-----------------------------------------------------------------------------
  108. // Purpose:
  109. // Input : bFullUpdate -
  110. //-----------------------------------------------------------------------------
  111. void CMapLineOccluder::CalcBounds(BOOL bFullUpdate)
  112. {
  113. CMapClass::CalcBounds(bFullUpdate);
  114. //
  115. // Pretend we're a point so that we don't change our parent entity bounds
  116. // in the 2D view.
  117. //
  118. m_Render2DBox.ResetBounds();
  119. m_Render2DBox.UpdateBounds(m_vStart, m_vEnd);
  120. //
  121. // Build our bounds for frustum culling in the 3D views.
  122. //
  123. m_CullBox.ResetBounds();
  124. m_CullBox.UpdateBounds(m_vStart, m_vEnd);
  125. m_BoundingBox.ResetBounds(); // we don't want to use the bounds of the sphere for our bounding box
  126. }
  127. //-----------------------------------------------------------------------------
  128. // Purpose:
  129. // Output : CMapClass
  130. //-----------------------------------------------------------------------------
  131. CMapClass *CMapLineOccluder::Copy(bool bUpdateDependencies)
  132. {
  133. CMapLineOccluder *pCopy = new CMapLineOccluder( false );
  134. if (pCopy != NULL)
  135. {
  136. pCopy->CopyFrom(this, bUpdateDependencies);
  137. }
  138. return(pCopy);
  139. }
  140. //-----------------------------------------------------------------------------
  141. // Purpose: Makes this an exact duplicate of pObject.
  142. // Input : pObject - Object to copy.
  143. // Output : Returns this.
  144. //-----------------------------------------------------------------------------
  145. CMapClass *CMapLineOccluder::CopyFrom(CMapClass *pObject, bool bUpdateDependencies)
  146. {
  147. #if 0
  148. Assert(pObject->IsMapClass(MAPCLASS_TYPE(CMapLineOccluder)));
  149. CMapLineOccluder *pFrom = (CMapLineOccluder *)pObject;
  150. CMapClass::CopyFrom(pObject, bUpdateDependencies);
  151. m_flRadius = pFrom->m_flRadius;
  152. strcpy(m_szKeyName, pFrom->m_szKeyName);
  153. #endif
  154. return(this);
  155. }
  156. void CMapLineOccluder::SetParent(CMapAtom *pParent)
  157. {
  158. __super::SetParent( pParent );
  159. // [smessick] commented out missing FOW stuff
  160. #if 0
  161. CMapEntity *pParentEnt = dynamic_cast< CMapEntity * >( pParent );
  162. CFoW *pFoW = CMapDoc::GetActiveMapDoc()->GetFoW();
  163. if ( pFoW != NULL && pParentEnt != NULL )
  164. {
  165. Vector2D vStart, vEnd;
  166. Vector vPlane;
  167. int nSliceNum;
  168. sscanf( pParentEnt->GetKeyValue( "start" ), "%g %g", &vStart.x, &vStart.y );
  169. sscanf( pParentEnt->GetKeyValue( "end" ), "%g %g", &vEnd.x, &vEnd.y );
  170. sscanf( pParentEnt->GetKeyValue( "plane" ), "%g %g %g", &vPlane.x, &vPlane.y, &vPlane.z );
  171. nSliceNum = atoi( pParentEnt->GetKeyValue( "slice_num" ) );
  172. CFOW_2DPlane Plane( vPlane.z, Vector2D( vPlane.x, vPlane.y ) );
  173. m_pLineOccluder = new CFoW_LineOccluder( vStart, vEnd, Plane, nSliceNum );
  174. pFoW->AddTriSoupOccluder( m_pLineOccluder, nSliceNum );
  175. float flZPos;
  176. flZPos = pFoW->GetSliceZPosition( nSliceNum );
  177. m_vStart.Init( vStart.x, vStart.y, flZPos );
  178. m_vEnd.Init( vEnd.x, vEnd.y, flZPos );
  179. pParentEnt->SetOrigin( ( m_vStart + m_vEnd ) / 2 );
  180. }
  181. #endif
  182. }
  183. //-----------------------------------------------------------------------------
  184. // Purpose: Gets the tool object for a given context data from HitTest2D.
  185. //-----------------------------------------------------------------------------
  186. CBaseTool *CMapLineOccluder::GetToolObject(int nHitData, bool bAttachObject)
  187. {
  188. #if 0
  189. CToolSphere *pTool = (CToolSphere *)ToolManager()->GetToolForID(TOOL_SPHERE);
  190. if ( bAttachObject )
  191. pTool->Attach(this);
  192. return pTool;
  193. #endif
  194. return NULL;
  195. }
  196. //-----------------------------------------------------------------------------
  197. // Purpose:
  198. // Input : pView -
  199. // point - point in client coordinates
  200. // Output :
  201. //-----------------------------------------------------------------------------
  202. bool CMapLineOccluder::HitTest2D(CMapView2D *pView, const Vector2D &point, HitInfo_t &HitData)
  203. {
  204. #if 0
  205. if ( m_flRadius <= 0 )
  206. {
  207. return NULL;
  208. }
  209. Vector2D vecClientOrigin;
  210. pView->WorldToClient(vecClientOrigin, m_Origin);
  211. Vector vecRadius = m_Origin;
  212. vecRadius[pView->axHorz] += m_flRadius;
  213. Vector2D vecClientRadius;
  214. pView->WorldToClient(vecClientRadius, vecRadius);
  215. int nRadius = abs(vecClientRadius.x - vecClientOrigin.x);
  216. vecClientRadius.x = nRadius;
  217. vecClientRadius.y = nRadius;
  218. HitData.pObject = this;
  219. HitData.nDepth = 0; // handles have no depth
  220. HitData.uData = nRadius;
  221. Vector2D vecClientMin = vecClientOrigin - vecClientRadius;
  222. Vector2D vecClientMax = vecClientOrigin + vecClientRadius;
  223. //
  224. // Check the four resize handles.
  225. //
  226. Vector2D vecTemp(vecClientOrigin.x, vecClientMin.y - HANDLE_OFFSET);
  227. if (pView->CheckDistance(point, vecTemp, 6))
  228. {
  229. // Top handle
  230. SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
  231. return true;
  232. }
  233. vecTemp.x = vecClientOrigin.x;
  234. vecTemp.y = vecClientMax.y + HANDLE_OFFSET;
  235. if (pView->CheckDistance(point, vecTemp, HANDLE_RADIUS))
  236. {
  237. // Bottom handle
  238. SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
  239. return true;
  240. }
  241. vecTemp.x = vecClientMin.x - HANDLE_OFFSET;
  242. vecTemp.y = vecClientOrigin.y;
  243. if (pView->CheckDistance(point, vecTemp, HANDLE_RADIUS))
  244. {
  245. // Left handle
  246. SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
  247. return true;
  248. }
  249. vecTemp.x = vecClientMax.x + HANDLE_OFFSET;
  250. vecTemp.y = vecClientOrigin.y;
  251. if (pView->CheckDistance(point, vecTemp, HANDLE_RADIUS))
  252. {
  253. // Right handle
  254. SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
  255. return true;
  256. }
  257. HitData.pObject = NULL;
  258. #endif
  259. return false;
  260. }
  261. //-----------------------------------------------------------------------------
  262. // Purpose: Notifies that this object's parent entity has had a key value change.
  263. // Input : szKey - The key that changed.
  264. // szValue - The new value of the key.
  265. //-----------------------------------------------------------------------------
  266. void CMapLineOccluder::OnParentKeyChanged(const char *szKey, const char *szValue)
  267. {
  268. #if 0
  269. if (!stricmp(szKey, m_szKeyName))
  270. {
  271. m_flRadius = atof(szValue);
  272. PostUpdate(Notify_Changed);
  273. CFoW *pFoW = CMapDoc::GetActiveMapDoc()->GetFoW();
  274. if ( pFoW )
  275. {
  276. pFoW->UpdateOccluderSize( m_FoWHandle, m_flRadius );
  277. }
  278. }
  279. #endif
  280. }
  281. //-----------------------------------------------------------------------------
  282. // Purpose:
  283. // Input :
  284. // Output :
  285. //-----------------------------------------------------------------------------
  286. void CMapLineOccluder::OnRemoveFromWorld(CMapWorld *pWorld, bool bNotifyChildren)
  287. {
  288. // CFoW *pFoW = CMapDoc::GetActiveMapDoc()->GetFoW();
  289. }
  290. #define MAX_SLICE_COLORS 5
  291. static unsigned char nVerticalColors[ MAX_SLICE_COLORS ][ 3 ] =
  292. {
  293. { 127, 127, 127 },
  294. { 255, 255, 255 },
  295. { 255, 0, 0 },
  296. { 0, 255, 0 },
  297. { 255, 255, 0 }
  298. };
  299. //-----------------------------------------------------------------------------
  300. // Purpose:
  301. // Input : pRender -
  302. //-----------------------------------------------------------------------------
  303. void CMapLineOccluder::Render2D(CRender2D *pRender)
  304. {
  305. // [smessick] commented out missing FOW stuff
  306. #if 0
  307. if ( m_pLineOccluder == NULL )
  308. {
  309. return;
  310. }
  311. int nSliceNum = m_pLineOccluder->GetSliceNum();
  312. if ( nSliceNum < MAX_SLICE_COLORS )
  313. {
  314. pRender->SetDrawColor( nVerticalColors[ nSliceNum ][ 0 ], nVerticalColors[ nSliceNum ][ 1 ], nVerticalColors[ nSliceNum ][ 2 ] );
  315. }
  316. else
  317. {
  318. pRender->SetDrawColor( 255, 255, 255 );
  319. }
  320. pRender->DrawLine( m_vStart, m_vEnd );
  321. #if 0
  322. if ( m_flRadius > 0 )
  323. {
  324. pRender->SetDrawColor( 255, 0, 0 );
  325. Vector2D ptClientRadius;
  326. pRender->TransformNormal(ptClientRadius, Vector(m_flRadius,m_flRadius,m_flRadius) );
  327. int radius = ptClientRadius.x;
  328. pRender->DrawCircle( m_Origin, m_flRadius );
  329. bool bPopMode = pRender->BeginClientSpace();
  330. pRender->SetHandleStyle( HANDLE_RADIUS, CRender::HANDLE_SQUARE );
  331. pRender->SetHandleColor( 255,0,0 );
  332. if ( IsSelected() )
  333. {
  334. //
  335. // Draw the four resize handles.
  336. //
  337. Vector2D offset;
  338. offset.x = 0;
  339. offset.y = -(radius + HANDLE_OFFSET);
  340. pRender->DrawHandle( m_Origin, &offset );
  341. offset.x = 0;
  342. offset.y = radius + HANDLE_OFFSET;
  343. pRender->DrawHandle( m_Origin, &offset );
  344. offset.x = -(radius + HANDLE_OFFSET);
  345. offset.y = 0;
  346. pRender->DrawHandle( m_Origin, &offset );
  347. offset.x = radius + HANDLE_OFFSET;
  348. offset.y = 0;
  349. pRender->DrawHandle( m_Origin, &offset );
  350. }
  351. pRender->DrawHandle( m_Origin, &vec2_origin );
  352. if ( bPopMode )
  353. pRender->EndClientSpace();
  354. }
  355. #endif
  356. #endif
  357. }
  358. //-----------------------------------------------------------------------------
  359. // Purpose: Renders the wireframe sphere.
  360. // Input : pRender - Interface to renderer.
  361. //-----------------------------------------------------------------------------
  362. void CMapLineOccluder::Render3D(CRender3D *pRender)
  363. {
  364. // [smessick] commented out missing FOW stuff
  365. #if 0
  366. if ( m_pLineOccluder == NULL )
  367. {
  368. return;
  369. }
  370. pRender->PushRenderMode( RENDER_MODE_WIREFRAME );
  371. int nSliceNum = m_pLineOccluder->GetSliceNum();
  372. if ( nSliceNum < MAX_SLICE_COLORS )
  373. {
  374. pRender->SetDrawColor( nVerticalColors[ nSliceNum ][ 0 ], nVerticalColors[ nSliceNum ][ 1 ], nVerticalColors[ nSliceNum ][ 2 ] );
  375. }
  376. else
  377. {
  378. pRender->SetDrawColor( 255, 255, 255 );
  379. }
  380. pRender->DrawLine( m_vStart, m_vEnd );
  381. #if 0
  382. if ( m_flRadius > 0 )
  383. {
  384. pRender->RenderWireframeSphere(m_Origin, m_flRadius, 12, 12, 255, 0, 0);
  385. }
  386. #endif
  387. pRender->PopRenderMode();
  388. #endif
  389. }
  390. //-----------------------------------------------------------------------------
  391. // Purpose: Overridden to chain down to our endpoints, which are not children.
  392. //-----------------------------------------------------------------------------
  393. void CMapLineOccluder::SetOrigin(Vector &vecOrigin)
  394. {
  395. BaseClass::SetOrigin(vecOrigin);
  396. }
  397. //-----------------------------------------------------------------------------
  398. // Purpose: Overridden to chain down to our endpoints, which are not children.
  399. //-----------------------------------------------------------------------------
  400. SelectionState_t CMapLineOccluder::SetSelectionState(SelectionState_t eSelectionState)
  401. {
  402. SelectionState_t eState = BaseClass::SetSelectionState(eSelectionState);
  403. return eState;
  404. }
  405. //-----------------------------------------------------------------------------
  406. // Purpose: Overridden to transform our endpoints.
  407. //-----------------------------------------------------------------------------
  408. void CMapLineOccluder::DoTransform(const VMatrix &matrix)
  409. {
  410. BaseClass::DoTransform(matrix);
  411. }
  412. void CMapLineOccluder::SetRadius(float flRadius)
  413. {
  414. }