00001 /*---------------------------------------------------------------------------*\ 00002 * OpenSG * 00003 * * 00004 * * 00005 * Copyright (C) 2000-2002 by the OpenSG Forum * 00006 * * 00007 * www.opensg.org * 00008 * * 00009 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de * 00010 * * 00011 \*---------------------------------------------------------------------------*/ 00012 /*---------------------------------------------------------------------------*\ 00013 * License * 00014 * * 00015 * This library is free software; you can redistribute it and/or modify it * 00016 * under the terms of the GNU Library General Public License as published * 00017 * by the Free Software Foundation, version 2. * 00018 * * 00019 * This library is distributed in the hope that it will be useful, but * 00020 * WITHOUT ANY WARRANTY; without even the implied warranty of * 00021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00022 * Library General Public License for more details. * 00023 * * 00024 * You should have received a copy of the GNU Library General Public * 00025 * License along with this library; if not, write to the Free Software * 00026 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 00027 * * 00028 \*---------------------------------------------------------------------------*/ 00029 /*---------------------------------------------------------------------------*\ 00030 * Changes * 00031 * * 00032 * * 00033 * * 00034 * * 00035 * * 00036 * * 00037 \*---------------------------------------------------------------------------*/ 00038 00039 #ifndef _OSGINTERSECTACTION_H_ 00040 #define _OSGINTERSECTACTION_H_ 00041 #ifdef __sgi 00042 #pragma once 00043 #endif 00044 00045 //--------------------------------------------------------------------------- 00046 // Includes 00047 //--------------------------------------------------------------------------- 00048 00049 #include <vector> 00050 00051 #include <OSGSystemDef.h> 00052 #include <OSGBaseTypes.h> 00053 #include <OSGAction.h> 00054 00055 OSG_BEGIN_NAMESPACE 00056 00057 //--------------------------------------------------------------------------- 00058 // Forward References 00059 //--------------------------------------------------------------------------- 00060 00061 class Node; 00062 00063 //--------------------------------------------------------------------------- 00064 // Types 00065 //--------------------------------------------------------------------------- 00066 00067 //--------------------------------------------------------------------------- 00068 // Class 00069 //--------------------------------------------------------------------------- 00070 00074 class OSG_SYSTEMLIB_DLLMAPPING IntersectAction : public Action 00075 { 00076 public: 00077 00078 //----------------------------------------------------------------------- 00079 // enums 00080 //----------------------------------------------------------------------- 00081 00082 //----------------------------------------------------------------------- 00083 // types 00084 //----------------------------------------------------------------------- 00085 00086 //----------------------------------------------------------------------- 00087 // class functions 00088 //----------------------------------------------------------------------- 00089 00090 static const char *getClassname(void) { return "IntersectAction"; }; 00091 00092 // create a new IntersectAction by cloning the prototype 00093 static IntersectAction * create( void ); 00094 static IntersectAction * create( const Line &line, 00095 const Real32 maxdist = Inf ); 00096 00097 // prototype access 00098 // after setting the prototype all new IntersectActions are clones of it 00099 static void setPrototype( IntersectAction * proto ); 00100 static IntersectAction *getPrototype( void ); 00101 00102 //----------------------------------------------------------------------- 00103 // instance functions 00104 //----------------------------------------------------------------------- 00105 00106 IntersectAction& operator =(const IntersectAction &source); 00107 00108 virtual ~IntersectAction(void); 00109 00110 /*------------------------- your_category -------------------------------*/ 00111 00112 /*------------------------- access ------------------------------*/ 00113 00114 // set input data 00115 void setLine( const Line &line, const Real32 maxdist = Inf ); 00116 00117 // get input data 00118 inline const Line& getLine( void ) const; 00119 inline Real32 getMaxDist( void ) const; 00120 00121 // get result data 00122 inline bool didHit( void ) const; 00123 00124 inline Real32 getHitT( void ) const; 00125 00126 inline Pnt3f getHitPoint( void ) const; 00127 00128 inline Vec3f getHitNormal( void ) const; 00129 00130 inline NodePtr getHitObject( void ) const; 00131 00132 inline Int32 getHitTriangle( void ) const; 00133 00134 00135 // to be used by the traversed nodes 00136 // set (temporary) results 00137 Action::ResultE setEnterLeave( Real32 enter, Real32 leave ); 00138 void setHit( Real32 t, NodePtr obj, Int32 triIndex, Vec3f &normal ); 00139 00140 // when entering/leaving a different coordinate system, the values might 00141 // have to be scaled 00142 void scale(Real32 s); 00143 00144 00145 /*------------------------- your_operators ------------------------------*/ 00146 00147 00148 /*------------------------- assignment ----------------------------------*/ 00149 00150 /*------------------------- comparison ----------------------------------*/ 00151 00152 bool operator < (const IntersectAction &other) const; 00153 00154 bool operator == (const IntersectAction &other) const; 00155 bool operator != (const IntersectAction &other) const; 00156 00157 00158 // default registration. static, so it can be called during static init 00159 00160 static void registerEnterDefault( const FieldContainerType &type, 00161 const Action::Functor &func); 00162 00163 static void registerLeaveDefault( const FieldContainerType &type, 00164 const Action::Functor &func); 00165 00166 protected: 00167 00168 //----------------------------------------------------------------------- 00169 // enums 00170 //----------------------------------------------------------------------- 00171 00172 //----------------------------------------------------------------------- 00173 // types 00174 //----------------------------------------------------------------------- 00175 00176 //----------------------------------------------------------------------- 00177 // class variables 00178 //----------------------------------------------------------------------- 00179 00180 //----------------------------------------------------------------------- 00181 // class functions 00182 //----------------------------------------------------------------------- 00183 00184 //----------------------------------------------------------------------- 00185 // instance variables 00186 //----------------------------------------------------------------------- 00187 00188 //----------------------------------------------------------------------- 00189 // instance functions 00190 //----------------------------------------------------------------------- 00191 00192 IntersectAction(void); 00193 IntersectAction(const IntersectAction &source); 00194 00195 virtual Action::ResultE start( void ); 00196 00197 // access default functors 00198 00199 virtual std::vector<Functor>* getDefaultEnterFunctors( void ); 00200 virtual std::vector<Functor>* getDefaultLeaveFunctors( void ); 00201 00202 private: 00203 00204 //----------------------------------------------------------------------- 00205 // enums 00206 //----------------------------------------------------------------------- 00207 00208 //----------------------------------------------------------------------- 00209 // types 00210 //----------------------------------------------------------------------- 00211 00212 typedef Action Inherited; 00213 00214 //----------------------------------------------------------------------- 00215 // friend classes 00216 //----------------------------------------------------------------------- 00217 00218 //----------------------------------------------------------------------- 00219 // friend functions 00220 //----------------------------------------------------------------------- 00221 00222 //----------------------------------------------------------------------- 00223 // class variables 00224 //----------------------------------------------------------------------- 00225 00226 static char cvsid[]; 00227 00228 // the prototype which is copied to create new actions 00229 static IntersectAction * _prototype; 00230 00231 // default functors for instantiation 00232 static std::vector<Functor> *_defaultEnterFunctors; 00233 static std::vector<Functor> *_defaultLeaveFunctors; 00234 00235 //----------------------------------------------------------------------- 00236 // class functions 00237 //----------------------------------------------------------------------- 00238 00239 //----------------------------------------------------------------------- 00240 // instance variables 00241 //----------------------------------------------------------------------- 00242 00243 // Line definition 00244 00245 // the line to be tested 00246 Line _line; 00247 00248 // the maximum distance along the line 00249 Real32 _maxdist; 00250 00251 // Results (also intermediate) 00252 // hit at all (either bv or face) 00253 bool _hit; 00254 // enter leave distance for bounding volume 00255 Real32 _enterT; 00256 Real32 _leaveT; 00257 00258 // Hit distance 00259 Real32 _hitT; 00260 // Hit object 00261 NodePtr _hitObject; 00262 // Index of the hit triangle ( from TriangleIterator::getIndex() ) 00263 Int32 _hitTriangle; 00264 // Normal of the hit triangle 00265 Vec3f _hitNormal; 00266 00267 //----------------------------------------------------------------------- 00268 // instance functions 00269 //----------------------------------------------------------------------- 00270 00271 }; 00272 00273 //--------------------------------------------------------------------------- 00274 // Exported Types 00275 //--------------------------------------------------------------------------- 00276 00277 // class pointer 00278 00279 typedef IntersectAction *IntersectActionP; 00280 00281 OSG_END_NAMESPACE 00282 00283 #include "OSGIntersectAction.inl" 00284 00285 #endif /* _OSGRENDERACTION_H_ */
1.4.3