Hi Johan
On Mon, Jun 2, 2008 at 7:59 AM, Johan Johnsson <[EMAIL PROTECTED]> wrote:
> Which is the easiest way to draw line curves i osgviewer.
>
> Im developing a function that draw a function from startPos to endPos (vec3)
> both. With a math function.
>
> Any hints? .. about functions available?
Drawing mathematical curves in OpenGL is generally done using line
strips, i.e. you sample your function at regular intervals, this
produces a list of vertex and you connect them with lines. If you
choose an appropriate sample rate, your curve will look smooth.
sample code for the OSG:
float your_math_func(float x) { ...... }
int numSteps = 100; // More vertices->smoother curve, slower display
float xstart = startPos.x();
float xstep = (endPos.x() - startPos().x) / (float)(numSteps-1);
osg::Vec3Array* vertices = new osg::Vec3Array;
float x = xstart;
for (int i=0;i<numSamples;++i) {
vertices->push_back(osg::Vec3(x,your_math_func(x),0.0f));
x += xstep; }
osg::Geometry* geom = new osg::Geometry;
geom->setVertexArray(vertices);
geom->addPrimitiveSet(new
osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP, 0, vertices->size()));
Thibault
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org