osg::Geometry* ShapeVisitor_VisualizerCreator::createGridGeometry( int size, int noOfLines, osg::Vec3f center ) { osg::Geometry* geom = new osg::Geometry(); osg::Vec3Array* positionsOfLines = new osg::Vec3Array; geom->setVertexArray( positionsOfLines ); // position of borders osg::Vec3f dif1( ( osg::Vec3f::value_type )( -size/2 ), ( osg::Vec3f::value_type )( size/2 ), -10 ); // top left osg::Vec3f dif2( ( osg::Vec3f::value_type )( -size/2 ), ( osg::Vec3f::value_type )( -size/2 ), -10 ); osg::Vec3f dif3( ( osg::Vec3f::value_type )( size/2 ), ( osg::Vec3f::value_type )( size/2 ), -10 ); // increment for creating points of mesh at border osg::Vec3f incrementX( ( osg::Vec3f::value_type )( size/noOfLines ), 0, 0 ); osg::Vec3f incrementY( 0, ( osg::Vec3f::value_type )( -size/noOfLines ), 0 ); // computing and saving positions of points at border of mesh for ( int i=0; i<2; i++ ) { osg::Vec3f base1 = center + dif1; osg::Vec3f base2 = center + dif2; // computing positions at x axis for ( int j=0; j<noOfLines; j++ ) { positionsOfLines->push_back( base1 + incrementX ); base1 += incrementX; positionsOfLines->push_back( base2 + incrementX + incrementY ); base2 += incrementX; } base1 = center + dif1; base2 = center + dif3; // computing positions at y axis for ( int j=0; j<noOfLines; j++ ) { positionsOfLines->push_back( base1 + incrementY ); base1 += incrementY; positionsOfLines->push_back( base2 + incrementY + incrementX ); base2 += incrementY; } // connecting two corresponding points at border of mesh for ( int k=0; k<noOfLines*4; k=k+2 ) { osg::DrawElementsUInt* line = new osg::DrawElementsUInt( osg::PrimitiveSet::LINES, 0 ); line->push_back( k ); line->push_back( k+1 ); geom->addPrimitiveSet( line ); } } return geom; }
int main() { const int n = 10; fValue values[n]; for (int i = 0; i < n; i++) { values[i].x = i; values[i].y = F(i); } dif1(values, n); dif2(values, n); printf("y = sin(%ix)%i^(-x)\n\n", b, a); printf(" X\t\t Y\t\t dy\t\t ddy\n"); for (int i = 0; i < n; i++) values[i].print(); system("pause"); return 0; }