drawViewerObjects< posTrait, colTrait, sizeTrait, geoTrait > Struct Template Reference

Inheritance diagram for drawViewerObjects< posTrait, colTrait, sizeTrait, geoTrait >:

osg::ParticlesDrawer

List of all members.

Public Member Functions

virtual void draw (Particles *part, DrawActionBase *action, UInt32 length)
virtual void drawIndexed (Particles *part, DrawActionBase *action, Int32 *index, UInt32 length)


Detailed Description

template<class posTrait, class colTrait, class sizeTrait, class geoTrait>
struct drawViewerObjects< posTrait, colTrait, sizeTrait, geoTrait >

Definition at line 2141 of file OSGParticles.cpp.


Member Function Documentation

template<class posTrait, class colTrait, class sizeTrait, class geoTrait>
virtual void drawViewerObjects< posTrait, colTrait, sizeTrait, geoTrait >::draw ( Particles part,
DrawActionBase action,
UInt32  length 
) [inline, virtual]

Implements osg::ParticlesDrawer.

Definition at line 2143 of file OSGParticles.cpp.

References osg::VectorInterface< ValueTypeT, StorageInterfaceT >::cross(), osg::Action::getActNode(), osg::CameraBase::getBeacon(), osg::DrawActionBase::getCamera(), osg::ParticlesBase::getPositions(), osg::ParticlesBase::getSecPositions(), init(), osg::TransformationMatrix< ValueTypeT >::invert(), osg::TransformationMatrix< ValueTypeT >::multLeft(), osg::VectorInterface< ValueTypeT, StorageInterfaceT >::normalize(), and p.

02144     {
02145         // get ModelView matrix to define the direction vectors
02146         Matrix camera,toworld;
02147         action->getCamera()->getBeacon()->getToWorld(camera);
02148         action->getActNode()->getToWorld(toworld);
02149         // normalize them, we don't want to neutralize scales in toworld
02150         toworld[0].normalize();
02151         toworld[1].normalize();
02152         toworld[2].normalize();       
02153         toworld.invert();
02154         camera.multLeft(toworld);
02155 
02156         // Viewer position & up
02157         Pnt3f  vpos(camera[3]);
02158 
02159         // some variables for faster access
02160         GeoPositionsPtr pos = part->getPositions();
02161 
02162         // init traits
02163         typename geoTrait::dataType geoData;
02164         geoTrait::init(part, action, geoData);
02165 
02166         typename colTrait::dataType colData;
02167         colTrait::init(part, action, colData);
02168 
02169         typename sizeTrait::dataType sizeData;
02170         sizeTrait::init(part, action, sizeData);
02171 
02172         typename posTrait::dataType posData, secPosData;
02173         posTrait::init(part, action, posData   , part->getPositions());
02174         posTrait::init(part, action, secPosData, part->getSecPositions());
02175         
02176         for(UInt32 i = 0; i < length; ++i)
02177         {
02178             if(geoTrait::particle (geoData,  i))
02179                 continue;
02180 
02181             if(colTrait::particle (colData,  i))
02182                 continue;
02183 
02184             if(sizeTrait::particle(sizeData, i))
02185                 continue;
02186 
02187             if(posTrait::particle (posData,  i))
02188                 continue;
02189 
02190             if(posTrait::particle (secPosData,  i))
02191                 continue;
02192 
02193             // calc the coordinate system
02194             
02195             Pnt3f &p  = posTrait::position(posData   );
02196             Pnt3f &sp = posTrait::position(secPosData);
02197             Vec3f  n  = vpos - p;
02198            
02199             Vec3f dz(sp - p);
02200             dz.normalize();
02201 
02202             Vec3f dx(n.cross(dz));
02203             if(dx.isZero())
02204             {
02205                 dx=Vec3f(1,0,0).cross(dz);
02206                 if(dx.isZero())
02207                 {
02208                     dx=Vec3f(0,1,0).cross(dz);
02209                     if(dx.isZero())
02210                     {
02211                         dx=Vec3f(0,0,1).cross(dz);
02212                     }
02213                     else
02214                     {
02215                         dx.setValues(0,0,0);
02216                     }
02217                 }
02218             }
02219             dx.normalize();
02220 
02221             Vec3f dy(dx.cross(dz));
02222 
02223             // now draw the geometry;
02224             geoTrait::draw(geoData, p, sp, dx, dy, dz, 
02225                            sizeTrait::size(sizeData, i));
02226         }
02227          
02228         geoTrait::exit(part, action, geoData);
02229    }

template<class posTrait, class colTrait, class sizeTrait, class geoTrait>
virtual void drawViewerObjects< posTrait, colTrait, sizeTrait, geoTrait >::drawIndexed ( Particles part,
DrawActionBase action,
Int32 *  index,
UInt32  length 
) [inline, virtual]

Implements osg::ParticlesDrawer.

Definition at line 2231 of file OSGParticles.cpp.

References osg::VectorInterface< ValueTypeT, StorageInterfaceT >::cross(), osg::Action::getActNode(), osg::CameraBase::getBeacon(), osg::DrawActionBase::getCamera(), osg::ParticlesBase::getPositions(), osg::ParticlesBase::getSecPositions(), init(), osg::TransformationMatrix< ValueTypeT >::invert(), osg::TransformationMatrix< ValueTypeT >::multLeft(), osg::VectorInterface< ValueTypeT, StorageInterfaceT >::normalize(), and p.

02233     {
02234         // get ModelView matrix to define the direction vectors
02235         Matrix camera,toworld;
02236         action->getCamera()->getBeacon()->getToWorld(camera);
02237         action->getActNode()->getToWorld(toworld);
02238         // normalize them, we don't want to neutralize scales in toworld
02239         toworld[0].normalize();
02240         toworld[1].normalize();
02241         toworld[2].normalize();       
02242         toworld.invert();
02243         camera.multLeft(toworld);
02244 
02245         // Viewer position & up
02246         Pnt3f  vpos(camera[3]);
02247 
02248         // some variables for faster access
02249         GeoPositionsPtr pos = part->getPositions();
02250 
02251         // init traits
02252         typename geoTrait::dataType geoData;
02253         geoTrait::init(part, action, geoData);
02254 
02255         typename colTrait::dataType colData;
02256         colTrait::init(part, action, colData);
02257 
02258         typename sizeTrait::dataType sizeData;
02259         sizeTrait::init(part, action, sizeData);
02260 
02261         typename posTrait::dataType posData, secPosData;
02262         posTrait::init(part, action, posData   , part->getPositions());
02263         posTrait::init(part, action, secPosData, part->getSecPositions());
02264 
02265         Int32 i;
02266 
02267         for(UInt32 ii = 0; ii < length; ++ii)
02268         {
02269             i = index[ii];
02270 
02271             if(i < 0 || i > Int32(pos->getSize()))
02272                 continue;
02273 
02274             if(geoTrait::particle (geoData,  i))
02275                 continue;
02276 
02277             if(colTrait::particle (colData,  i))
02278                 continue;
02279 
02280             if(sizeTrait::particle(sizeData, i))
02281                 continue;
02282 
02283             if(posTrait::particle (posData,  i))
02284                 continue;
02285 
02286             if(posTrait::particle (secPosData,  i))
02287                 continue;
02288 
02289             // calc the coordinate system
02290             
02291             Pnt3f &p  = posTrait   ::position(posData   );
02292             Pnt3f &sp = posTrait   ::position(secPosData);
02293             Vec3f  n  = vpos - p;
02294             
02295             Vec3f dz(sp - p);
02296             dz.normalize();
02297 
02298             Vec3f dx(n.cross(dz));
02299             if(dx.isZero())
02300             {
02301                 dx=Vec3f(1,0,0).cross(dz);
02302                 if(dx.isZero())
02303                 {
02304                     dx=Vec3f(0,1,0).cross(dz);
02305                     if(dx.isZero())
02306                     {
02307                         dx=Vec3f(0,0,1).cross(dz);
02308                     }
02309                     else
02310                     {
02311                         dx.setValues(0,0,0);
02312                     }
02313                 }
02314             }
02315             dx.normalize();
02316 
02317             Vec3f dy(dx.cross(dz));
02318 
02319             // now draw the geometry;
02320             geoTrait::draw(geoData, p, sp, dx, dy, dz, 
02321                            sizeTrait::size(sizeData, i));
02322         }
02323         
02324         geoTrait::exit(part, action, geoData);
02325     }


The documentation for this struct was generated from the following file:

Generated on Mon Mar 17 12:02:59 2008 for OpenSG by  doxygen 1.5.5