[osg-users] Filling colors into a Drawn object

2008-05-07 Thread Srikanth Bemineni

Hi,

As requested by Robert, I am splitting my questions into multiple mails.

How do we fill colors in a drawn object.Here I am trying to draw a 
circle and also I want to fill it with yellow  color.



/*/
   //degree to radian conversion
   const float DEG2RAD = 3.14159/180;
   osg::Geode* circle = new osg::Geode;

   osg::Geometry* circleGeom = new osg::Geometry; //circle geometery
   circle-addDrawable( circleGeom );
   osg::Vec3Array* circleArray = new osg::Vec3Array;

   //To calculate circle points
   //here it is every 30 degrees 12 point circle or polygon what ever
   int radius  = 1000;
   for (int i=0; i  360; i = i + 30 )
   {
   float degInRad = i*DEG2RAD;
   circleArray-push_back( 
osg::Vec3(cos(degInRad)*radius,0,sin(degInRad)*radius ) );

   }

   circleGeom-setVertexArray( circleArray );
   
   //attaching the points
   osg::DrawElementsUInt* circleelementobj = new  
osg::DrawElementsUInt( osg::PrimitiveSet::LINE_LOOP, 0 );


   osg::Vec4Array*  ccolors = new osg::Vec4Array;
   osg::TemplateIndexArray unsigned int, 
osg::Array::UIntArrayType,4,4 *colorIndexArray;
   colorIndexArray =new osg::TemplateIndexArrayunsigned int, 
osg::Array::UIntArrayType,4,4;


   osg::Vec2Array* texcoords = new osg::Vec2Array(360/30);

   for( int j=0 ; j  360/30 ; j++ )
   {
   circleelementobj-push_back( j );
   ccolors-push_back(osg::Vec4(1.0f, 1.0f, 0.0f, 1.0f) ); //index 
0 redi
   (*texcoords)[j].set( 40.50f, 40.0f ); //I really didn't get what 
to do just copied from the tutorial

   }

   circleelementobj-push_back( 0 );

   for( int k = 0 ; k  360 /30 ; k++ )
   {
   colorIndexArray-push_back(0);
   }

  
   ccolors-push_back(osg::Vec4(1.0f, 1.0f, 0.0f, 1.0f) ); //index 0 red


   circleGeom-addPrimitiveSet( circleelementobj );

   circleGeom-setColorArray(ccolors);
   circleGeom-setColorIndices(colorIndexArray);
   circleGeom-setColorBinding(osg::Geometry::BIND_PER_VERTEX);
   circleGeom-setTexCoordArray(0, texcoords);

osg::PositionAttitudeTransform* circleXForm =
   new osg::PositionAttitudeTransform();


circleXForm-setPosition(osg::Vec3( 4000 ,0, 4100 ));
root-addChild(circleXForm);
circleXForm-addChild( circle );
  
/*/


--
With Regards
Srikanth Bemineni
Geotrace Technologies
281-497-8440 extn 228

  

  

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Filling colors into a Drawn object

2008-05-07 Thread Joakim Simonsson


Hi,


How do we fill colors in a drawn object.Here I am trying to draw a
circle and also I want to fill it with yellow  color.


The only way to fill a circle is to build polygons. One polygon would be  
enough, since the circle shape is convex.


With other words, change the primitive set on this line: (could be  
POLYGON, not sure, check the src)



osg::DrawElementsUInt( osg::PrimitiveSet::LINE_LOOP, 0 );


If you want an edge on your circle, you can use your line loop in addition  
to the poly.


Texture coordinates. Well, they pretty much depend on you texture. If you  
don't use a texture, don't set up the texture array.



--
Joakim Simonsson
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Filling colors into a Drawn object

2008-05-07 Thread Srikanth Bemineni
Yeah setting osg::PrimitiveSet::LINE_LOOP to osg::PrimitiveSet::POLYGON 
works.

Thank you

Joakim Simonsson wrote:


Hi,


How do we fill colors in a drawn object.Here I am trying to draw a
circle and also I want to fill it with yellow color.


The only way to fill a circle is to build polygons. One polygon 
would be enough, since the circle shape is convex.


With other words, change the primitive set on this line: (could be 
POLYGON, not sure, check the src)



osg::DrawElementsUInt( osg::PrimitiveSet::LINE_LOOP, 0 );


If you want an edge on your circle, you can use your line loop in 
addition to the poly.


Texture coordinates. Well, they pretty much depend on you texture. If 
you don't use a texture, don't set up the texture array.






--
With Regards
Srikanth Bemineni
Geotrace Technologies
281-497-8440 extn 228

  

  


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org