home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 March / Gamestar_82_2006-03_dvd.iso / DVDStar / Editace / quake4_sdkv10.exe / source / idlib / math / Pluecker.cpp < prev    next >
C/C++ Source or Header  |  2005-11-14  |  2KB  |  60 lines

  1.  
  2. #include "../precompiled.h"
  3. #pragma hdrstop
  4.  
  5. idPluecker pluecker_origin( 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f );
  6.  
  7. /*
  8. ================
  9. idPluecker::FromPlanes
  10.  
  11.   pluecker coordinate for the intersection of two planes
  12. ================
  13. */
  14. bool idPluecker::FromPlanes( const idPlane &p1, const idPlane &p2 ) {
  15.  
  16.     p[0] = -( p1[2] * -p2[3] - p2[2] * -p1[3] );
  17.     p[1] = -( p2[1] * -p1[3] - p1[1] * -p2[3] );
  18.     p[2] = p1[1] * p2[2] - p2[1] * p1[2];
  19.  
  20.     p[3] = -( p1[0] * -p2[3] - p2[0] * -p1[3] );
  21.     p[4] = p1[0] * p2[1] - p2[0] * p1[1];
  22.     p[5] = p1[0] * p2[2] - p2[0] * p1[2];
  23.  
  24.     return ( p[2] != 0.0f || p[5] != 0.0f || p[4] != 0.0f );
  25. }
  26.  
  27. /*
  28. ================
  29. idPluecker::Distance3DSqr
  30.  
  31.   calculates square of shortest distance between the two
  32.   3D lines represented by their pluecker coordinates
  33. ================
  34. */
  35. float idPluecker::Distance3DSqr( const idPluecker &a ) const {
  36.     float d, s;
  37.     idVec3 dir;
  38.  
  39.     dir[0] = -a.p[5] *  p[4] -  a.p[4] * -p[5];
  40.     dir[1] =  a.p[4] *  p[2] -  a.p[2] *  p[4];
  41.     dir[2] =  a.p[2] * -p[5] - -a.p[5] *  p[2];
  42.     if ( dir[0] == 0.0f && dir[1] == 0.0f && dir[2] == 0.0f ) {
  43.         return -1.0f;    // FIXME: implement for parallel lines
  44.     }
  45.     d = a.p[4] * (  p[2] * dir[1] - -p[5] * dir[0] ) +
  46.         a.p[5] * (  p[2] * dir[2] -  p[4] * dir[0] ) +
  47.         a.p[2] * ( -p[5] * dir[2] -  p[4] * dir[1] );
  48.     s = PermutedInnerProduct( a ) / d;
  49.     return ( dir * dir ) * ( s * s );
  50. }
  51.  
  52. /*
  53. =============
  54. idPluecker::ToString
  55. =============
  56. */
  57. const char *idPluecker::ToString( int precision ) const {
  58.     return idStr::FloatArrayToString( ToFloatPtr(), GetDimension(), precision );
  59. }
  60.