关闭

OSGEarth绘制Geometry:绘圆(二)

2153人阅读 评论(0) 收藏 举报
分类:

功能描述如下:
1. 鼠标点击之处为圆心位置;
2. 以圆心到鼠标move的距离为半径绘圆;
3. 鼠标有点点击结束绘制;
4. 鼠标点击为新的圆心,继续下次绘制。
代码如下:drawcircle.h

class DrawCircle : public HandleAdapter
{
public:
    DrawCircle(GraphicsView* view);
    ~DrawCircle();

protected:
    virtual void slotPicked(osg::Vec3d pos);
    virtual void slotMoveing(osg::Vec3d pos);
    virtual void slotRightHandle();

private:
    osg::Vec3d m_centerPoint;

    osgEarth::Symbology::Style m_circleStyle;
    osgEarth::Annotation::CircleNode* m_pCircleNode;
    osgEarth::Annotation::CircleNodeEditor* m_pCircleEdit;
};

功能代码如下:drawcircle.cpp

DrawCircle::DrawCircle(GraphicsView* view)
    : HandleAdapter(view)
{
    m_centerPoint = osg::Vec3d();
    m_pLayerGroup->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
    m_pCircleNode = NULL;
    m_pCircleEdit = NULL;

    m_circleStyle.getOrCreate<osgEarth::Symbology::PolygonSymbol>()
        ->fill()->color() = osgEarth::Symbology::Color::Yellow;
    m_circleStyle.getOrCreate<osgEarth::Symbology::AltitudeSymbol>()
        ->clamping() = osgEarth::Symbology::AltitudeSymbol::CLAMP_TO_TERRAIN;
    m_circleStyle.getOrCreate<osgEarth::Symbology::AltitudeSymbol>()
        ->technique() = osgEarth::Symbology::AltitudeSymbol::TECHNIQUE_DRAPE;
    m_circleStyle.getOrCreate<osgEarth::Symbology::AltitudeSymbol>()
        ->verticalOffset() = 0.1;
}

DrawCircle::~DrawCircle()
{

}

void DrawCircle::slotPicked(osg::Vec3d pos)
{
    if (m_centerPoint == osg::Vec3d() && pos == osg::Vec3d())
    {
        return;
    }
    else if (m_centerPoint == osg::Vec3d())
    {
        m_centerPoint = pos;
    }

    if (m_pCircleNode == NULL)
    {
        m_pCircleNode = new osgEarth::Annotation::CircleNode(
            m_pMap3D->getMapNode(),
            osgEarth::GeoPoint::GeoPoint(m_pMap3D->getSRS(),
            m_centerPoint, osgEarth::AltitudeMode::ALTMODE_RELATIVE),
            osgEarth::Linear::Linear(50, osgEarth::Units::METERS),
            m_circleStyle,
            osgEarth::Angular::Angular(0.0, osgEarth::Units::DEGREES));

        m_pCircleEdit = new osgEarth::Annotation::CircleNodeEditor(m_pCircleNode);
        m_pLayerGroup->addChild(m_pCircleNode);
        m_pLayerGroup->addChild(m_pCircleEdit);
    }

    m_pCircleNode->setRadius(
        osgEarth::GeoMath::distance(m_centerPoint, pos, m_pMap3D->getSRS()));
}

void DrawCircle::slotMoveing(osg::Vec3d pos)
{
    if (m_pCircleNode != NULL && m_centerPoint != osg::Vec3d())
    {
        m_pCircleNode->setRadius(
            osgEarth::GeoMath::distance(m_centerPoint, pos, m_pMap3D->getSRS()));
    }
}

void DrawCircle::slotRightHandle()
{
    // 保证下次绘制的为新的圆
    m_centerPoint = osg::Vec3d();
    m_pCircleNode = NULL;
}
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:115017次
    • 积分:1508
    • 等级:
    • 排名:千里之外
    • 原创:44篇
    • 转载:0篇
    • 译文:0篇
    • 评论:101条
    文章分类
    最新评论