Hi, Paul. Not in any way did your code insulted my intelligence. I haven't been to any Computer Graphics course in my whole life, so keep feeding me with the basics! : )
Well. I've got a question here. I've addapted that code you've given me so that it was supposed to create a sphere. You can deduce that it didn't (it just draws the original circle). I was wondering if you could point out my mistake. It doesn't seem to be in the logics of computer graphics, but something I don't know about OSG. Thanks for your help. ////////CODE/////////// #include <osg/LineWidth> #include <osg/Geometry> #include <osg/math> #include <math.h> #include <osgViewer/Viewer> osg::Vec3Array* circleVerts( int plane, int approx, float radius ) { const double angle( osg::PI * 2. / (double) approx ); osg::Vec3Array* v = new osg::Vec3Array; int idx, count; double x(0.), y(0.), z(0.); double height; double original_radius = radius; for(count = 0; count <= approx/4; count++) { height = original_radius*sin(count*angle); radius = cos(count*angle)*radius; switch(plane) { case 0: // X x = height; break; case 1: //Y y = height; break; case 2: //Z z = height; break; } for( idx=0; idx<approx; idx++) { double cosAngle = cos(idx*angle); double sinAngle = sin(idx*angle); switch (plane) { case 0: // X y = radius*cosAngle; z = radius*sinAngle; break; case 1: // Y x = radius*cosAngle; z = radius*sinAngle; break; case 2: // Z x = radius*cosAngle; y = radius*sinAngle; break; } v->push_back( osg::Vec3( x, y, z ) ); } } return v; } osg::Geode* circles( int plane, int approx, float radius ) { osg::Geode* geode = new osg::Geode; osg::LineWidth* lw = new osg::LineWidth( 3. ); geode->getOrCreateStateSet()->setAttributeAndModes( lw, osg::StateAttribute::ON ); osg::Geometry* geom = new osg::Geometry; osg::Vec3Array* v = circleVerts( plane, approx, radius ); geom->setVertexArray( v ); osg::Vec4Array* c = new osg::Vec4Array; c->push_back( osg::Vec4( 1., 1., 1., 1. ) ); geom->setColorArray( c ); geom->setColorBinding( osg::Geometry::BIND_OVERALL ); geom->addPrimitiveSet( new osg::DrawArrays( GL_LINE_LOOP, 0, approx ) ); geode->addDrawable( geom ); return geode; } int main(int argc, char **argv) { // use an ArgumentParser object to manage the program arguments. osg::ArgumentParser arguments(&argc,argv); osg::DisplaySettings::instance()->setMinimumNumAlphaBits(8); // construct the viewer. osgViewer::Viewer viewer; osg::Group* root = new osg::Group(); root->addChild(circles(0, 200, 1.0)); viewer.setSceneData(root); return viewer.run(); }
_______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org