DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

ScreenRect.cpp (3849B)


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