Joined: 17 Dec 2014
|Posted: Wed Dec 31, 2014 10:16 pm Post subject:
Redrawing an the arc of a circle with a new length
I am currently able to draw an arc of a circle, but I want to be able to change the length of my arc. Eventually the arc length will change based on the position of the mouse, so it needs to update rather quickly. I think I could just remove the existing geometry from my geode, create a whole new arc geometry with the new length, then add that geometry to the geode.
1) I was wondering if there was an either more efficient or more standard way to do this? What is the standard method for "editing" a geometry once it has already been created?
2) Is there any way I could add or remove vertices from my existing arc geometry? If yes, is it the route I should take?
The code I have to draw the arc:
osg::Geode* arc_geode = new osg::Geode();
osg::Geometry* arc_geom = new osg::Geometry();
int num_pts = 720; //total number of points in the circle
osg::Vec3Array* pts = new osg::Vec3Array();
for(int i = 0; i < 181; i++) //draw an arc up to point 180
float angle = float(i)*(float(2.0 * osg::PI) / float(num_pts));
float x = radius * cosf(angle);
float y = radius * sinf(angle);
pts->push_back(osg::Vec3(x, y, 0.0));
osg::DrawElementsUInt* arc_base = new osg::DrawElementsUInt(osg::PrimitiveSet::LINES, 0);
for(int k = 0; k < 181; k++)
if(k != 180)