Main Page | Class Hierarchy | Class List | Directories | File List | Class Members

IntersectionPoints.cpp

00001 #include "lifevariables.h"
00002 #include "CScanner.h"
00003 
00004 bool CScanner::GetIntersectionPoints( sPoint3f   *pBeginCoord, sPoint3f  *pEndCoord, 
00005                                       sPoint3f   eye,          sVector3f ray)
00006 {
00007     _iXCount = 0;
00008     unsigned long mag0 = 0, mag1 = 0;
00009 
00010     GetXYIntersectionPoints(eye, ray);
00011 
00012     GetYZIntersectionPoints(eye, ray);
00013 
00014     GetXZIntersectionPoints(eye, ray);
00015 
00016     if ( _iXCount > 2 || _iXCount == 1 )
00017     {
00018         throw;
00019     }
00020     else if ( _iXCount == 0 )
00021     {
00022         return false;
00023     }
00024     else if ( _iXCount == 2 ) 
00025     {
00026         mag0 = _aIntersectionPoints[0].GetMagnitude();
00027         mag1 = _aIntersectionPoints[1].GetMagnitude();
00028 
00029         if (mag0 < mag1)
00030         {
00031             *pBeginCoord = _aIntersectionPoints[0].GetPoint();
00032             *pEndCoord   = _aIntersectionPoints[1].GetPoint();
00033         }
00034         else
00035         {
00036             *pBeginCoord = _aIntersectionPoints[1].GetPoint();
00037             *pEndCoord   = _aIntersectionPoints[0].GetPoint();        
00038         }
00039     }
00040     return true;
00041 }
00042 
00043 void CScanner::GetXYIntersectionPoints(sPoint3f   eye,sVector3f ray)
00044 {
00045     sPoint3f xy_n,  xy_f;
00046     float    tp,    tm;
00047 
00048     /*
00049      * if z component of ray is 0, we're parallel to the x-y plane
00050      */
00051     if ( !ray.z )
00052     {
00053         return;
00054     }
00055     else
00056     {
00057         tp = ( _range.z - eye.z) / ray.z;
00058         tm = ( - _range.z - eye.z ) / ray.z;
00059     
00060         xy_n.x = eye.x + tm * ray.x;
00061         xy_n.y = eye.y + tm * ray.y;
00062         xy_n.z = eye.z + tm * ray.z;
00063 
00064         xy_f.x = eye.x + tp * ray.x;
00065         xy_f.y = eye.y + tp * ray.y;
00066         xy_f.z = eye.z + tp * ray.z;
00067     }
00068 
00069     /*
00070      * Test the near and far points to see if they fall within the volume
00071      */
00072 
00073     sPoint3f nearPoint( abs(xy_n.x) , abs(xy_n.y), abs(xy_n.z));
00074     sPoint3f farPoint( abs(xy_f.x), abs(xy_f.y), abs(xy_f.z));
00075 
00076     if ( nearPoint.x <= _range.x && 
00077          nearPoint.y <= _range.y &&
00078          nearPoint.z <= _range.z    )
00079     {
00080         if ( _iXCount >= 2 )
00081             throw;
00082 
00083        _aIntersectionPoints[_iXCount++].Set(xy_n);
00084     }
00085 
00086     if ( farPoint.x <= _range.x && 
00087          farPoint.y <= _range.y &&
00088          farPoint.z <= _range.z    )
00089     {
00090         if ( _iXCount >= 2 )
00091             throw;
00092 
00093         _aIntersectionPoints[_iXCount++].Set(xy_f);
00094     }
00095 
00096     return;
00097 }
00098 
00099 void CScanner::GetYZIntersectionPoints(sPoint3f   eye, sVector3f ray)
00100 {
00101     sPoint3f yz_n,  yz_f;
00102     float    tp,    tm;
00103 
00104     /*
00105      * if x component of ray is 0, we're parallel to the y-z plane
00106      */
00107     if ( !ray.x )
00108     {
00109         return;
00110     }
00111     else
00112     {
00113         tp = ( _range.x - eye.x) / ray.x;
00114         tm = ( - _range.x - eye.x ) / ray.x;
00115     
00116         yz_n.x = eye.x + tm * ray.x;
00117         yz_n.y = eye.y + tm * ray.y;
00118         yz_n.z = eye.z + tm * ray.z;
00119 
00120         yz_f.x = eye.x + tp * ray.x;
00121         yz_f.y = eye.y + tp * ray.y;
00122         yz_f.z = eye.z + tp * ray.z;
00123     }
00124 
00125     /*
00126      * Test the near and far points to see if they fall within the volume
00127      */
00128 
00129     sPoint3f nearPoint( abs(yz_n.x) , abs(yz_n.y), abs(yz_n.z));
00130     sPoint3f farPoint( abs(yz_f.x), abs(yz_f.y), abs(yz_f.z));
00131 
00132     if ( nearPoint.x <= _range.x && 
00133          nearPoint.y <= _range.y &&
00134          nearPoint.z <= _range.z    )
00135     {
00136         if ( _iXCount >= 2 )
00137             throw;
00138 
00139         _aIntersectionPoints[_iXCount++].Set(yz_n);
00140     }
00141 
00142     if ( farPoint.x <= _range.x && 
00143          farPoint.y <= _range.y &&
00144          farPoint.z <= _range.z    )
00145     {
00146         if ( _iXCount >= 2 )
00147             throw;
00148 
00149         _aIntersectionPoints[_iXCount++].Set(yz_f);
00150     }
00151     
00152     return;
00153 }
00154 
00155 void CScanner::GetXZIntersectionPoints(sPoint3f   eye, sVector3f ray)
00156 {
00157     sPoint3f xz_n,  xz_f;
00158     float    tp,    tm;
00159 
00160     /*
00161      * if y component of ray is 0, we're parallel to the x-z plane
00162      */
00163     if ( !ray.y )
00164     {
00165         return;
00166     }
00167     else
00168     {
00169         tp = ( _range.y - eye.y) / ray.y;
00170         tm = ( - _range.y - eye.y ) / ray.y;
00171     
00172         xz_n.x = eye.x + tm * ray.x;
00173         xz_n.y = eye.y + tm * ray.y;
00174         xz_n.z = eye.z + tm * ray.z;
00175 
00176         xz_f.x = eye.x + tp * ray.x;
00177         xz_f.y = eye.y + tp * ray.y;
00178         xz_f.z = eye.z + tp * ray.z;
00179     }
00180 
00181     /*
00182      * Test the near and far points to see if they fall within the volume
00183      */
00184 
00185     sPoint3f nearPoint( abs(xz_n.x) , abs(xz_n.y), abs(xz_n.z));
00186     sPoint3f farPoint( abs(xz_f.x), abs(xz_f.y), abs(xz_f.z));
00187 
00188     if ( nearPoint.x <= _range.x && 
00189          nearPoint.y <= _range.y &&
00190          nearPoint.z <= _range.z    )
00191     {
00192         if ( _iXCount >= 2 )
00193             throw;
00194 
00195         _aIntersectionPoints[_iXCount++].Set(xz_n);
00196     }
00197 
00198     if ( farPoint.x <= _range.x && 
00199          farPoint.y <= _range.y &&
00200          farPoint.z <= _range.z    )
00201     {
00202         if ( _iXCount >= 2 )
00203             throw;
00204 
00205         _aIntersectionPoints[_iXCount++].Set(xz_f);
00206     }
00207     
00208     return;
00209 }

Generated on Mon Dec 12 15:20:26 2005 for CCube by  doxygen 1.4.1