Open Inventor Reference
|
00001 /* 00002 * 00003 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * Further, this software is distributed without any warranty that it is 00016 * free of the rightful claim of any third person regarding infringement 00017 * or the like. Any license provided herein, whether implied or 00018 * otherwise, applies only to this software file. Patent licenses, if 00019 * any, provided herein do not apply to combinations of this program with 00020 * other software, or any other product whatsoever. 00021 * 00022 * You should have received a copy of the GNU Lesser General Public 00023 * License along with this library; if not, write to the Free Software 00024 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00025 * 00026 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, 00027 * Mountain View, CA 94043, or: 00028 * 00029 * http://www.sgi.com 00030 * 00031 * For further information regarding this notice, see: 00032 * 00033 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ 00034 * 00035 */ 00036 00037 00038 /* 00039 * Copyright (C) 1990,91 Silicon Graphics, Inc. 00040 * 00041 _______________________________________________________________________ 00042 ______________ S I L I C O N G R A P H I C S I N C . ____________ 00043 | 00044 | $Revision: 1.3 $ 00045 | 00046 | Description: 00047 | This file contains definitions of various linear algebra classes, 00048 | such as vectors, coordinates, etc.. 00049 | 00050 | Classes: 00051 | SbVec3f 00052 | SbVec2f 00053 | SbVec2s 00054 | SbVec3s //!< Extension to SGI OIV 2.1 00055 | SbVec4f 00056 | SbRotation 00057 | SbMatrix 00058 | SbViewVolume 00059 | 00060 | SbLine 00061 | SbPlane 00062 | SbSphere 00063 | 00064 | Author(s) : Paul S. Strauss, Nick Thompson, 00065 | David Mott, Alain Dumesny 00066 | 00067 ______________ S I L I C O N G R A P H I C S I N C . ____________ 00068 _______________________________________________________________________ 00069 */ 00070 00071 #ifndef _SB_LINEAR_ 00072 #define _SB_LINEAR_ 00073 00074 #include <Inventor/system/SbSystem.h> 00075 #include <math.h> 00076 #include <Inventor/SbBasic.h> 00077 00083 00084 typedef float SbMat[4][4]; 00085 00086 00087 class SbVec3f; 00088 class SbVec2f; 00089 class SbVec2s; 00090 class SbVec4f; 00091 class SbRotation; 00092 class SbMatrix; 00093 00094 class SbLine; 00095 class SbPlane; 00096 class SbCylinder; 00097 class SbSphere; 00098 00100 class SbBox3f; 00101 00102 00103 00104 00107 00118 00119 00120 class INVENTOR_API SbVec3f { 00121 public: 00122 00124 SbVec3f() { } 00125 00127 SbVec3f(const float v[3]) 00128 { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; } 00129 00131 SbVec3f(float x, float y, float z) 00132 { vec[0] = x; vec[1] = y; vec[2] = z; } 00133 00135 SbVec3f(SbPlane &p0, SbPlane &p1, SbPlane &p2); 00136 00138 SbVec3f cross(const SbVec3f &v) const; 00139 00141 float dot(const SbVec3f &v) const; 00142 00144 const float *getValue() const { return vec; } 00145 00147 void getValue(float &x, float &y, float &z) const; 00148 00150 float length() const; 00151 00153 float normalize(); 00154 00156 void negate(); 00157 00159 SbVec3f & setValue(const float v[3]) 00160 { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; return *this; } 00161 00163 SbVec3f & setValue(float x, float y, float z) 00164 { vec[0] = x; vec[1] = y; vec[2] = z; return *this; } 00165 00168 SbVec3f & setValue(const SbVec3f &barycentic, 00169 const SbVec3f &v0, const SbVec3f &v1, const SbVec3f &v2); 00170 00172 float & operator [](int i) { return (vec[i]); } 00173 const float & operator [](int i) const { return (vec[i]); } 00174 00176 SbVec3f & operator *=(float d); 00177 00179 SbVec3f & operator /=(float d) 00180 { return *this *= (1.0f / d); } 00181 00183 SbVec3f & operator +=(SbVec3f v); 00185 SbVec3f & operator -=(SbVec3f v); 00186 00188 SbVec3f operator -() const; 00189 00191 friend INVENTOR_API SbVec3f operator *(const SbVec3f &v, float d); 00192 friend INVENTOR_API SbVec3f operator *(float d, const SbVec3f &v) 00193 { return v * d; } 00194 friend INVENTOR_API SbVec3f operator /(const SbVec3f &v, float d) 00195 { return v * (1.0f / d); } 00196 00198 friend INVENTOR_API SbVec3f operator +(const SbVec3f &v1, const SbVec3f &v2); 00199 00200 friend INVENTOR_API SbVec3f operator -(const SbVec3f &v1, const SbVec3f &v2); 00201 00203 friend INVENTOR_API int operator ==(const SbVec3f &v1, const SbVec3f &v2); 00204 friend INVENTOR_API int operator !=(const SbVec3f &v1, const SbVec3f &v2) 00205 { return !(v1 == v2); } 00206 00209 SbBool equals(const SbVec3f v, float tolerance) const; 00210 00213 SbVec3f getClosestAxis() const; 00214 00215 protected: 00216 float vec[3]; 00217 }; 00218 00219 00220 00221 00224 00235 00236 00237 class INVENTOR_API SbVec2f { 00238 public: 00239 00241 SbVec2f() { } 00242 00244 SbVec2f(const float v[2]) { setValue(v); } 00245 00247 SbVec2f(float x, float y) { setValue(x, y); } 00248 00250 float dot(const SbVec2f &v) const; 00251 00253 const float *getValue() const { return vec; } 00254 00256 void getValue(float &x, float &y) const; 00257 00259 float length() const; 00260 00262 void negate(); 00263 00265 float normalize(); 00266 00268 SbVec2f & setValue(const float v[2]); 00269 00271 SbVec2f & setValue(float x, float y); 00272 00274 float & operator [](int i) { return (vec[i]); } 00275 const float & operator [](int i) const { return (vec[i]); } 00276 00278 SbVec2f & operator *=(float d); 00279 00281 SbVec2f & operator /=(float d) 00282 { return *this *= (1.0f / d); } 00283 00285 SbVec2f & operator +=(const SbVec2f &u); 00287 SbVec2f & operator -=(const SbVec2f &u); 00288 00290 SbVec2f operator -() const; 00291 00293 friend INVENTOR_API SbVec2f operator *(const SbVec2f &v, float d); 00294 friend INVENTOR_API SbVec2f operator *(float d, const SbVec2f &v) 00295 { return v * d; } 00296 friend INVENTOR_API SbVec2f operator /(const SbVec2f &v, float d) 00297 { return v * (1.0f / d); } 00298 00300 friend INVENTOR_API SbVec2f operator +(const SbVec2f &v1, const SbVec2f &v2); 00301 00302 friend INVENTOR_API SbVec2f operator -(const SbVec2f &v1, const SbVec2f &v2); 00303 00305 friend INVENTOR_API int operator ==(const SbVec2f &v1, const SbVec2f &v2); 00306 friend INVENTOR_API int operator !=(const SbVec2f &v1, const SbVec2f &v2) 00307 { return !(v1 == v2); } 00308 00311 SbBool equals(const SbVec2f v, float tolerance) const; 00312 00313 protected: 00314 float vec[2]; 00315 }; 00316 00317 00318 00319 00322 00333 00334 00335 class INVENTOR_API SbVec2s { 00336 public: 00337 00339 SbVec2s() { } 00340 00342 SbVec2s(const short v[2]) { setValue(v); } 00343 00345 SbVec2s(short x, short y) { setValue(x, y); } 00346 00348 int32_t dot(const SbVec2s &v) const; 00349 00351 const short *getValue() const { return vec; } 00352 00354 void getValue(short &x, short &y) const; 00355 00357 void negate(); 00358 00360 SbVec2s & setValue(const short v[2]); 00361 00363 SbVec2s & setValue(short x, short y); 00364 00366 short & operator [](int i) { return (vec[i]); } 00367 const short & operator [](int i) const { return (vec[i]); } 00368 00370 SbVec2s & operator *=(int d); 00372 SbVec2s & operator *=(double d); 00373 00375 SbVec2s & operator /=(int d); 00377 SbVec2s & operator /=(double d) 00378 { return *this *= (1.0 / d); } 00379 00381 SbVec2s & operator +=(const SbVec2s &u); 00383 SbVec2s & operator -=(const SbVec2s &u); 00384 00386 SbVec2s operator -() const; 00387 00389 friend INVENTOR_API SbVec2s operator *(const SbVec2s &v, int d); 00390 friend INVENTOR_API SbVec2s operator *(const SbVec2s &v, double d); 00391 friend INVENTOR_API SbVec2s operator *(int d, const SbVec2s &v) 00392 { return v * d; } 00393 friend INVENTOR_API SbVec2s operator *(double d, const SbVec2s &v) 00394 { return v * d; } 00395 friend INVENTOR_API SbVec2s operator /(const SbVec2s &v, int d); 00396 friend INVENTOR_API SbVec2s operator /(const SbVec2s &v, double d) 00397 { return v * (1.0 / d); } 00398 00400 friend INVENTOR_API SbVec2s operator +(const SbVec2s &v1, const SbVec2s &v2); 00401 00402 friend INVENTOR_API SbVec2s operator -(const SbVec2s &v1, const SbVec2s &v2); 00403 00405 friend INVENTOR_API int operator ==(const SbVec2s &v1, const SbVec2s &v2); 00406 friend INVENTOR_API int operator !=(const SbVec2s &v1, const SbVec2s &v2) 00407 { return !(v1 == v2); } 00408 00409 protected: 00410 short vec[2]; 00411 }; 00412 00421 00422 class INVENTOR_API SbVec3s { 00423 public: 00424 00426 SbVec3s() { } 00427 00429 SbVec3s(const short v[3]) { setValue(v); } 00430 00432 SbVec3s(short x, short y, short z) { setValue(x, y, z); } 00433 00435 int32_t dot(const SbVec3s &v) const; 00436 00438 const short *getValue() const { return vec; } 00439 00441 void getValue(short &x, short &y, short &z) const; 00442 00444 void negate(); 00445 00447 SbVec3s & setValue(const short v[3]); 00448 00450 SbVec3s & setValue(short x, short y, short z); 00451 00453 short & operator [](int i) { return (vec[i]); } 00454 const short & operator [](int i) const { return (vec[i]); } 00455 00457 SbVec3s & operator *=(int d); 00458 SbVec3s & operator *=(double d); 00459 00460 SbVec3s & operator /=(int d); 00461 SbVec3s & operator /=(double d) 00462 { return *this *= (1.0 / d); } 00463 00465 SbVec3s & operator +=(const SbVec3s &u); 00467 SbVec3s & operator -=(const SbVec3s &u); 00468 00470 SbVec3s operator -() const; 00471 00473 friend INVENTOR_API SbVec3s operator *(const SbVec3s &v, int d); 00474 friend INVENTOR_API SbVec3s operator *(const SbVec3s &v, double d); 00475 friend INVENTOR_API SbVec3s operator *(int d, const SbVec3s &v) 00476 { return v * d; } 00477 friend INVENTOR_API SbVec3s operator *(double d, const SbVec3s &v) 00478 { return v * d; } 00479 friend INVENTOR_API SbVec3s operator /(const SbVec3s &v, int d); 00480 friend INVENTOR_API SbVec3s operator /(const SbVec3s &v, double d) 00481 { return v * (1.0 / d); } 00482 00484 friend INVENTOR_API SbVec3s operator +(const SbVec3s &v1, const SbVec3s &v2); 00485 00486 friend INVENTOR_API SbVec3s operator -(const SbVec3s &v1, const SbVec3s &v2); 00487 00489 friend INVENTOR_API int operator ==(const SbVec3s &v1, const SbVec3s &v2); 00490 friend INVENTOR_API int operator !=(const SbVec3s &v1, const SbVec3s &v2) 00491 { return !(v1 == v2); } 00492 00493 protected: 00494 short vec[3]; 00495 }; 00496 00497 00498 00499 00502 00513 00514 00515 class INVENTOR_API SbVec4f { 00516 public: 00517 00519 SbVec4f() { } 00520 00522 SbVec4f(const float v[4]) { setValue(v); } 00523 00525 SbVec4f(float x, float y, float z, float w) { setValue(x, y, z, w); } 00526 00528 float dot(const SbVec4f &v) const; 00529 00531 void getReal(SbVec3f &v) const; 00532 00534 const float *getValue() const { return vec; } 00535 00537 void getValue(float &x, float &y, float &z, float &w) const; 00538 00540 float length() const; 00541 00543 void negate(); 00544 00546 float normalize(); 00547 00549 SbVec4f & setValue(const float v[4]); 00550 00552 SbVec4f & setValue(float x, float y, float z, float w); 00553 00555 float & operator [](int i) { return (vec[i]); } 00556 const float & operator [](int i) const { return (vec[i]); } 00557 00559 SbVec4f & operator *=(float d); 00560 00562 SbVec4f & operator /=(float d) 00563 { return *this *= (1.0f / d); } 00564 00566 SbVec4f & operator +=(const SbVec4f &u); 00568 SbVec4f & operator -=(const SbVec4f &u); 00569 00571 SbVec4f operator -() const; 00572 00574 friend INVENTOR_API SbVec4f operator *(const SbVec4f &v, float d); 00575 friend INVENTOR_API SbVec4f operator *(float d, const SbVec4f &v) 00576 { return v * d; } 00577 friend INVENTOR_API SbVec4f operator /(const SbVec4f &v, float d) 00578 { return v * (1.0f / d); } 00579 00581 friend INVENTOR_API SbVec4f operator +(const SbVec4f &v1, const SbVec4f &v2); 00582 00583 friend INVENTOR_API SbVec4f operator -(const SbVec4f &v1, const SbVec4f &v2); 00584 00586 friend INVENTOR_API int operator ==(const SbVec4f &v1, const SbVec4f &v2); 00587 friend INVENTOR_API int operator !=(const SbVec4f &v1, const SbVec4f &v2) 00588 { return !(v1 == v2); } 00589 00592 SbBool equals(const SbVec4f v, float tolerance) const; 00593 00594 protected: 00595 float vec[4]; 00596 }; 00597 00598 00599 00600 00603 00619 00620 00621 class INVENTOR_API SbRotation { 00622 public: 00623 00625 SbRotation() 00626 {} 00627 00629 SbRotation(const float v[4]) 00630 { setValue(v); } 00631 00633 SbRotation(float q0, float q1, float q2, float q3) 00634 { setValue(q0, q1, q2, q3); } 00635 00637 SbRotation(const SbMatrix &m) 00638 { setValue(m); } 00639 00641 SbRotation(const SbVec3f &axis, float radians) 00642 { setValue(axis, radians); } 00643 00653 SbRotation(const SbVec3f &rotateFrom, const SbVec3f &rotateTo) 00654 { setValue(rotateFrom, rotateTo); } 00655 00657 const float * getValue() const 00658 { return (quat); } 00659 00661 void getValue(float &q0, float &q1, 00662 float &q2, float &q3) const; 00663 00665 void getValue(SbVec3f &axis, float &radians) const; 00666 00668 void getValue(SbMatrix &matrix) const; 00669 00671 SbRotation & invert(); 00672 00674 SbRotation inverse() const 00675 { SbRotation q = *this; return q.invert(); } 00676 00678 SbRotation & setValue(const float q[4]); 00679 00681 SbRotation & setValue(float q0, float q1, float q2, float q3); 00682 00684 SbRotation & setValue(const SbMatrix &m); 00685 00687 SbRotation & setValue(const SbVec3f &axis, float radians); 00688 00690 SbRotation & setValue(const SbVec3f &rotateFrom, 00691 const SbVec3f &rotateTo); 00692 00694 SbRotation & operator *=(const SbRotation &q); 00695 00697 friend INVENTOR_API int operator ==(const SbRotation &q1, const SbRotation &q2); 00698 friend INVENTOR_API int operator !=(const SbRotation &q1, const SbRotation &q2) 00699 { return !(q1 == q2); } 00700 00703 SbBool equals(const SbRotation &r, float tolerance) const; 00704 00706 friend INVENTOR_API SbRotation operator *(const SbRotation &q1, const SbRotation &q2); 00707 00709 void multVec(const SbVec3f &src, SbVec3f &dst) const; 00710 00713 void scaleAngle( float scaleFactor ); 00714 00717 static SbRotation slerp(const SbRotation &rot0, 00718 const SbRotation &rot1, float t); 00719 00721 static SbRotation identity() 00722 { return SbRotation(0.0, 0.0, 0.0, 1.0); } 00723 00724 private: 00725 float quat[4]; 00726 00728 float norm() const; 00729 00731 void normalize(); 00732 }; 00733 00734 00735 00736 00739 00750 00751 00752 class INVENTOR_API SbMatrix { 00753 public: 00754 00756 SbMatrix() { } 00757 00759 SbMatrix(float a11, float a12, float a13, float a14, 00760 float a21, float a22, float a23, float a24, 00761 float a31, float a32, float a33, float a34, 00762 float a41, float a42, float a43, float a44); 00763 00765 SbMatrix(const SbMat &m); 00766 00768 void setValue(const SbMat &m); 00769 00771 void setValue(const float* data); 00772 00773 public: 00774 00776 void makeIdentity(); 00777 00779 static SbMatrix identity(); 00780 00782 void setRotate(const SbRotation &q); 00783 00785 void setScale(float s); 00786 00788 void setScale(const SbVec3f &s); 00789 00791 void setTranslate(const SbVec3f &t); 00792 00797 void setTransform( 00798 const SbVec3f &translation, 00799 const SbRotation &rotation, 00800 const SbVec3f &scaleFactor, 00801 const SbRotation &scaleOrientation, 00802 const SbVec3f ¢er); 00805 void setTransform(const SbVec3f &t, const SbRotation &r, 00806 const SbVec3f &s) 00807 { setTransform(t, r, s, 00808 SbRotation(0,0,0,1), SbVec3f(0,0,0)); } 00809 void setTransform(const SbVec3f &t, const SbRotation &r, 00810 const SbVec3f &s, const SbRotation &so) 00811 { setTransform(t, r, s, so, SbVec3f(0,0,0)); } 00812 00820 void getTransform(SbVec3f &translation, 00821 SbRotation &rotation, 00822 SbVec3f &scaleFactor, 00823 SbRotation &scaleOrientation, 00824 const SbVec3f ¢er) const; 00825 void getTransform(SbVec3f &t, SbRotation &r, 00826 SbVec3f &s, SbRotation &so) const 00827 { getTransform(t, r, s, so, SbVec3f(0,0,0)); } 00828 00829 00831 00833 void getValue(SbMat &m) const; 00834 const SbMat & getValue() const { return matrix; } 00835 00838 float det3(int r1, int r2, int r3, int c1, int c2, int c3) const; 00839 00841 float det3() const { return det3(0, 1, 2, 0, 1, 2); } 00842 00844 float det4() const; 00845 00851 SbBool factor(SbMatrix &r, SbVec3f &s, SbMatrix &u, 00852 SbVec3f &t, SbMatrix &proj) const; 00853 00856 SbMatrix inverse() const; 00857 00860 SbBool LUDecomposition(int index[4], float &d); 00861 00864 void LUBackSubstitution(int index[4], float b[4]) const; 00865 00867 SbMatrix transpose() const; 00868 00870 SbMatrix & multRight(const SbMatrix &m); // this = this * m 00872 SbMatrix & multLeft(const SbMatrix &m); // this = m * this 00873 00875 void multMatrixVec(const SbVec3f &src, SbVec3f &dst) const; 00876 00878 void multVecMatrix(const SbVec3f &src, SbVec3f &dst) const; 00880 void multVecMatrix(const SbVec4f &src, SbVec4f &dst) const; 00882 void multVecMatrix(const SbVec3f &src, SbVec4f &dst) const; 00883 00892 void multDirMatrix(const SbVec3f &src, SbVec3f &dst) const; 00893 00896 void multLineMatrix(const SbLine &src, SbLine &dst) const; 00897 00899 void print(FILE *fp) const; 00900 00902 operator float *() { return &matrix[0][0]; } 00903 00905 operator SbMat &() { return matrix; } 00906 00908 float * operator [](int i) { return &matrix[i][0]; } 00909 const float * operator [](int i) const { return &matrix[i][0]; } 00910 00912 SbMatrix & operator =(const SbMat &m); 00913 00915 SbMatrix & operator =(const SbMatrix &m); 00916 00918 SbMatrix & operator =(const SbRotation &q) { setRotate(q); return *this; } 00919 00921 SbMatrix & operator *=(const SbMatrix &m) { return multRight(m); } 00922 00924 friend INVENTOR_API SbMatrix operator *(const SbMatrix &m1, const SbMatrix &m2); 00925 00927 friend INVENTOR_API int operator ==(const SbMatrix &m1, const SbMatrix &m2); 00928 friend INVENTOR_API int operator !=(const SbMatrix &m1, const SbMatrix &m2) 00929 { return !(m1 == m2); } 00930 00932 SbBool equals(const SbMatrix &m, float tolerance) const; 00933 00934 private: 00935 SbMat matrix; 00936 00938 void jacobi3(float evalues[3], SbVec3f evectors[3], int &rots) const; 00939 00940 SbBool affine_inverse(const SbMatrix &in, SbMatrix &out) const; 00941 }; 00942 00943 00944 00947 00959 00960 00961 class INVENTOR_API SbViewVolume { 00962 public: 00963 00965 SbViewVolume(); 00967 ~SbViewVolume() {} 00968 00973 void getMatrices(SbMatrix &affine, SbMatrix &proj) const; 00974 00977 SbMatrix getMatrix() const; 00978 00983 SbMatrix getCameraSpaceMatrix() const; 00984 00986 void projectPointToLine(const SbVec2f &pt, 00987 SbLine &line) const; 00988 void projectPointToLine(const SbVec2f &pt, 00989 SbVec3f &line0, SbVec3f &line1) const; 00990 00996 void projectToScreen(const SbVec3f &src, 00997 SbVec3f &dst) const; 00998 01001 SbPlane getPlane(float distFromEye) const; 01002 01005 SbVec3f getSightPoint(float distFromEye) const; 01006 01010 SbVec3f getPlanePoint(float distFromEye, 01011 const SbVec2f &normPoint) const; 01012 01018 SbRotation getAlignRotation(SbBool rightAngleOnly = FALSE) const; 01019 01023 float getWorldToScreenScale(const SbVec3f &worldCenter, 01024 float normRadius) const; 01025 01029 SbVec2f projectBox(const SbBox3f &box) const; 01030 01035 SbViewVolume narrow(float left, float bottom, 01036 float right, float top) const; 01037 01041 SbViewVolume narrow(const SbBox3f &box) const; 01042 01045 void ortho(float left, float right, 01046 float bottom, float top, 01047 float nearVal, float farVal); 01048 01053 void perspective(float fovy, float aspect, 01054 float nearVal, float farVal); 01055 01059 void rotateCamera(const SbRotation &q); 01060 01064 void translateCamera(const SbVec3f &v); 01065 01069 SbVec3f zVector() const; 01070 01076 SbViewVolume zNarrow(float nearVal, float farVal) const; 01077 01079 void scale(float factor); 01080 01084 void scaleWidth(float ratio); 01088 void scaleHeight(float ratio); 01089 01091 enum ProjectionType { 01092 ORTHOGRAPHIC, 01093 PERSPECTIVE 01094 }; 01095 01097 ProjectionType getProjectionType() const { return type; } 01098 01100 const SbVec3f & getProjectionPoint() const { return projPoint; } 01101 01103 const SbVec3f & getProjectionDirection() const { return projDir; } 01104 01106 float getNearDist() const { return nearDist; } 01107 01109 float getWidth() const { return (lrfO-llfO).length(); } 01111 float getHeight() const { return (ulfO-llfO).length(); } 01113 float getDepth() const { return nearToFar; } 01114 01115 SoINTERNAL public: 01116 ProjectionType type; 01117 01120 SbVec3f projPoint; 01121 SbVec3f projDir; 01122 float nearDist; 01123 float nearToFar; 01124 SbVec3f llf; 01125 SbVec3f lrf; 01126 SbVec3f ulf; 01127 01132 void transform(const SbMatrix &matrix); 01133 01135 SbBool intersect(const SbVec3f &point) const; 01136 01140 SbBool intersect(const SbVec3f &p0, const SbVec3f &p1, 01141 SbVec3f &closestPoint) const; 01142 01144 SbBool intersect(const SbBox3f &box) const; 01145 01148 SbBool outsideTest(const SbPlane &p, 01149 const SbVec3f &min, const SbVec3f &max) const; 01150 01151 private: 01154 SbVec3f llfO; 01155 SbVec3f lrfO; 01156 SbVec3f ulfO; 01157 }; 01158 01159 01160 01163 01175 01176 01177 class INVENTOR_API SbLine { 01178 public: 01181 SbLine() {} 01182 01185 SbLine(const SbVec3f &p0, const SbVec3f &p1); 01186 01188 void setValue(const SbVec3f &p0, const SbVec3f &p1); 01189 01194 SbBool getClosestPoints(const SbLine &line2, 01195 SbVec3f &ptOnThis, 01196 SbVec3f &ptOnLine2 ) const; 01197 01199 SbVec3f getClosestPoint(const SbVec3f &point) const; 01200 01202 const SbVec3f & getPosition() const { return pos; } 01204 const SbVec3f & getDirection() const { return dir; } 01205 01206 01207 SoINTERNAL public: 01209 SbBool intersect( const SbBox3f &box, 01210 SbVec3f &enter, SbVec3f &exit ) const; 01211 SbBool intersect( float angle, const SbBox3f &box ) const; 01212 SbBool intersect( float angle, const SbVec3f &point ) const; 01213 SbBool intersect( float angle, const SbVec3f &v0, 01214 const SbVec3f &v1, SbVec3f &pt ) const; 01215 SbBool intersect( const SbVec3f &v0, 01216 const SbVec3f &v1, 01217 const SbVec3f &v2, 01218 SbVec3f &pt, SbVec3f &barycentric, 01219 SbBool &front ) const; 01220 01221 private: 01224 SbVec3f pos; 01225 SbVec3f dir; 01226 }; 01227 01228 01229 01232 01243 01244 01245 class INVENTOR_API SbPlane { 01246 public: 01248 SbPlane() {} 01249 01252 SbPlane(const SbVec3f &p0, const SbVec3f &p1, const SbVec3f &p2); 01253 01256 SbPlane(const SbVec3f &n, float d); 01257 01260 SbPlane(const SbVec3f &n, const SbVec3f &p); 01261 01263 void offset(float d); 01264 01267 SbBool intersect(const SbLine &l, 01268 SbVec3f &intersection) const; 01269 01271 void transform(const SbMatrix &matrix); 01272 01275 SbBool isInHalfSpace(const SbVec3f &point) const; 01276 01278 float getDistance(const SbVec3f &point) const; 01279 01281 const SbVec3f & getNormal() const { return normalVec; } 01283 float getDistanceFromOrigin() const { return distance; } 01284 01286 friend INVENTOR_API int operator ==(const SbPlane &p1, const SbPlane &p2); 01287 friend INVENTOR_API int operator !=(const SbPlane &p1, const SbPlane &p2) 01288 { return !(p1 == p2); } 01289 01290 private: 01292 01294 SbVec3f normalVec; 01295 01297 float distance; 01298 }; 01299 01300 01303 01314 01315 01316 class INVENTOR_API SbCylinder { 01317 public: 01318 01320 SbCylinder(); 01321 01323 SbCylinder(const SbLine &a, float r); 01324 01326 void setValue(const SbLine &a, float r); 01327 01329 void setAxis(const SbLine &a); 01331 void setRadius(float r); 01332 01334 const SbLine & getAxis() const { return axis; } 01336 float getRadius() const { return radius; } 01337 01339 SbBool intersect(const SbLine &l, SbVec3f &intersection) const; 01340 SbBool intersect(const SbLine &l, 01341 SbVec3f &enter, SbVec3f &exit) const; 01342 01343 private: 01344 SbLine axis; 01345 float radius; 01346 01347 static SbBool unitCylinderIntersect(const SbLine &l, 01348 SbVec3f &in, SbVec3f &out); 01349 }; 01350 01351 01352 01353 01356 01368 01369 01370 class INVENTOR_API SbSphere { 01371 public: 01372 01374 SbSphere() {} 01375 01377 SbSphere(const SbVec3f &c, float r); 01378 01380 void setValue(const SbVec3f &c, float r); 01381 01383 void setCenter(const SbVec3f &c); 01385 void setRadius(float r); 01386 01388 const SbVec3f & getCenter() const { return center; } 01390 float getRadius() const { return radius; } 01391 01393 void circumscribe(const SbBox3f &box); 01394 01396 SbBool intersect(const SbLine &l, SbVec3f &intersection) const; 01397 SbBool intersect(const SbLine &l, SbVec3f &enter, SbVec3f &exit) const; 01398 01399 private: 01400 SbVec3f center; 01401 float radius; 01402 }; 01403 01404 #endif /* _SB_LINEAR_ */