doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Pluecker.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 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 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 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 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.
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 #include "../precompiled.h"
30 #pragma hdrstop
31 
32 idPluecker pluecker_origin( 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f );
33 
34 /*
35 ================
36 idPluecker::FromPlanes
37 
38  pluecker coordinate for the intersection of two planes
39 ================
40 */
41 bool idPluecker::FromPlanes( const idPlane &p1, const idPlane &p2 ) {
42 
43  p[0] = -( p1[2] * -p2[3] - p2[2] * -p1[3] );
44  p[1] = -( p2[1] * -p1[3] - p1[1] * -p2[3] );
45  p[2] = p1[1] * p2[2] - p2[1] * p1[2];
46 
47  p[3] = -( p1[0] * -p2[3] - p2[0] * -p1[3] );
48  p[4] = p1[0] * p2[1] - p2[0] * p1[1];
49  p[5] = p1[0] * p2[2] - p2[0] * p1[2];
50 
51  return ( p[2] != 0.0f || p[5] != 0.0f || p[4] != 0.0f );
52 }
53 
54 /*
55 ================
56 idPluecker::Distance3DSqr
57 
58  calculates square of shortest distance between the two
59  3D lines represented by their pluecker coordinates
60 ================
61 */
62 float idPluecker::Distance3DSqr( const idPluecker &a ) const {
63  float d, s;
64  idVec3 dir;
65 
66  dir[0] = -a.p[5] * p[4] - a.p[4] * -p[5];
67  dir[1] = a.p[4] * p[2] - a.p[2] * p[4];
68  dir[2] = a.p[2] * -p[5] - -a.p[5] * p[2];
69  if ( dir[0] == 0.0f && dir[1] == 0.0f && dir[2] == 0.0f ) {
70  return -1.0f; // FIXME: implement for parallel lines
71  }
72  d = a.p[4] * ( p[2]*dir[1] - -p[5]*dir[0]) +
73  a.p[5] * ( p[2]*dir[2] - p[4]*dir[0]) +
74  a.p[2] * (-p[5]*dir[2] - p[4]*dir[1]);
75  s = PermutedInnerProduct( a ) / d;
76  return ( dir * dir ) * ( s * s );
77 }
78 
79 /*
80 =============
81 idPluecker::ToString
82 =============
83 */
84 const char *idPluecker::ToString( int precision ) const {
85  return idStr::FloatArrayToString( ToFloatPtr(), GetDimension(), precision );
86 }
Definition: Vector.h:316
static const char * FloatArrayToString(const float *array, const int length, const int precision)
Definition: Str.cpp:418
int GetDimension(void) const
Definition: Pluecker.h:356
GLdouble s
Definition: glext.h:2935
const char * ToString(int precision=2) const
Definition: Pluecker.cpp:84
idPluecker pluecker_origin(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)
bool FromPlanes(const idPlane &p1, const idPlane &p2)
Definition: Pluecker.cpp:41
Definition: Plane.h:71
float PermutedInnerProduct(const idPluecker &a) const
Definition: Pluecker.h:316
GLubyte GLubyte GLubyte a
Definition: glext.h:4662
const float * ToFloatPtr(void) const
Definition: Pluecker.h:360
tuple f
Definition: idal.py:89
float p[6]
Definition: Pluecker.h:89
float Distance3DSqr(const idPluecker &a) const
Definition: Pluecker.cpp:62
GLfloat GLfloat p
Definition: glext.h:4674