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.1.1.1 $ 00045 | 00046 | Description: 00047 | Defines the SoRayPickAction class 00048 | 00049 | Author(s) : Paul S. Strauss, Nick Thompson 00050 | 00051 ______________ S I L I C O N G R A P H I C S I N C . ____________ 00052 _______________________________________________________________________ 00053 */ 00054 00055 #ifndef _SO_RAY_PICK_ACTION_ 00056 #define _SO_RAY_PICK_ACTION_ 00057 00058 #include <Inventor/system/SbSystem.h> 00059 #include <Inventor/SoLists.h> 00060 #include <Inventor/actions/SoPickAction.h> 00061 00062 00065 00095 00096 00097 class INVENTOR_API SoRayPickAction : public SoPickAction { 00098 00099 SO_ACTION_HEADER(SoRayPickAction); 00100 00101 public: 00102 00106 SoRayPickAction(const SbViewportRegion &viewportRegion); 00107 00109 virtual ~SoRayPickAction(); 00110 00115 00119 void setPoint(const SbVec2s &viewportPoint); 00120 00123 void setNormalizedPoint(const SbVec2f &normPoint); 00124 00131 void setRadius(float radiusInPixels); 00132 00143 void setRay(const SbVec3f &start, const SbVec3f &direction, 00144 float nearDistance = -1.0, 00145 float farDistance = -1.0); 00146 00149 void setPickAll(SbBool flag) { pickAll = flag; } 00152 SbBool isPickAll() const { return pickAll; } 00153 00158 00160 const SoPickedPointList &getPickedPointList() const { return ptList; } 00161 00163 SoPickedPoint * getPickedPoint(int index = 0) const; 00164 00165 SoEXTENDER public: 00166 00172 void computeWorldSpaceRay(); 00173 00176 SbBool hasWorldSpaceRay() const; 00177 00185 void setObjectSpace(); 00186 void setObjectSpace(const SbMatrix &matrix); 00187 00195 00198 SbBool intersect(const SbVec3f &v0, 00199 const SbVec3f &v1, 00200 const SbVec3f &v2, 00201 SbVec3f &intersection, SbVec3f &barycentric, 00202 SbBool &front) const; 00203 00205 SbBool intersect(const SbVec3f &v0, const SbVec3f &v1, 00206 SbVec3f &intersection) const; 00207 00209 SbBool intersect(const SbVec3f &point) const; 00210 00215 SbBool intersect(const SbBox3f &box, 00216 SbBool useFullViewVolume = TRUE); 00217 00225 const SbViewVolume &getViewVolume() const { return objVol; } 00226 00232 const SbLine & getLine() const { return objLine; } 00233 00240 SbBool isBetweenPlanes(const SbVec3f &intersection) const; 00241 00249 SoPickedPoint * addIntersection(const SbVec3f &objectSpacePoint); 00250 00251 protected: 00253 virtual void beginTraversal(SoNode *node); 00254 00255 SoINTERNAL public: 00256 static void initClass(); 00257 00258 private: 00259 SbBool lineWasSet; 00260 SbBool rayWasComputed; 00261 SbBool pickAll; 00262 SbVec2s VPPoint; 00263 SbVec2f normVPPoint; 00264 SbBool normPointSet; 00265 float VPRadius; 00266 SbMatrix objToWorld; 00267 SbMatrix worldToObj; 00268 SoPickedPointList ptList; 00269 00273 SbViewVolume worldVol; 00274 00279 SbBool clipToNear, clipToFar; 00280 00283 SbLine objLine; 00284 SbViewVolume objVol; 00285 00290 SbBool extraMatrixSet; 00291 SbMatrix extraMatrix; 00292 00294 void computeMatrices(); 00295 00297 void computeObjVolAndLine(); 00298 00301 SbBool isCloser(const SoPickedPoint *pp0, 00302 const SoPickedPoint *pp1); 00303 00306 static float rayDistance(const SbVec3f &start, 00307 const SbVec3f &direction, 00308 const SbVec3f &point); 00309 }; 00310 00311 #endif /* _SO_RAY_PICK_ACTION_ */