Hi Patrick,
On 5/9/2013 9:16 PM, Patrick Keenan wrote:
Hi,
This post was really helpful for me but I still couldn't add points on the fly
either. A few edits made it happen so I'm attaching my M_OSG_line_strip class.
To use the class I have the following in my CreateScene()
Code:
osg::Vec3Array* line_pts = new osg::Vec3Array;
line_pts->push_back(osg::Vec3(100, 0, 0));
line_pts->push_back(osg::Vec3(0, 100, 500));
line_pts->push_back(osg::Vec3(100, 100, 100));
lines_test = new
M_OSG_line_strip(osg::Matrix::rotate(osg::inDegrees(0.0f), 0.0f, 0.0f, 1.0f),
osg::Matrix::translate(0.0f, 0.0f, 0.0f),
osg::Matrix::rotate(osg::inDegrees(0.0f), 0.0f, 0.0f, 1.0f),
line_pts,
osg::Vec4(0.0f,1.0f,1.0f,1.0f)
);
Memory leak if lines_test assignment line throws an exception (lines_pts
will leak). An osg::ref_ptr would solve this.
tmp_root->addChild(lines_test->Get());
and to dynamically add a new line I have
Code:
void M_frame::OnTestBtnClick(wxCommandEvent& WXUNUSED(event))
{
osg::Vec3f* new_pt = new osg::Vec3f(4000.0f, 2000.0f, 0.0f); // works
lines_test->Add_new_point(new_pt);
}
Another memory leak for all points created since nobody is calling
delete. I suggest passing osg::Vec3 parameters by value or const reference.
Regards,
Judson
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org