Hi,

How to calculate normal vector using the osg::smoothingVisitor ?
Guide me by providing some example related to above question .
I have to find normal for lightning effect. I have draw various model
using triangle strip . Now i'm in need of finding normal.

Here I'have attached some part of simple model of cube .
Kindly help me what is the best way for me to finding normal here


Some part of my code is : 
// front face of Cube
        {

   
   {
                osg::Geometry* pGeo = new osg::Geometry;

                        // add 4 vertices creating a quad
                osg::Vec3Array* pVerts = new osg::Vec3Array(3);
                (*pVerts)[0].set((*points1)[0].x() ,(*points1)[0].y() , 
(*points1)[0].z());
                (*pVerts)[1].set((*points1)[1].x() ,(*points1)[1].y() , 
(*points1)[1].z());
                (*pVerts)[2].set((*points1)[2].x() ,(*points1)[2].y() , 
(*points1)[2].z());
                pGeo->setVertexArray( pVerts );

                // create a primitive set
                osg::DrawElementsUInt* pPrimitiveSet = new 
osg::DrawElementsUInt( osg::PrimitiveSet::TRIANGLES, 0 );
                pPrimitiveSet->push_back( 0 );
                pPrimitiveSet->push_back( 1 );
                pPrimitiveSet->push_back( 2 );
                pGeo->addPrimitiveSet( pPrimitiveSet );

                // create an arraw for texture coordinates
                osg::Vec2Array* pTexCoords = new osg::Vec2Array( 3 );
                (*pTexCoords)[0].set(  (*points2)[9].x() , (*points2)[9].y()  );
            (*pTexCoords)[1].set(  (*points2)[8].x() , (*points2)[8].y()  );
            (*pTexCoords)[2].set(  (*points2)[7].x() , (*points2)[7].y()  );
                pGeo->setTexCoordArray( 0, pTexCoords );

                // create geometry node that will contain all our drawables
                
                
                geode->addDrawable( pGeo );

                }

                {
                osg::Geometry* pGeo = new osg::Geometry;

                        // add 4 vertices creating a quad
                osg::Vec3Array* pVerts = new osg::Vec3Array(3);
                (*pVerts)[0].set((*points1)[0].x() ,(*points1)[0].y() , 
(*points1)[0].z());
                (*pVerts)[1].set((*points1)[2].x() ,(*points1)[2].y() , 
(*points1)[2].z());
                (*pVerts)[2].set((*points1)[3].x() ,(*points1)[3].y() , 
(*points1)[3].z());
                pGeo->setVertexArray( pVerts );

                // create a primitive set
                osg::DrawElementsUInt* pPrimitiveSet = new 
osg::DrawElementsUInt( osg::PrimitiveSet::TRIANGLES, 0 );
                pPrimitiveSet->push_back( 0 );
                pPrimitiveSet->push_back( 1 );
                pPrimitiveSet->push_back( 2 );
                pGeo->addPrimitiveSet( pPrimitiveSet );

                // create an arraw for texture coordinates
                osg::Vec2Array* pTexCoords = new osg::Vec2Array( 3 );
                (*pTexCoords)[0].set(  (*points2)[9].x() , (*points2)[9].y()  );
            (*pTexCoords)[1].set(  (*points2)[7].x() , (*points2)[7].y()  );
            (*pTexCoords)[2].set(  (*points2)[10].x() , (*points2)[10].y()  );
                pGeo->setTexCoordArray( 0, pTexCoords );

                // create geometry node that will contain all our drawables
                
                
                geode->addDrawable( pGeo );

                }

                
                
                
        }



//Side right face
        {
                {
                osg::Geometry* pGeo = new osg::Geometry;

                        // add 4 vertices creating a quad
                osg::Vec3Array* pVerts = new osg::Vec3Array(3);
                (*pVerts)[0].set((*points1)[1].x() ,(*points1)[1].y() , 
(*points1)[1].z());
                (*pVerts)[1].set((*points1)[5].x() ,(*points1)[5].y() , 
(*points1)[5].z());
                (*pVerts)[2].set((*points1)[6].x() ,(*points1)[6].y() , 
(*points1)[6].z());
                pGeo->setVertexArray( pVerts );

                // create a primitive set
                osg::DrawElementsUInt* pPrimitiveSet = new 
osg::DrawElementsUInt( osg::PrimitiveSet::TRIANGLES, 0 );
                pPrimitiveSet->push_back( 0 );
                pPrimitiveSet->push_back( 1 );
                pPrimitiveSet->push_back( 2 );
                pGeo->addPrimitiveSet( pPrimitiveSet );

                // create an arraw for texture coordinates
                osg::Vec2Array* pTexCoords = new osg::Vec2Array( 3 );
                (*pTexCoords)[0].set(  (*points2)[6].x() , (*points2)[6].y()  );
            (*pTexCoords)[1].set(  (*points2)[5].x() , (*points2)[5].y()  );
            (*pTexCoords)[2].set(  (*points2)[4].x() , (*points2)[4].y()  );
                pGeo->setTexCoordArray( 0, pTexCoords );

                // create geometry node that will contain all our drawables
                
                
                geode->addDrawable( pGeo );

                }

                {
                osg::Geometry* pGeo = new osg::Geometry;

                        // add 4 vertices creating a quad
                osg::Vec3Array* pVerts = new osg::Vec3Array(3);
                (*pVerts)[0].set((*points1)[1].x() ,(*points1)[1].y() , 
(*points1)[1].z());
                (*pVerts)[1].set((*points1)[6].x() ,(*points1)[6].y() , 
(*points1)[6].z());
                (*pVerts)[2].set((*points1)[2].x() ,(*points1)[2].y() , 
(*points1)[2].z());
                pGeo->setVertexArray( pVerts );

                // create a primitive set
                osg::DrawElementsUInt* pPrimitiveSet = new 
osg::DrawElementsUInt( osg::PrimitiveSet::TRIANGLES, 0 );
                pPrimitiveSet->push_back( 0 );
                pPrimitiveSet->push_back( 1 );
                pPrimitiveSet->push_back( 2 );
                pGeo->addPrimitiveSet( pPrimitiveSet );

                // create an arraw for texture coordinates
                osg::Vec2Array* pTexCoords = new osg::Vec2Array( 3 );
                (*pTexCoords)[0].set(  (*points2)[6].x() , (*points2)[6].y()  );
            (*pTexCoords)[1].set(  (*points2)[4].x() , (*points2)[4].y()  );
            (*pTexCoords)[2].set(  (*points2)[7].x() , (*points2)[7].y()  );
                pGeo->setTexCoordArray( 0, pTexCoords );

                // create geometry node that will contain all our drawables
                
                
                geode->addDrawable( pGeo );

                }

                
                
                
        }

... 

Thank you!

Cheers,
manish

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=33603#33603





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to