Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

HV_bsp.cpp

Go to the documentation of this file.
00001 /*------------------------------------ Includes ---------------------------------------------*/ 00002 #include "HV_bsp.h" 00003 00004 using namespace std; 00005 00006 00007 00008 /*--------------------------------------------------------------------------------------------------*/ 00009 // met le segment p0<-->p_inter dans w_front 00010 // met le segment p_inter<-->p1 dans w_back 00011 static void Build_Two_Segments( cPoint2D & p0 , cPoint2D & p1 ,cPoint2D& p_inter ,cHV_Wall& w_front , cHV_Wall& w_back) 00012 { 00013 w_front = cHV_Wall(p0 , p_inter); 00014 w_back = cHV_Wall( cPoint2D(p_inter.Get_X(),p_inter.Get_Y()) , p1); 00015 } 00016 00017 /*--------------------------------------------------------------------------------------------------*/ 00018 std::ostream &operator<<(std::ostream &os, const cHV_Wall &ex) 00019 { 00020 return os << ex.p0 << "-->" << ex.p1; 00021 }; 00022 00023 00024 /****************************************************************************************************/ 00025 // class cHV_Wall 00026 /****************************************************************************************************/ 00027 /*--------------------------------------------------------------------------------------------------*/ 00028 cHV_Wall::cHV_Wall():cWall() 00029 { 00030 Set_HV(); 00031 Set_Order(); 00032 } 00033 00034 /*--------------------------------------------------------------------------------------------------*/ 00035 cHV_Wall::cHV_Wall(cWall& wall):cWall(wall) 00036 { 00037 Set_HV(); 00038 Set_Order(); 00039 } 00040 00041 00042 00043 /*--------------------------------------------------------------------------------------------------*/ 00044 cHV_Wall::cHV_Wall( cPoint2D &A, cPoint2D &B):cWall(A,B) 00045 { 00046 Set_HV(); 00047 Set_Order(); 00048 if( Get_Length()<0.1 ) 00049 { 00050 std::cout << "WARNING : cHV_Wall( cPoint2D &A, cPoint2D &B):cWall(A,B) \n"; 00051 std::cout << "le cHV_Wall a une longueur tres petite ... \n"; 00052 std::cout << (*this) << "\n"; 00053 } 00054 } 00055 00056 /*--------------------------------------------------------------------------------------------------*/ 00057 void cHV_Wall::Set_HV() 00058 { 00059 if( p0.Get_X() == p1.Get_X() ) 00060 bHorizontal = false; 00061 else if( p0.Get_Y() == p1.Get_Y() ) 00062 bHorizontal = true; 00063 else 00064 { 00065 cout << "ERROR : void cHV_Wall::Set_HV()"; 00066 cout << (*this) << " is not an valid HV_wall !!! \n"; 00067 } 00068 } 00069 00070 /*--------------------------------------------------------------------------------------------------*/ 00071 void cHV_Wall::Get_Wall_Seg(cHV_Seg & wall) 00072 { 00073 wall.Set(p0 , p1); 00074 } 00075 00076 00077 /*--------------------------------------------------------------------------------------------------*/ 00078 BSP_POSITION_POINT cHV_Wall::Get_Position_Point( cPoint2D & A ) 00079 { 00080 if( bHorizontal) 00081 { 00082 if( A.Get_Y() < this->p0.Get_Y() ) 00083 return POINT_FRONT; 00084 else if( A.Get_Y() > this->p0.Get_Y() ) 00085 return POINT_BACK; 00086 else 00087 return POINT_ON; 00088 } 00089 else 00090 { 00091 if( A.Get_X() < this->p0.Get_X() ) 00092 return POINT_FRONT; 00093 else if( A.Get_X() > this->p0.Get_X() ) 00094 return POINT_BACK; 00095 else 00096 return POINT_ON; 00097 } 00098 } 00099 00100 00101 /*--------------------------------------------------------------------------------------------------*/ 00102 void cHV_Wall::Set_Order() 00103 { 00104 int t; 00105 if( bHorizontal) 00106 { 00107 if( p0.Get_X() > p1.Get_X() ) 00108 { 00109 t = p0.Get_X(); 00110 p0.Set(p1.Get_X() , p1.Get_Y() ); 00111 p1.Set( t , p1.Get_Y() ); 00112 } 00113 } 00114 else 00115 { 00116 if( p0.Get_Y() > p1.Get_Y() ) 00117 { 00118 t = p0.Get_Y(); 00119 p0.Set(p1.Get_X() , p1.Get_Y() ); 00120 p1.Set( p1.Get_X() , t); 00121 } 00122 } 00123 } 00124 00125 00126 00127 00128 /*--------------------------------------------------------------------------------------------------*/ 00129 void cHV_Wall::Get_Intersection( cHV_Wall& w ,cPoint2D& p_inter) 00130 { 00131 if( bHorizontal) 00132 { 00133 if( w.bHorizontal) 00134 { 00135 cout << "ERROR : void Get_Intersection( cHV_Wall& w ,cPoint2D& ) \n"; 00136 cout << " les deux droites sont horizontales !! \n"; 00137 cout << "d1 =" << (*this) << "\n"; 00138 cout << "d2 =" << w << "\n"; 00139 } 00140 else 00141 { 00142 p_inter.Set( w.p0.Get_X(),this->p0.Get_Y() ); 00143 } 00144 } 00145 else 00146 { 00147 if( w.bHorizontal) 00148 { 00149 p_inter.Set( this->p0.Get_X(),w.p0.Get_Y() ); 00150 } 00151 else 00152 { 00153 cout << "ERROR : void Get_Intersection( cHV_Wall& w ,cPoint2D& ) \n"; 00154 cout << " les deux droites sont verticales !! \n"; 00155 cout << "d1 =" << (*this) << "\n"; 00156 cout << "d2 =" << w << "\n"; 00157 } 00158 } 00159 } 00160 00161 /*--------------------------------------------------------------------------------------------------*/ 00162 BSP_POSITION_DIVIDER cHV_Wall::Get_Position_Divider_And_Split( cHV_Wall & w , cHV_Wall & w_front , cHV_Wall & w_back ) 00163 { 00164 BSP_POSITION_POINT pos0 = Get_Position_Point( w.p0) ; 00165 BSP_POSITION_POINT pos1 = Get_Position_Point( w.p1) ; 00166 cPoint2D p_inter; 00167 00168 switch( pos0) 00169 { 00170 case POINT_FRONT: 00171 switch(pos1) 00172 { 00173 case POINT_FRONT: 00174 return DIVIDER_FRONT; 00175 case POINT_BACK: 00176 Get_Intersection( w , p_inter); 00177 Build_Two_Segments( w.p0 , w.p1 , p_inter , w_front , w_back); 00178 return DIVIDER_CROSS; 00179 case POINT_ON: 00180 return DIVIDER_FRONT; 00181 default: 00182 cout << "ERROR : BSP_POSITION_DIVIDER cHV_Wall::Get_Position_Divider_And_Split( cHV_Wall & w , cHV_Wall & w_front , cHV_Wall & w_back ) \n"; 00183 return DIVIDER_ON; // pour eviter le warning "path without return" 00184 } 00185 break; 00186 case POINT_BACK: 00187 switch(pos1) 00188 { 00189 case POINT_FRONT: 00190 Get_Intersection( w , p_inter); 00191 Build_Two_Segments( w.p1 , w.p0 , p_inter , w_front , w_back); 00192 return DIVIDER_CROSS; 00193 case POINT_BACK: 00194 return DIVIDER_BACK; 00195 case POINT_ON: 00196 return DIVIDER_BACK; 00197 default: 00198 cout << "ERROR : BSP_POSITION_DIVIDER cHV_Wall::Get_Position_Divider_And_Split( cHV_Wall & w , cHV_Wall & w_front , cHV_Wall & w_back ) \n"; 00199 return DIVIDER_ON; // pour eviter le warning "path without return" 00200 } 00201 break; 00202 case POINT_ON: 00203 switch(pos1) 00204 { 00205 case POINT_FRONT: 00206 return DIVIDER_ON; 00207 case POINT_BACK: 00208 return DIVIDER_BACK; 00209 case POINT_ON: 00210 cout << "ERROR : BSP_POSITION_DIVIDER cHV_Wall::Get_Position_Divider_And_Split( cHV_Wall & w , cHV_Wall & w_front , cHV_Wall & w_back ) \n"; 00211 cout << "les murs parallelles ne sont pas encore gérés ! \n"; 00212 cout << "cWall :" << w << " et " << (*this) << " \n"; 00213 return DIVIDER_ON; // pour eviter le warning "path without return" 00214 default: 00215 cout << "ERROR : BSP_POSITION_DIVIDER cHV_Wall::Get_Position_Divider_And_Split( cHV_Wall & w , cHV_Wall & w_front , cHV_Wall & w_back ) \n"; 00216 return DIVIDER_ON; // pour eviter le warning "path without return" 00217 } 00218 break; 00219 default: 00220 cout << "ERROR : BSP_POSITION_DIVIDER cHV_Wall::Get_Position_Divider_And_Split( cHV_Wall & w , cHV_Wall & w_front , cHV_Wall & w_back ) \n"; 00221 return DIVIDER_ON; // pour eviter le warning "path without return" 00222 } 00223 }

Generated on Fri May 21 19:22:37 2004 for LIBELL by doxygen 1.3.7