kestiny的专栏

抬头望天,脚踏实地

OSGEarth绘制Geometry:绘圆(二)

功能描述如下:
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;
}
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chlk118/article/details/46822267
个人分类: C++/Qt OSG
想对作者说点什么? 我来说一句

osg实现画圆功能,并能放大

2013年10月17日 2KB 下载

没有更多推荐了,返回首页

不良信息举报

OSGEarth绘制Geometry:绘圆(二)

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭