00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045
00046 #include "OSGConfig.h"
00047
00048 #include <OSGLog.h>
00049 #include <OSGFieldContainer.h>
00050 #include <OSGFieldContainerPtr.h>
00051 #include <OSGNode.h>
00052 #include <OSGNodeCore.h>
00053 #include <OSGAction.h>
00054 #include "OSGIntersectAction.h"
00055
00056 OSG_USING_NAMESPACE
00057
00058
00059
00060
00061
00062
00070
00071
00072
00073
00074
00075
00076
00077
00078 char IntersectAction::cvsid[] = "@(#)$Id: OSGIntersectAction.cpp,v 1.10 2001/10/15 04:52:15 vossg Exp $";
00079
00080 IntersectAction * IntersectAction::_prototype = NULL;
00081
00082 std::vector<Action::Functor> *IntersectAction::_defaultEnterFunctors;
00083 std::vector<Action::Functor> *IntersectAction::_defaultLeaveFunctors;
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 void IntersectAction::registerEnterDefault( const FieldContainerType &type,
00096 const Action::Functor &func )
00097 {
00098 if ( ! _defaultEnterFunctors )
00099 _defaultEnterFunctors = new std::vector<Action::Functor>;
00100
00101 while(type.getId() >= _defaultEnterFunctors->size())
00102 {
00103 _defaultEnterFunctors->push_back(
00104 osgTypedFunctionFunctor2CPtrRef<ResultE,
00105 CNodePtr,
00106 Action *>(
00107 &IntersectAction::_defaultEnterFunction));
00108 }
00109
00110 (*_defaultEnterFunctors)[ type.getId() ] = func;
00111 }
00112
00113 void IntersectAction::registerLeaveDefault( const FieldContainerType &type,
00114 const Action::Functor &func )
00115 {
00116 if ( ! _defaultLeaveFunctors )
00117 _defaultLeaveFunctors = new std::vector<Action::Functor>;
00118
00119 while(type.getId() >= _defaultLeaveFunctors->size())
00120 {
00121 _defaultLeaveFunctors->push_back(
00122 osgTypedFunctionFunctor2CPtrRef<ResultE,
00123 CNodePtr,
00124 Action *>(
00125 &IntersectAction::_defaultLeaveFunction));
00126 }
00127
00128 (*_defaultLeaveFunctors)[ type.getId() ] = func;
00129 }
00130
00131
00132 void IntersectAction::setPrototype( IntersectAction * proto )
00133 {
00134 _prototype = proto;
00135 }
00136
00137 IntersectAction *IntersectAction::getPrototype( void )
00138 {
00139 return _prototype;
00140 }
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00166 IntersectAction::IntersectAction(void) :
00167 _line(), _maxdist(),
00168 _hit(false), _enterT(-1), _leaveT(-1), _hitT(-1), _hitObject(),
00169 _hitTriangle(-1)
00170 {
00171 if ( _defaultEnterFunctors )
00172 _enterFunctors = *_defaultEnterFunctors;
00173
00174 if ( _defaultLeaveFunctors )
00175 _leaveFunctors = *_defaultLeaveFunctors;
00176 }
00177
00178
00179 IntersectAction::IntersectAction( const IntersectAction& source ) :
00180 Inherited( source ),
00181 _line( source._line ), _maxdist( source._maxdist ),
00182 _hit(source._hit), _enterT(source._enterT), _leaveT(source._leaveT),
00183 _hitT(source._hitT), _hitObject(source._hitObject),
00184 _hitTriangle(source._hitTriangle)
00185 {
00186 }
00187
00188
00192 IntersectAction * IntersectAction::create( void )
00193 {
00194 IntersectAction * act;
00195
00196 if ( _prototype )
00197 act = new IntersectAction( *_prototype );
00198 else
00199 act = new IntersectAction();
00200
00201 return act;
00202 }
00203
00204
00208 IntersectAction * IntersectAction::create( const Line &line,
00209 const Real32 maxdist )
00210 {
00211 IntersectAction * act;
00212
00213 if ( _prototype )
00214 act = new IntersectAction( *_prototype );
00215 else
00216 act = new IntersectAction();
00217
00218 act->setLine( line, maxdist );
00219
00220 return act;
00221 }
00222
00226 IntersectAction::~IntersectAction(void)
00227 {
00228 }
00229
00230
00231
00232
00233
00234 void IntersectAction::setLine( const Line &line, const Real32 maxdist )
00235 {
00236 _line = line;
00237 _maxdist = maxdist;
00238 }
00239
00240 Action::ResultE IntersectAction::setEnterLeave( Real32 enter, Real32 leave )
00241 {
00242 if ( leave < 0 || enter > _maxdist ||
00243 ( _hit && enter > _hitT ) )
00244 return Action::Skip;
00245
00246 return Action::Continue;
00247 }
00248
00249 void IntersectAction::setHit( Real32 t, NodePtr obj, Int32 triIndex,
00250 Vec3f &normal )
00251 {
00252 if ( t < 0 || t > _hitT || t > _maxdist)
00253 return;
00254
00255 _hitT = t;
00256 _hitObject = obj;
00257 _hitTriangle = triIndex;
00258 _hitNormal = normal;
00259 _hit = true;
00260 }
00261
00262 void IntersectAction::scale(Real32 s)
00263 {
00264 _hitT *= s;
00265 _maxdist *= s;
00266 }
00267
00268
00269
00270
00271 Action::ResultE IntersectAction::start( void )
00272 {
00273 _hitT = Inf;
00274 _hitObject = NullFC;
00275 _hitTriangle = -1;
00276 _hit = false;
00277 return Continue;
00278 }
00279
00280
00281
00282
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00310 bool IntersectAction::operator < (const IntersectAction &other) const
00311 {
00312 return this < &other;
00313 }
00314
00318 bool IntersectAction::operator == (
00319 const IntersectAction &OSG_CHECK_ARG(other)) const
00320 {
00321 return false;
00322 }
00323
00327 bool IntersectAction::operator != (const IntersectAction &other) const
00328 {
00329 return ! (*this == other);
00330 }
00331
00332
00333
00334
00335
00336
00337
00338 std::vector<IntersectAction::Functor> *
00339 IntersectAction::getDefaultEnterFunctors(void)
00340 {
00341 return _defaultEnterFunctors;
00342 }
00343
00344 std::vector<IntersectAction::Functor> *
00345 IntersectAction::getDefaultLeaveFunctors(void)
00346 {
00347 return _defaultLeaveFunctors;
00348 }
00349
00350
00351
00352
00353
00354
00355
00359
00362
00363
00365
00366
00368
00369
00371
00372
00374
00375
00377
00378
00380
00381
00383