Pluecker.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 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 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 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 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 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. #include "../precompiled.h"
  21. #pragma hdrstop
  22. idPluecker pluecker_origin( 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f );
  23. /*
  24. ================
  25. idPluecker::FromPlanes
  26. pluecker coordinate for the intersection of two planes
  27. ================
  28. */
  29. bool idPluecker::FromPlanes( const idPlane &p1, const idPlane &p2 ) {
  30. p[0] = -( p1[2] * -p2[3] - p2[2] * -p1[3] );
  31. p[1] = -( p2[1] * -p1[3] - p1[1] * -p2[3] );
  32. p[2] = p1[1] * p2[2] - p2[1] * p1[2];
  33. p[3] = -( p1[0] * -p2[3] - p2[0] * -p1[3] );
  34. p[4] = p1[0] * p2[1] - p2[0] * p1[1];
  35. p[5] = p1[0] * p2[2] - p2[0] * p1[2];
  36. return ( p[2] != 0.0f || p[5] != 0.0f || p[4] != 0.0f );
  37. }
  38. /*
  39. ================
  40. idPluecker::Distance3DSqr
  41. calculates square of shortest distance between the two
  42. 3D lines represented by their pluecker coordinates
  43. ================
  44. */
  45. float idPluecker::Distance3DSqr( const idPluecker &a ) const {
  46. float d, s;
  47. idVec3 dir;
  48. dir[0] = -a.p[5] * p[4] - a.p[4] * -p[5];
  49. dir[1] = a.p[4] * p[2] - a.p[2] * p[4];
  50. dir[2] = a.p[2] * -p[5] - -a.p[5] * p[2];
  51. if ( dir[0] == 0.0f && dir[1] == 0.0f && dir[2] == 0.0f ) {
  52. return -1.0f; // FIXME: implement for parallel lines
  53. }
  54. d = a.p[4] * ( p[2]*dir[1] - -p[5]*dir[0]) +
  55. a.p[5] * ( p[2]*dir[2] - p[4]*dir[0]) +
  56. a.p[2] * (-p[5]*dir[2] - p[4]*dir[1]);
  57. s = PermutedInnerProduct( a ) / d;
  58. return ( dir * dir ) * ( s * s );
  59. }
  60. /*
  61. =============
  62. idPluecker::ToString
  63. =============
  64. */
  65. const char *idPluecker::ToString( int precision ) const {
  66. return idStr::FloatArrayToString( ToFloatPtr(), GetDimension(), precision );
  67. }