|
我用这样的EventHandler实现随手画线,为什么只有第一条线会出现,但是在第二次点击鼠标的时候才出现,而以后再画的线就不出现了?
case osgGA::GUIEventAdapter:USH:
current_geometry_ = new Geometry;
geode_->addDrawable(current_geometry_.get());
vertices = new Vec2Array;
vertices->push_back(Vec2(ea.getX(), ea.getY()));
current_geometry_->setVertexArray(vertices);
colors = new Vec3Array;
colors->push_back(Vec3(1, 0, 0));
current_geometry_->setColorArray(colors);
colors = NULL;
current_geometry_->setColorBinding(Geometry::BIND_OVERALL);
current_geometry_->addPrimitiveSet(new DrawArrays(GL_LINE_STRIP, 0, 1));
return true;
case osgGA::GUIEventAdapter:RAG:
vertices = dynamic_cast<Vec2Array*>(current_geometry_->getVertexArray());
vertices->push_back(Vec2(ea.getX(), ea.getY()));
dynamic_cast<DrawArrays*>(current_geometry_->getPrimitiveSet(0))->setCount(vertices->size());
return true;
case osgGA::GUIEventAdapter::RELEASE:
current_geometry_ = NULL;
return true;
其中current_geometry_和geode_为类变量,并且我已经将geode_设为Object::DYNAMIC了 |
|