ScreenRect.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #pragma hdrstop
  21. #include "../idlib/precompiled.h"
  22. #include "tr_local.h"
  23. /*
  24. ==========================================================================================
  25. idScreenRect
  26. ==========================================================================================
  27. */
  28. /*
  29. ======================
  30. idScreenRect::Clear
  31. ======================
  32. */
  33. void idScreenRect::Clear() {
  34. x1 = y1 = 32000;
  35. x2 = y2 = -32000;
  36. zmin = 0.0f;
  37. zmax = 1.0f;
  38. }
  39. /*
  40. ======================
  41. idScreenRect::AddPoint
  42. ======================
  43. */
  44. void idScreenRect::AddPoint( float x, float y ) {
  45. int ix = idMath::Ftoi( x );
  46. int iy = idMath::Ftoi( y );
  47. if ( ix < x1 ) {
  48. x1 = ix;
  49. }
  50. if ( ix > x2 ) {
  51. x2 = ix;
  52. }
  53. if ( iy < y1 ) {
  54. y1 = iy;
  55. }
  56. if ( iy > y2 ) {
  57. y2 = iy;
  58. }
  59. }
  60. /*
  61. ======================
  62. idScreenRect::Expand
  63. ======================
  64. */
  65. void idScreenRect::Expand() {
  66. x1--;
  67. y1--;
  68. x2++;
  69. y2++;
  70. }
  71. /*
  72. ======================
  73. idScreenRect::Intersect
  74. ======================
  75. */
  76. void idScreenRect::Intersect( const idScreenRect &rect ) {
  77. if ( rect.x1 > x1 ) {
  78. x1 = rect.x1;
  79. }
  80. if ( rect.x2 < x2 ) {
  81. x2 = rect.x2;
  82. }
  83. if ( rect.y1 > y1 ) {
  84. y1 = rect.y1;
  85. }
  86. if ( rect.y2 < y2 ) {
  87. y2 = rect.y2;
  88. }
  89. }
  90. /*
  91. ======================
  92. idScreenRect::Union
  93. ======================
  94. */
  95. void idScreenRect::Union( const idScreenRect &rect ) {
  96. if ( rect.x1 < x1 ) {
  97. x1 = rect.x1;
  98. }
  99. if ( rect.x2 > x2 ) {
  100. x2 = rect.x2;
  101. }
  102. if ( rect.y1 < y1 ) {
  103. y1 = rect.y1;
  104. }
  105. if ( rect.y2 > y2 ) {
  106. y2 = rect.y2;
  107. }
  108. }
  109. /*
  110. ======================
  111. idScreenRect::Equals
  112. ======================
  113. */
  114. bool idScreenRect::Equals( const idScreenRect &rect ) const {
  115. return ( x1 == rect.x1 && x2 == rect.x2 && y1 == rect.y1 && y2 == rect.y2 );
  116. }
  117. /*
  118. ======================
  119. idScreenRect::IsEmpty
  120. ======================
  121. */
  122. bool idScreenRect::IsEmpty() const {
  123. return ( x1 > x2 || y1 > y2 );
  124. }
  125. /*
  126. ======================
  127. R_ShowColoredScreenRect
  128. ======================
  129. */
  130. void R_ShowColoredScreenRect( const idScreenRect &rect, int colorIndex ) {
  131. if ( !rect.IsEmpty() ) {
  132. static idVec4 colors[] = { colorRed, colorGreen, colorBlue, colorYellow, colorMagenta, colorCyan, colorWhite, colorPurple };
  133. tr.viewDef->renderWorld->DebugScreenRect( colors[colorIndex & 7], rect, tr.viewDef );
  134. }
  135. }