OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Redrawing an the arc of a circle with a new length


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General [forum]
View previous topic :: View next topic  
Author Message
jlguitar287
Newbie


Joined: 17 Dec 2014
Posts: 5

PostPosted: Wed Dec 31, 2014 10:16 pm    Post subject:
Redrawing an the arc of a circle with a new length
Reply with quote

Hello all,

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:

Code:
osg::Geode* arc_geode = new osg::Geode();
osg::Geometry* arc_geom = new osg::Geometry();
arc_geode->addDrawable(arc_geom);

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));
}

arc_geom->setVertexArray(pts);

osg::DrawElementsUInt* arc_base = new osg::DrawElementsUInt(osg::PrimitiveSet::LINES, 0);

for(int k = 0; k < 181; k++)
{
arc_base->push_back(k);
if(k != 180)
arc_base->push_back(k+1);
}

arc_geom->addPrimitiveSet(arc_base);


Thank you!

Cheers,
John-Luke
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General [forum] All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Draw vertex as Circle with color give... Bruno Oliveira General 7 Mon Jan 02, 2017 7:22 pm View latest post
No new posts Create circle osgEarth kingmarco1983 General 6 Tue Jul 05, 2016 6:43 pm View latest post
No new posts How to get the pixel length of a string robertosfield General 3 Wed Jul 24, 2013 5:55 am View latest post
No new posts Using osgManipulator Dragger to drag ... mschan01 General 1 Sun Dec 02, 2012 10:48 pm View latest post
No new posts How to set camera focal length iseeall General 12 Thu Dec 09, 2010 9:54 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP