drawViewerQuads< posTrait, colTrait, texTrait, sizeTrait > Struct Template Reference

Inheritance diagram for drawViewerQuads< posTrait, colTrait, texTrait, sizeTrait >:

osg::ParticlesDrawer

List of all members.

Public Member Functions

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


Detailed Description

template<class posTrait, class colTrait, class texTrait, class sizeTrait>
struct drawViewerQuads< posTrait, colTrait, texTrait, sizeTrait >

Definition at line 1387 of file OSGParticles.cpp.


Member Function Documentation

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

Implements osg::ParticlesDrawer.

Definition at line 1389 of file OSGParticles.cpp.

References osg::VectorInterface< ValueTypeT, StorageInterfaceT >::cross(), osg::Action::getActNode(), osg::DrawActionBase::getCameraToWorld(), osg::ParticlesBase::getPositions(), init(), osg::TransformationMatrix< ValueTypeT >::invert(), osg::TransformationMatrix< ValueTypeT >::multLeft(), osg::VectorInterface< ValueTypeT, StorageInterfaceT >::normalize(), p, and osg::RenderAction::top_matrix().

01391     {
01392         // get ModelView matrix to define the direction vectors
01393         Matrix camera,toworld;
01394 
01395         camera = action->getCameraToWorld();
01396 
01397         RenderAction *ra = dynamic_cast<RenderAction *>(action);
01398         
01399         if(ra != NULL)
01400         {
01401             toworld = ra->top_matrix();
01402         }
01403         else
01404         {
01405             action->getActNode()->getToWorld(toworld);
01406         }
01407 
01408         // normalize them, we don't want to neutralize scales in toworld
01409         toworld[0].normalize();
01410         toworld[1].normalize();
01411         toworld[2].normalize();       
01412         toworld.invert();
01413         camera.multLeft(toworld);
01414 
01415         // Viewer position & up
01416         Pnt3f  vpos(camera[3]);
01417         Vec3f  vup (camera[1]);
01418         vup.normalize();
01419         Vec3f  vdir,vnorm;
01420 
01421         // direction vector
01422         Vec4f d;
01423         
01424         // some variables for faster access
01425         GeoPositionsPtr  pos  = part->getPositions();
01426 
01427         // init traits
01428         typename colTrait::dataType colData;
01429         colTrait::init(part, action, colData);
01430 
01431         typename texTrait::dataType texData;
01432         texTrait::init(part, action, texData);
01433 
01434         typename sizeTrait::dataType sizeData;
01435         sizeTrait::init(part, action, sizeData);
01436 
01437         typename posTrait::dataType posData;
01438         posTrait::init(part, action, posData, part->getPositions());
01439 
01440         glBegin(GL_QUADS);
01441 
01442         Int32 i;
01443 
01444         for(UInt32 ii = 0; ii < length; ++ii)
01445         {
01446             i = index[ii];
01447 
01448             if(i < 0 || i > Int32(pos->getSize()))
01449                 continue;
01450 
01451             if(colTrait::particle (colData,  i))
01452                 continue;
01453 
01454             if(texTrait::particle (texData,  i))
01455                 continue;
01456 
01457             if(sizeTrait::particle(sizeData, i))
01458                 continue;
01459 
01460             if(posTrait::particle(posData, i))
01461                 continue;
01462 
01463             Real32 s = sizeTrait::size(sizeData, i)[0] / 2.f;
01464 
01465             if(s == 0)
01466                 continue;
01467 
01468             // calc viewer-relative coord system
01469             
01470             Pnt3f p = pos->getValue(i);  
01471             vdir = vpos - p;  
01472             vdir.normalize();         
01473             vnorm = vup.cross(vdir);
01474  
01475             d.setValues( -vnorm[0] - vup[0],
01476                          -vnorm[1] - vup[1],
01477                          -vnorm[2] - vup[2],
01478                          1 );
01479             colTrait::vertex(colData, i, 0);
01480             texTrait::vertex(texData, 0, 0, 0);
01481             posTrait::vertex(posData, 0, d, s);
01482 
01483             d.setValues(  vnorm[0] - vup[0],
01484                           vnorm[1] - vup[1],
01485                           vnorm[2] - vup[2],
01486                          1 );
01487             colTrait::vertex(colData, i, 1);
01488             texTrait::vertex(texData, 1, 1, 0);
01489             posTrait::vertex(posData, 1, d, s);
01490 
01491             d.setValues(  vnorm[0] + vup[0],
01492                           vnorm[1] + vup[1],
01493                           vnorm[2] + vup[2],
01494                          1 );
01495             colTrait::vertex(colData, i, 2);
01496             texTrait::vertex(texData, 2, 1, 1);
01497             posTrait::vertex(posData, 2, d, s);
01498 
01499             d.setValues( -vnorm[0] + vup[0],
01500                          -vnorm[1] + vup[1],
01501                          -vnorm[2] + vup[2],
01502                          1 );
01503             colTrait::vertex(colData, i, 3);
01504             texTrait::vertex(texData, 3, 0, 1);
01505             posTrait::vertex(posData, 3, d, s);
01506         }
01507 
01508         glEnd();
01509     }

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

Implements osg::ParticlesDrawer.

Definition at line 1511 of file OSGParticles.cpp.

References osg::VectorInterface< ValueTypeT, StorageInterfaceT >::cross(), osg::Action::getActNode(), osg::DrawActionBase::getCameraToWorld(), osg::ParticlesBase::getPositions(), init(), osg::TransformationMatrix< ValueTypeT >::invert(), osg::TransformationMatrix< ValueTypeT >::multLeft(), osg::VectorInterface< ValueTypeT, StorageInterfaceT >::normalize(), p, and osg::RenderAction::top_matrix().

01512     {
01513         // get ModelView matrix to define the direction vectors
01514         Matrix camera,toworld;
01515 
01516         camera = action->getCameraToWorld();
01517 
01518         RenderAction *ra = dynamic_cast<RenderAction *>(action);
01519         
01520         if(ra != NULL)
01521         {
01522             toworld = ra->top_matrix();
01523         }
01524         else
01525         {
01526             action->getActNode()->getToWorld(toworld);
01527         }
01528 
01529 
01530         // normalize them, we don't want to neutralize scales in toworld
01531         toworld[0].normalize();
01532         toworld[1].normalize();
01533         toworld[2].normalize();       
01534         toworld.invert();
01535         camera.multLeft(toworld);
01536 
01537         // Viewer position & up
01538         Pnt3f  vpos(camera[3]);
01539         Vec3f  vup (camera[1]);
01540         vup.normalize();
01541         Vec3f  vdir,vnorm;
01542 
01543         // direction vector
01544         Vec4f d;
01545         
01546         // some variables for faster access
01547         GeoPositionsPtr pos = part->getPositions();
01548 
01549         // init traits
01550         typename colTrait::dataType colData;
01551         colTrait::init(part, action, colData);
01552 
01553         typename texTrait::dataType texData;
01554         texTrait::init(part, action, texData);
01555 
01556         typename sizeTrait::dataType sizeData;
01557         sizeTrait::init(part, action, sizeData);
01558 
01559         typename posTrait::dataType posData;
01560         posTrait::init(part, action, posData, part->getPositions());
01561 
01562         glBegin(GL_QUADS);
01563        
01564         for(UInt32 i = 0; i < length; ++i)
01565         {
01566             if(colTrait::particle (colData,  i))
01567                 continue;
01568 
01569             if(texTrait::particle (texData,  i))
01570                 continue;
01571 
01572             if(sizeTrait::particle(sizeData, i))
01573                 continue;
01574 
01575             if(posTrait::particle(posData, i))
01576                 continue;
01577 
01578             Real32 s = sizeTrait::size(sizeData, i)[0] / 2.f;
01579 
01580             if(s == 0)
01581                 continue;
01582 
01583             // calc viewer-relative coord system
01584             
01585             Pnt3f p = pos->getValue(i);  
01586             vdir = vpos - p;  
01587             vdir.normalize();         
01588             vnorm = vup.cross(vdir);
01589  
01590             d.setValues( -vnorm[0] - vup[0],
01591                          -vnorm[1] - vup[1],
01592                          -vnorm[2] - vup[2],
01593                          1 );
01594             colTrait::vertex(colData, i, 0);
01595             texTrait::vertex(texData, 0, 0, 0);
01596             posTrait::vertex(posData, 0, d, s);
01597 
01598             d.setValues(  vnorm[0] - vup[0],
01599                           vnorm[1] - vup[1],
01600                           vnorm[2] - vup[2],
01601                          1 );
01602             colTrait::vertex(colData, i, 1);
01603             texTrait::vertex(texData, 1, 1, 0);
01604             posTrait::vertex(posData, 1, d, s);
01605 
01606             d.setValues(  vnorm[0] + vup[0],
01607                           vnorm[1] + vup[1],
01608                           vnorm[2] + vup[2],
01609                          1 );
01610             colTrait::vertex(colData, i, 2);
01611             texTrait::vertex(texData, 2, 1, 1);
01612             posTrait::vertex(posData, 2, d, s);
01613 
01614             d.setValues( -vnorm[0] + vup[0],
01615                          -vnorm[1] + vup[1],
01616                          -vnorm[2] + vup[2],
01617                          1 );
01618             colTrait::vertex(colData, i, 3);
01619             texTrait::vertex(texData, 3, 0, 1);
01620             posTrait::vertex(posData, 3, d, s);
01621         }
01622 
01623         glEnd();
01624     }


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