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.

107 lines
3.3 KiB

  1. #include "fow.h"
  2. #include "fow_horizontalslice.h"
  3. #include "fow_viewer.h"
  4. // memdbgon must be the last include file in a .cpp file!!!
  5. #include <tier0/memdbgon.h>
  6. //-----------------------------------------------------------------------------
  7. // Purpose: empty constructor
  8. //-----------------------------------------------------------------------------
  9. CFoW_HorizontalSlice::CFoW_HorizontalSlice( void )
  10. {
  11. }
  12. //-----------------------------------------------------------------------------
  13. // Purpose: clears the sphere tree of all line occluders
  14. //-----------------------------------------------------------------------------
  15. void CFoW_HorizontalSlice::Clear( void )
  16. {
  17. m_SphereTree.Purge();
  18. }
  19. //-----------------------------------------------------------------------------
  20. // Purpose: adds a line occluder to the sphere tree
  21. // Input : pLineOccluder - the occluder to add
  22. //-----------------------------------------------------------------------------
  23. void CFoW_HorizontalSlice::AddHorizontalOccluder( CFoW_LineOccluder *pLineOccluder )
  24. {
  25. Vector2D start = pLineOccluder->GetStart();
  26. Vector2D end = pLineOccluder->GetEnd();
  27. Vector2D diff = ( end - start );
  28. Sphere_t bounds;
  29. bounds.x = ( start.x + end.x ) / 2.0f;
  30. bounds.y = ( start.y + end.y ) / 2.0f;
  31. bounds.z = 0.0f;
  32. bounds.w = sqrt( ( diff.x * diff.x ) + ( diff.y * diff.y ) );
  33. m_SphereTree.Insert( (void *)pLineOccluder, &bounds );
  34. #if 0
  35. Sphere_t TestSphere( -320, -1088, 0.0f, 592.77820 );
  36. Vector vDiff = TestSphere.AsVector3D() - bounds.AsVector3D();
  37. float flLen = vDiff.Length();
  38. if ( flLen <= ( bounds.w + TestSphere.w ) )
  39. {
  40. Msg( "here" );
  41. CFoW_LineOccluder *FixedPointerArray[ FOW_MAX_LINE_OCCLUDERS_TO_CHECK ];
  42. CUtlVector< void * > FoundOccluders( ( void ** )FixedPointerArray, FOW_MAX_LINE_OCCLUDERS_TO_CHECK );
  43. int RealCount = m_SphereTree.IntersectWithSphere( TestSphere, true, FoundOccluders, FOW_MAX_LINE_OCCLUDERS_TO_CHECK );
  44. bool bFound = false;
  45. for ( int i = 0; i < FoundOccluders.Count(); i++ )
  46. {
  47. if ( FixedPointerArray[ i ] == pLineOccluder )
  48. {
  49. bFound = true;
  50. }
  51. }
  52. if ( bFound == true )
  53. {
  54. Msg( "We found it!\n" );
  55. }
  56. else
  57. {
  58. Msg( "WE LOST IT!!!?" );
  59. }
  60. }
  61. #endif
  62. }
  63. //-----------------------------------------------------------------------------
  64. // Purpose: tests the viewer against all line occluders that are near the viewer
  65. // Input : pFoW - the main FoW object
  66. // pViewer - the viewer to obstruct
  67. //-----------------------------------------------------------------------------
  68. void CFoW_HorizontalSlice::ObstructViewer( CFoW *pFoW, CFoW_Viewer *pViewer )
  69. {
  70. Sphere_t TestSphere( pViewer->GetLocation().x, pViewer->GetLocation().y, 0.0f, pViewer->GetSize() );
  71. CFoW_LineOccluder *FixedPointerArray[ FOW_MAX_LINE_OCCLUDERS_TO_CHECK ];
  72. CUtlVector< void * > FoundOccluders( ( void ** )FixedPointerArray, FOW_MAX_LINE_OCCLUDERS_TO_CHECK );
  73. int RealCount = m_SphereTree.IntersectWithSphere( TestSphere, true, FoundOccluders, FOW_MAX_LINE_OCCLUDERS_TO_CHECK );
  74. if ( RealCount > FOW_MAX_LINE_OCCLUDERS_TO_CHECK )
  75. {
  76. // we overflowed, what should we do?
  77. }
  78. // Msg( "Slice Counts: %d / %d\n", FoundOccluders.Count(), RealCount );
  79. for ( int i = 0; i < FoundOccluders.Count(); i++ )
  80. {
  81. FixedPointerArray[ i ]->ObstructViewer( pFoW, pViewer );
  82. }
  83. }
  84. #include <tier0/memdbgoff.h>